@@ -114,6 +114,19 @@ impl<LR: LogRecord> tracing::field::Visit for EventVisitor<'_, LR> {
114114 . add_attribute ( Key :: new ( field. name ( ) ) , AnyValue :: from ( value) ) ;
115115 }
116116
117+ fn record_u64 ( & mut self , field : & tracing:: field:: Field , value : u64 ) {
118+ match i64:: try_from ( value) {
119+ Ok ( signed) => {
120+ self . log_record
121+ . add_attribute ( Key :: new ( field. name ( ) ) , AnyValue :: from ( signed) ) ;
122+ }
123+ Err ( _) => {
124+ self . log_record
125+ . add_attribute ( Key :: new ( field. name ( ) ) , AnyValue :: from ( format ! ( "{value:?}" ) ) ) ;
126+ }
127+ }
128+ }
129+
117130 // TODO: Remaining field types from AnyValue : Bytes, ListAny, Boolean
118131}
119132
@@ -331,7 +344,11 @@ mod tests {
331344 let _guard = tracing:: subscriber:: set_default ( subscriber) ;
332345
333346 // Act
334- error ! ( name
: "my-event-name" , target
: "my-system" , event_id =
20 , user_name =
"otel" , user_email =
"[email protected] " ) ; 347+ let small_u64value: u64 = 42 ;
348+ let big_u64value: u64 = u64:: MAX ;
349+ let small_usizevalue: usize = 42 ;
350+ let big_usizevalue: usize = usize:: MAX ;
351+ error ! ( name
: "my-event-name" , target
: "my-system" , event_id =
20 , small_u64value
, big_u64value
, small_usizevalue
, big_usizevalue
, user_name =
"otel" , user_email =
"[email protected] " ) ; 335352 assert ! ( logger_provider. force_flush( ) . is_ok( ) ) ;
336353
337354 // Assert TODO: move to helper methods
@@ -362,9 +379,9 @@ mod tests {
362379
363380 // Validate attributes
364381 #[ cfg( not( feature = "experimental_metadata_attributes" ) ) ]
365- assert_eq ! ( log. record. attributes_iter( ) . count( ) , 3 ) ;
366- #[ cfg( feature = "experimental_metadata_attributes" ) ]
367382 assert_eq ! ( log. record. attributes_iter( ) . count( ) , 7 ) ;
383+ #[ cfg( feature = "experimental_metadata_attributes" ) ]
384+ assert_eq ! ( log. record. attributes_iter( ) . count( ) , 11 ) ;
368385 assert ! ( attributes_contains(
369386 & log. record,
370387 & Key :: new( "event_id" ) ,
@@ -380,6 +397,26 @@ mod tests {
380397 & Key :: new( "user_email" ) ,
381398 & AnyValue :: String ( "[email protected] " . into
( ) ) 382399 ) ) ;
400+ assert ! ( attributes_contains(
401+ & log. record,
402+ & Key :: new( "small_u64value" ) ,
403+ & AnyValue :: Int ( 42 . into( ) )
404+ ) ) ;
405+ assert ! ( attributes_contains(
406+ & log. record,
407+ & Key :: new( "big_u64value" ) ,
408+ & AnyValue :: String ( format!( "{}" , u64 :: MAX ) . into( ) )
409+ ) ) ;
410+ assert ! ( attributes_contains(
411+ & log. record,
412+ & Key :: new( "small_usizevalue" ) ,
413+ & AnyValue :: Int ( 42 . into( ) )
414+ ) ) ;
415+ assert ! ( attributes_contains(
416+ & log. record,
417+ & Key :: new( "big_usizevalue" ) ,
418+ & AnyValue :: String ( format!( "{}" , u64 :: MAX ) . into( ) )
419+ ) ) ;
383420 #[ cfg( feature = "experimental_metadata_attributes" ) ]
384421 {
385422 assert ! ( attributes_contains(
0 commit comments