Skip to content

Commit 8237f87

Browse files
authored
Add event_name field to LogRecord (#1488)
1 parent 0101233 commit 8237f87

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

opentelemetry/src/logs/record.rs

+14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use std::{borrow::Cow, collections::HashMap, time::SystemTime};
99
/// LogRecord represents all data carried by a log record, and
1010
/// is provided to `LogExporter`s as input.
1111
pub struct LogRecord {
12+
/// Event name. Optional as not all the logging API support it.
13+
pub event_name: Option<Cow<'static, str>>,
14+
1215
/// Record timestamp
1316
pub timestamp: Option<SystemTime>,
1417

@@ -33,6 +36,7 @@ pub struct LogRecord {
3336
impl Default for LogRecord {
3437
fn default() -> Self {
3538
LogRecord {
39+
event_name: None,
3640
timestamp: None,
3741
observed_timestamp: SystemTime::now(),
3842
trace_context: None,
@@ -368,6 +372,16 @@ impl LogRecordBuilder {
368372
self
369373
}
370374

375+
/// Sets the `event_name` of a record.
376+
pub fn with_name(self, name: Cow<'static, str>) -> Self {
377+
Self {
378+
record: LogRecord {
379+
event_name: Some(name),
380+
..self.record
381+
},
382+
}
383+
}
384+
371385
/// Build the record, consuming the Builder
372386
pub fn build(self) -> LogRecord {
373387
self.record

0 commit comments

Comments
 (0)