@@ -388,6 +388,68 @@ async fn f64_histogram_with_attributes_is_exported() {
388
388
exporter. export ( ) . unwrap ( ) ;
389
389
}
390
390
391
+ #[ tokio:: test]
392
+ async fn display_attribute_is_exported ( ) {
393
+ let ( subscriber, exporter) = init_subscriber (
394
+ "hello_world" . to_string ( ) ,
395
+ InstrumentKind :: Counter ,
396
+ 1_u64 ,
397
+ Some ( AttributeSet :: from (
398
+ [ KeyValue :: new ( "display_key_1" , "display: foo" ) ] . as_slice ( ) ,
399
+ ) ) ,
400
+ ) ;
401
+
402
+ struct DisplayAttribute ( String ) ;
403
+
404
+ impl std:: fmt:: Display for DisplayAttribute {
405
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
406
+ write ! ( f, "display: {}" , self . 0 )
407
+ }
408
+ }
409
+
410
+ let display_attribute = DisplayAttribute ( "foo" . to_string ( ) ) ;
411
+
412
+ tracing:: subscriber:: with_default ( subscriber, || {
413
+ tracing:: info!(
414
+ monotonic_counter. hello_world = 1_u64 ,
415
+ display_key_1 = %display_attribute,
416
+ ) ;
417
+ } ) ;
418
+
419
+ exporter. export ( ) . unwrap ( ) ;
420
+ }
421
+
422
+ #[ tokio:: test]
423
+ async fn debug_attribute_is_exported ( ) {
424
+ let ( subscriber, exporter) = init_subscriber (
425
+ "hello_world" . to_string ( ) ,
426
+ InstrumentKind :: Counter ,
427
+ 1_u64 ,
428
+ Some ( AttributeSet :: from (
429
+ [ KeyValue :: new ( "debug_key_1" , "debug: foo" ) ] . as_slice ( ) ,
430
+ ) ) ,
431
+ ) ;
432
+
433
+ struct DebugAttribute ( String ) ;
434
+
435
+ impl std:: fmt:: Debug for DebugAttribute {
436
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
437
+ write ! ( f, "debug: {}" , self . 0 )
438
+ }
439
+ }
440
+
441
+ let debug_attribute = DebugAttribute ( "foo" . to_string ( ) ) ;
442
+
443
+ tracing:: subscriber:: with_default ( subscriber, || {
444
+ tracing:: info!(
445
+ monotonic_counter. hello_world = 1_u64 ,
446
+ debug_key_1 = ?debug_attribute,
447
+ ) ;
448
+ } ) ;
449
+
450
+ exporter. export ( ) . unwrap ( ) ;
451
+ }
452
+
391
453
fn init_subscriber < T > (
392
454
expected_metric_name : String ,
393
455
expected_instrument_kind : InstrumentKind ,
0 commit comments