@@ -5,7 +5,7 @@ use opentelemetry::{
5
5
} ;
6
6
use std:: { borrow:: Cow , time:: SystemTime } ;
7
7
8
- #[ derive( Debug , Default , Clone ) ]
8
+ #[ derive( Debug , Default , Clone , PartialEq ) ]
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.
@@ -99,7 +99,7 @@ impl opentelemetry::logs::LogRecord for LogRecord {
99
99
100
100
/// TraceContext stores the trace context for logs that have an associated
101
101
/// span.
102
- #[ derive( Debug , Clone ) ]
102
+ #[ derive( Debug , Clone , PartialEq ) ]
103
103
#[ non_exhaustive]
104
104
pub struct TraceContext {
105
105
/// Trace id
@@ -198,4 +198,68 @@ mod tests {
198
198
Some ( vec![ ( Key :: new( "key" ) , AnyValue :: String ( "value" . into( ) ) ) ] )
199
199
) ;
200
200
}
201
+
202
+ #[ test]
203
+ fn compare_trace_context ( ) {
204
+ let trace_context = TraceContext {
205
+ trace_id : TraceId :: from_u128 ( 1 ) ,
206
+ span_id : SpanId :: from_u64 ( 1 ) ,
207
+ trace_flags : Some ( TraceFlags :: default ( ) ) ,
208
+ } ;
209
+
210
+ let trace_context_cloned = trace_context. clone ( ) ;
211
+
212
+ assert_eq ! ( trace_context, trace_context_cloned) ;
213
+
214
+ let trace_context_different = TraceContext {
215
+ trace_id : TraceId :: from_u128 ( 2 ) ,
216
+ span_id : SpanId :: from_u64 ( 2 ) ,
217
+ trace_flags : Some ( TraceFlags :: default ( ) ) ,
218
+ } ;
219
+
220
+ assert_ne ! ( trace_context, trace_context_different) ;
221
+ }
222
+
223
+ #[ test]
224
+ fn compare_log_record ( ) {
225
+ let log_record = LogRecord {
226
+ event_name : Some ( Cow :: Borrowed ( "test_event" ) ) ,
227
+ target : Some ( Cow :: Borrowed ( "foo::bar" ) ) ,
228
+ timestamp : Some ( SystemTime :: now ( ) ) ,
229
+ observed_timestamp : Some ( SystemTime :: now ( ) ) ,
230
+ severity_text : Some ( Cow :: Borrowed ( "ERROR" ) ) ,
231
+ severity_number : Some ( Severity :: Error ) ,
232
+ body : Some ( AnyValue :: String ( "Test body" . into ( ) ) ) ,
233
+ attributes : Some ( vec ! [ ( Key :: new( "key" ) , AnyValue :: String ( "value" . into( ) ) ) ] ) ,
234
+ trace_context : Some ( TraceContext {
235
+ trace_id : TraceId :: from_u128 ( 1 ) ,
236
+ span_id : SpanId :: from_u64 ( 1 ) ,
237
+ trace_flags : Some ( TraceFlags :: default ( ) ) ,
238
+ } ) ,
239
+ } ;
240
+
241
+ let log_record_cloned = log_record. clone ( ) ;
242
+
243
+ assert_eq ! ( log_record, log_record_cloned) ;
244
+
245
+ let mut log_record_different = log_record. clone ( ) ;
246
+ log_record_different. event_name = Some ( Cow :: Borrowed ( "different_event" ) ) ;
247
+
248
+ assert_ne ! ( log_record, log_record_different) ;
249
+ }
250
+
251
+ #[ test]
252
+ fn compare_log_record_target_borrowed_eq_owned ( ) {
253
+ let log_record_borrowed = LogRecord {
254
+ event_name : Some ( Cow :: Borrowed ( "test_event" ) ) ,
255
+ ..Default :: default ( )
256
+ } ;
257
+
258
+ let log_record_owned = LogRecord {
259
+ event_name : Some ( Cow :: Owned ( "test_event" . to_string ( ) ) ) ,
260
+ ..Default :: default ( )
261
+ } ;
262
+
263
+ assert_eq ! ( log_record_borrowed, log_record_owned) ;
264
+ }
201
265
}
0 commit comments