@@ -163,6 +163,10 @@ pub fn ourlog_merge_otel(ourlog: &mut Annotated<OurLog>) {
163
163
} )
164
164
. unwrap_or_default ( ) ;
165
165
166
+ // This is separate from the sdk provided time since Relay always acts as the collector in Sentry.
167
+ // We may change this in the future with forwarding Relays.
168
+ let observed_time_unix_nano = UnixTimestamp :: now ( ) . as_nanos ( ) ;
169
+
166
170
attributes. insert (
167
171
"sentry.severity_text" . to_owned ( ) ,
168
172
Annotated :: new ( Attribute :: new (
@@ -203,7 +207,7 @@ pub fn ourlog_merge_otel(ourlog: &mut Annotated<OurLog>) {
203
207
"sentry.observed_timestamp_nanos" . to_owned ( ) ,
204
208
Annotated :: new ( Attribute :: new (
205
209
AttributeType :: String ,
206
- Value :: String ( timestamp_nanos . to_string ( ) ) ,
210
+ Value :: String ( observed_time_unix_nano . to_string ( ) ) ,
207
211
) ) ,
208
212
) ;
209
213
attributes. insert (
@@ -476,8 +480,34 @@ mod tests {
476
480
}
477
481
}"# ;
478
482
483
+ let before_test = UnixTimestamp :: now ( ) . as_nanos ( ) ;
479
484
let mut merged_log = Annotated :: < OurLog > :: from_json ( json) . unwrap ( ) ;
480
485
ourlog_merge_otel ( & mut merged_log) ;
486
+ let after_test = UnixTimestamp :: now ( ) . as_nanos ( ) ;
487
+
488
+ // Test the observed timestamp separately
489
+ let observed_timestamp = merged_log
490
+ . value ( )
491
+ . and_then ( |log| log. attribute ( "sentry.observed_timestamp_nanos" ) )
492
+ . and_then ( |attr| attr. as_str ( ) . and_then ( |s| s. parse :: < u64 > ( ) . ok ( ) ) )
493
+ . unwrap_or ( 0 ) ;
494
+
495
+ assert ! ( observed_timestamp > 0 ) ;
496
+ assert ! ( observed_timestamp >= before_test) ;
497
+ assert ! ( observed_timestamp <= after_test) ;
498
+
499
+ // Set observed timestamp to a fixed value for snapshot testing
500
+ if let Some ( log) = merged_log. value_mut ( ) {
501
+ if let Some ( attributes) = log. attributes . value_mut ( ) {
502
+ attributes. insert (
503
+ "sentry.observed_timestamp_nanos" . to_owned ( ) ,
504
+ Annotated :: new ( Attribute :: new (
505
+ AttributeType :: String ,
506
+ Value :: String ( "946684800000000000" . to_string ( ) ) ,
507
+ ) ) ,
508
+ ) ;
509
+ }
510
+ }
481
511
482
512
insta:: assert_debug_snapshot!( merged_log, @r###"
483
513
OurLog {
@@ -608,7 +638,34 @@ mod tests {
608
638
body : Annotated :: new ( "somebody" . into ( ) ) ,
609
639
..Default :: default ( )
610
640
} ) ;
641
+
642
+ let before_test = UnixTimestamp :: now ( ) . as_nanos ( ) ;
611
643
ourlog_merge_otel ( & mut ourlog) ;
644
+ let after_test = UnixTimestamp :: now ( ) . as_nanos ( ) ;
645
+
646
+ // Test the observed timestamp separately
647
+ let observed_timestamp = ourlog
648
+ . value ( )
649
+ . and_then ( |log| log. attribute ( "sentry.observed_timestamp_nanos" ) )
650
+ . and_then ( |attr| attr. as_str ( ) . and_then ( |s| s. parse :: < u64 > ( ) . ok ( ) ) )
651
+ . unwrap_or ( 0 ) ;
652
+
653
+ assert ! ( observed_timestamp > 0 ) ;
654
+ assert ! ( observed_timestamp >= before_test) ;
655
+ assert ! ( observed_timestamp <= after_test) ;
656
+
657
+ // Set observed timestamp to a fixed value for snapshot testing
658
+ if let Some ( log) = ourlog. value_mut ( ) {
659
+ if let Some ( attributes) = log. attributes . value_mut ( ) {
660
+ attributes. insert (
661
+ "sentry.observed_timestamp_nanos" . to_owned ( ) ,
662
+ Annotated :: new ( Attribute :: new (
663
+ AttributeType :: String ,
664
+ Value :: String ( "1638144000000000000" . to_string ( ) ) ,
665
+ ) ) ,
666
+ ) ;
667
+ }
668
+ }
612
669
613
670
insta:: assert_debug_snapshot!( ourlog, @r#"
614
671
OurLog {
0 commit comments