@@ -252,33 +252,38 @@ mod tests {
252
252
assert ! ( log. record. trace_context. is_none( ) ) ;
253
253
254
254
// Validate attributes
255
- let attributes = log. record . attributes . clone ( ) ;
256
255
#[ cfg( not( feature = "experimental_metadata_attributes" ) ) ]
257
- assert_eq ! ( attributes . len ( ) , 3 ) ;
256
+ assert_eq ! ( log . record . attributes_len ( ) , 3 ) ;
258
257
#[ cfg( feature = "experimental_metadata_attributes" ) ]
259
- assert_eq ! ( attributes. len( ) , 8 ) ;
260
- assert ! ( attributes. contains( & Some ( ( Key :: new( "event_id" ) , 20 . into( ) ) ) ) ) ;
261
- assert ! ( attributes. contains( & Some ( ( Key :: new( "user_name" ) , "otel" . into( ) ) ) ) ) ;
262
- assert ! ( attributes. contains( & Some ( (
263
- Key :: new( "user_email" ) ,
264
- "otel@opentelemetry.io" . into( )
265
- ) ) ) ) ;
258
+ assert_eq ! ( log. record. attributes_len( ) , 8 ) ;
259
+ assert ! ( log
260
+ . record
261
+ . attributes_contains( & Key :: new( "event_id" ) , & AnyValue :: Int ( 20 ) ) ) ;
262
+ assert ! ( log
263
+ . record
264
+ . attributes_contains( & Key :: new( "user_name" ) , & AnyValue :: String ( "otel" . into( ) ) ) ) ;
265
+ assert ! ( log. record. attributes_contains(
266
+ & Key :: new( "user_email" ) ,
267
+ & AnyValue :: String ( "otel@opentelemetry.io" . into( ) )
268
+ ) ) ;
269
+
266
270
#[ cfg( feature = "experimental_metadata_attributes" ) ]
267
271
{
268
- assert ! ( attributes. contains( & Some ( ( Key :: new( "code.filename" ) , "layer.rs" . into( ) ) ) ) ) ;
269
- assert ! ( attributes. contains( & Some ( (
270
- Key :: new( "code.namespace" ) ,
271
- "opentelemetry_appender_tracing::layer::tests" . into( )
272
- ) ) ) ) ;
272
+ assert ! ( log. record. attributes_contains(
273
+ & Key :: new( "code.filename" ) ,
274
+ & AnyValue :: String ( "layer.rs" . into( ) )
275
+ ) ) ;
276
+ assert ! ( log. record. attributes_contains(
277
+ & Key :: new( "code.namespace" ) ,
278
+ & AnyValue :: String ( "opentelemetry_appender_tracing::layer::tests" . into( ) )
279
+ ) ) ;
273
280
// The other 3 experimental_metadata_attributes are too unstable to check their value.
274
281
// Ex.: The path will be different on a Windows and Linux machine.
275
282
// Ex.: The line can change easily if someone makes changes in this source file.
276
- let attributes_key: Vec < Key > = attributes
277
- . iter ( )
278
- . filter_map ( |attr| match attr {
279
- Some ( ( key, _) ) => Some ( key. clone ( ) ) ,
280
- None => None ,
281
- } )
283
+ let attributes_key: Vec < Key > = log
284
+ . record
285
+ . attributes_iter ( )
286
+ . map ( |( key, _) | key. clone ( ) )
282
287
. collect ( ) ;
283
288
284
289
assert ! ( attributes_key. contains( & Key :: new( "code.filepath" ) ) ) ;
@@ -354,35 +359,38 @@ mod tests {
354
359
) ;
355
360
356
361
// validate attributes.
357
- let attributes = log. record . attributes . clone ( ) ;
358
362
#[ cfg( not( feature = "experimental_metadata_attributes" ) ) ]
359
- assert_eq ! ( attributes . len ( ) , 3 ) ;
363
+ assert_eq ! ( log . record . attributes_len ( ) , 3 ) ;
360
364
#[ cfg( feature = "experimental_metadata_attributes" ) ]
361
- assert_eq ! ( attributes. len( ) , 8 ) ;
362
- assert ! ( attributes. contains( & Some ( ( Key :: new( "event_id" ) , 20 . into( ) ) ) ) ) ;
363
- assert ! ( attributes. contains( & Some ( ( Key :: new( "user_name" ) , "otel" . into( ) ) ) ) ) ;
364
- assert ! ( attributes. contains( & Some ( (
365
- Key :: new( "user_email" ) ,
366
- "otel@opentelemetry.io" . into( )
367
- ) ) ) ) ;
365
+ assert_eq ! ( log. record. attributes_len( ) , 8 ) ;
366
+ assert ! ( log
367
+ . record
368
+ . attributes_contains( & Key :: new( "event_id" ) , & AnyValue :: Int ( 20 . into( ) ) ) ) ;
369
+ assert ! ( log
370
+ . record
371
+ . attributes_contains( & Key :: new( "user_name" ) , & AnyValue :: String ( "otel" . into( ) ) ) ) ;
372
+ assert ! ( log. record. attributes_contains(
373
+ & Key :: new( "user_email" ) ,
374
+ & AnyValue :: String ( "otel@opentelemetry.io" . into( ) )
375
+ ) ) ;
368
376
#[ cfg( feature = "experimental_metadata_attributes" ) ]
369
377
{
370
- assert ! ( attributes. contains( & Some ( ( Key :: new( "code.filename" ) , "layer.rs" . into( ) ) ) ) ) ;
371
- assert ! ( attributes. contains( & Some ( (
372
- Key :: new( "code.namespace" ) ,
373
- "opentelemetry_appender_tracing::layer::tests" . into( )
374
- ) ) ) ) ;
378
+ assert ! ( log. record. attributes_contains(
379
+ & Key :: new( "code.filename" ) ,
380
+ & AnyValue :: String ( "layer.rs" . into( ) )
381
+ ) ) ;
382
+ assert ! ( log. record. attributes_contains(
383
+ & Key :: new( "code.namespace" ) ,
384
+ & AnyValue :: String ( "opentelemetry_appender_tracing::layer::tests" . into( ) )
385
+ ) ) ;
375
386
// The other 3 experimental_metadata_attributes are too unstable to check their value.
376
387
// Ex.: The path will be different on a Windows and Linux machine.
377
388
// Ex.: The line can change easily if someone makes changes in this source file.
378
389
379
- //let attributes_key: Vec<Key> = attributes.iter().map(|(key, _)| key.clone()).collect();
380
- let attributes_key: Vec < Key > = attributes
381
- . iter ( )
382
- . filter_map ( |attr| match attr {
383
- Some ( ( key, _) ) => Some ( key. clone ( ) ) ,
384
- None => None ,
385
- } )
390
+ let attributes_key: Vec < Key > = log
391
+ . record
392
+ . attributes_iter ( )
393
+ . map ( |( key, _) | key. clone ( ) )
386
394
. collect ( ) ;
387
395
assert ! ( attributes_key. contains( & Key :: new( "code.filepath" ) ) ) ;
388
396
assert ! ( attributes_key. contains( & Key :: new( "code.lineno" ) ) ) ;
@@ -426,30 +434,27 @@ mod tests {
426
434
// Validate trace context is none.
427
435
assert ! ( log. record. trace_context. is_none( ) ) ;
428
436
429
- // Validate attributes
430
- #[ cfg( feature = "experimental_metadata_attributes" ) ]
431
- let attributes = log. record . attributes . clone ( ) ;
432
-
433
437
// Attributes can be polluted when we don't use this feature.
434
438
#[ cfg( feature = "experimental_metadata_attributes" ) ]
435
- assert_eq ! ( attributes . len ( ) , 5 ) ;
439
+ assert_eq ! ( log . record . attributes_len ( ) , 5 ) ;
436
440
437
441
#[ cfg( feature = "experimental_metadata_attributes" ) ]
438
442
{
439
- assert ! ( attributes. contains( & ( Some ( ( Key :: new( "code.filename" ) , "layer.rs" . into( ) ) ) ) ) ) ;
440
- assert ! ( attributes. contains( & Some ( (
441
- Key :: new( "code.namespace" ) ,
442
- "opentelemetry_appender_tracing::layer::tests" . into( )
443
- ) ) ) ) ;
443
+ assert ! ( log. record. attributes_contains(
444
+ & Key :: new( "code.filename" ) ,
445
+ & AnyValue :: String ( "layer.rs" . into( ) )
446
+ ) ) ;
447
+ assert ! ( log. record. attributes_contains(
448
+ & Key :: new( "code.namespace" ) ,
449
+ & AnyValue :: String ( "opentelemetry_appender_tracing::layer::tests" . into( ) )
450
+ ) ) ;
444
451
// The other 3 experimental_metadata_attributes are too unstable to check their value.
445
452
// Ex.: The path will be different on a Windows and Linux machine.
446
453
// Ex.: The line can change easily if someone makes changes in this source file.
447
- let attributes_key: Vec < Key > = attributes
448
- . iter ( )
449
- . filter_map ( |attr| match attr {
450
- Some ( ( key, _) ) => Some ( key. clone ( ) ) ,
451
- None => None ,
452
- } )
454
+ let attributes_key: Vec < Key > = log
455
+ . record
456
+ . attributes_iter ( )
457
+ . map ( |( key, _) | key. clone ( ) )
453
458
. collect ( ) ;
454
459
assert ! ( attributes_key. contains( & Key :: new( "code.filepath" ) ) ) ;
455
460
assert ! ( attributes_key. contains( & Key :: new( "code.lineno" ) ) ) ;
@@ -525,29 +530,27 @@ mod tests {
525
530
) ;
526
531
527
532
// validate attributes.
528
- #[ cfg( feature = "experimental_metadata_attributes" ) ]
529
- let attributes = log. record . attributes . clone ( ) ;
530
-
531
533
// Attributes can be polluted when we don't use this feature.
532
534
#[ cfg( feature = "experimental_metadata_attributes" ) ]
533
- assert_eq ! ( attributes . len ( ) , 5 ) ;
535
+ assert_eq ! ( log . record . attributes_len ( ) , 5 ) ;
534
536
535
537
#[ cfg( feature = "experimental_metadata_attributes" ) ]
536
538
{
537
- assert ! ( attributes. contains( & Some ( ( Key :: new( "code.filename" ) , "layer.rs" . into( ) ) ) ) ) ;
538
- assert ! ( attributes. contains( & Some ( (
539
- Key :: new( "code.namespace" ) ,
540
- "opentelemetry_appender_tracing::layer::tests" . into( )
541
- ) ) ) ) ;
539
+ assert ! ( log. record. attributes_contains(
540
+ & Key :: new( "code.filename" ) ,
541
+ & AnyValue :: String ( "layer.rs" . into( ) )
542
+ ) ) ;
543
+ assert ! ( log. record. attributes_contains(
544
+ & Key :: new( "code.namespace" ) ,
545
+ & AnyValue :: String ( "opentelemetry_appender_tracing::layer::tests" . into( ) )
546
+ ) ) ;
542
547
// The other 3 experimental_metadata_attributes are too unstable to check their value.
543
548
// Ex.: The path will be different on a Windows and Linux machine.
544
549
// Ex.: The line can change easily if someone makes changes in this source file.
545
- let attributes_key: Vec < Key > = attributes
546
- . iter ( )
547
- . filter_map ( |attr| match attr {
548
- Some ( ( key, _) ) => Some ( key. clone ( ) ) ,
549
- None => None ,
550
- } )
550
+ let attributes_key: Vec < Key > = log
551
+ . record
552
+ . attributes_iter ( )
553
+ . map ( |( key, _) | key. clone ( ) )
551
554
. collect ( ) ;
552
555
assert ! ( attributes_key. contains( & Key :: new( "code.filepath" ) ) ) ;
553
556
assert ! ( attributes_key. contains( & Key :: new( "code.lineno" ) ) ) ;
0 commit comments