@@ -5,16 +5,19 @@ use opentelemetry::{
5
5
} ;
6
6
use std:: { borrow:: Cow , time:: SystemTime } ;
7
7
8
- #[ derive( Debug , Clone , Default ) ]
8
+ #[ derive( Debug , Clone ) ]
9
9
#[ non_exhaustive]
10
10
/// LogRecord represents all data carried by a log record, and
11
11
/// is provided to `LogExporter`s as input.
12
12
pub struct LogRecord {
13
+ /// Event name. Optional as not all the logging API support it.
14
+ pub event_name : Option < Cow < ' static , str > > ,
15
+
13
16
/// Record timestamp
14
17
pub timestamp : Option < SystemTime > ,
15
18
16
19
/// Timestamp for when the record was observed by OpenTelemetry
17
- pub observed_timestamp : Option < SystemTime > ,
20
+ pub observed_timestamp : SystemTime ,
18
21
19
22
/// Trace context for logs associated with spans
20
23
pub trace_context : Option < TraceContext > ,
@@ -31,13 +34,35 @@ pub struct LogRecord {
31
34
pub attributes : Option < Vec < ( Key , AnyValue ) > > ,
32
35
}
33
36
37
+ impl Default for LogRecord {
38
+ fn default ( ) -> Self {
39
+ LogRecord {
40
+ event_name : None ,
41
+ timestamp : None ,
42
+ observed_timestamp : SystemTime :: now ( ) ,
43
+ trace_context : None ,
44
+ severity_text : None ,
45
+ severity_number : None ,
46
+ body : None ,
47
+ attributes : None ,
48
+ }
49
+ }
50
+ }
51
+
34
52
impl opentelemetry:: logs:: LogRecord for LogRecord {
53
+ fn set_event_name < T > ( & mut self , name : T )
54
+ where
55
+ T : Into < Cow < ' static , str > > ,
56
+ {
57
+ self . event_name = Some ( name. into ( ) ) ;
58
+ }
59
+
35
60
fn set_timestamp ( & mut self , timestamp : SystemTime ) {
36
61
self . timestamp = Some ( timestamp) ;
37
62
}
38
63
39
64
fn set_observed_timestamp ( & mut self , timestamp : SystemTime ) {
40
- self . observed_timestamp = Some ( timestamp) ;
65
+ self . observed_timestamp = timestamp;
41
66
}
42
67
43
68
fn set_severity_text ( & mut self , severity_text : Cow < ' static , str > ) {
@@ -112,7 +137,7 @@ mod tests {
112
137
let mut log_record = LogRecord :: default ( ) ;
113
138
let now = SystemTime :: now ( ) ;
114
139
log_record. set_observed_timestamp ( now) ;
115
- assert_eq ! ( log_record. observed_timestamp, Some ( now) ) ;
140
+ assert_eq ! ( log_record. observed_timestamp, now) ;
116
141
}
117
142
118
143
#[ test]
0 commit comments