@@ -96,6 +96,10 @@ def test_ourlog_extraction_with_otel_logs(
96
96
97
97
timestamp_proto .FromSeconds (int (timestamp ))
98
98
99
+ start_timestamp_nanos = int ((start .timestamp () - 1 ) * 1e9 )
100
+ end = datetime .now (timezone .utc )
101
+ end_timestamp_nanos = int ((end .timestamp () + 1 ) * 1e9 )
102
+
99
103
expected_logs = [
100
104
MessageToDict (
101
105
TraceItem (
@@ -136,12 +140,16 @@ def test_ourlog_extraction_with_otel_logs(
136
140
logs = [MessageToDict (log ) for log in ourlogs_consumer .get_ourlogs ()]
137
141
138
142
for log , expected_log in zip (logs , expected_logs ):
139
- # we can't generate uuid7 with a specific timestamp
140
- # in Python just yet so we're overriding it
141
143
expected_log ["itemId" ] = log ["itemId" ]
142
144
expected_log ["received" ] = time_within_delta ()
143
145
144
- # This field is set by Relay so we need to remove it
146
+ observed_timestamp_str = log ["attributes" ]["sentry.observed_timestamp_nanos" ][
147
+ "stringValue"
148
+ ]
149
+ observed_timestamp = int (observed_timestamp_str )
150
+ assert observed_timestamp > 0
151
+ assert start_timestamp_nanos < observed_timestamp < end_timestamp_nanos
152
+
145
153
del log ["attributes" ]["sentry.observed_timestamp_nanos" ]
146
154
147
155
assert logs == expected_logs
@@ -266,6 +274,10 @@ def test_ourlog_extraction_with_sentry_logs(
266
274
267
275
relay .send_envelope (project_id , envelope )
268
276
277
+ start_timestamp_nanos = int ((start .timestamp () - 1 ) * 1e9 )
278
+ end = datetime .now (timezone .utc )
279
+ end_timestamp_nanos = int ((end .timestamp () + 1 ) * 1e9 )
280
+
269
281
timestamp_nanos = int (timestamp * 1e6 ) * 1000
270
282
timestamp_proto = Timestamp ()
271
283
@@ -293,9 +305,6 @@ def test_ourlog_extraction_with_sentry_logs(
293
305
"sentry.severity_text" : AnyValue (string_value = "error" ),
294
306
"sentry.span_id" : AnyValue (string_value = "eee19b7ec3c1b175" ),
295
307
"sentry.trace_flags" : AnyValue (int_value = 0 ),
296
- "sentry.observed_timestamp_nanos" : AnyValue (
297
- string_value = str (timestamp_nanos )
298
- ),
299
308
"sentry.timestamp_precise" : AnyValue (int_value = timestamp_nanos ),
300
309
"sentry.timestamp_nanos" : AnyValue (
301
310
string_value = str (timestamp_nanos )
@@ -328,9 +337,6 @@ def test_ourlog_extraction_with_sentry_logs(
328
337
"sentry.severity_text" : AnyValue (string_value = "info" ),
329
338
"sentry.trace_flags" : AnyValue (int_value = 0 ),
330
339
"sentry.span_id" : AnyValue (string_value = "eee19b7ec3c1b174" ),
331
- "sentry.observed_timestamp_nanos" : AnyValue (
332
- string_value = str (timestamp_nanos )
333
- ),
334
340
"string.attribute" : AnyValue (string_value = "some string" ),
335
341
"valid_string_with_other" : AnyValue (string_value = "test" ),
336
342
"sentry.timestamp_precise" : AnyValue (int_value = timestamp_nanos ),
@@ -348,11 +354,18 @@ def test_ourlog_extraction_with_sentry_logs(
348
354
logs = [MessageToDict (log ) for log in ourlogs_consumer .get_ourlogs ()]
349
355
350
356
for log , expected_log in zip (logs , expected_logs ):
351
- # we can't generate uuid7 with a specific timestamp
352
- # in Python just yet so we're overriding it
353
357
expected_log ["itemId" ] = log ["itemId" ]
354
358
expected_log ["received" ] = time_within_delta ()
355
359
360
+ observed_timestamp_str = log ["attributes" ]["sentry.observed_timestamp_nanos" ][
361
+ "stringValue"
362
+ ]
363
+ observed_timestamp = int (observed_timestamp_str )
364
+ assert observed_timestamp > 0
365
+ assert start_timestamp_nanos < observed_timestamp < end_timestamp_nanos
366
+
367
+ del log ["attributes" ]["sentry.observed_timestamp_nanos" ]
368
+
356
369
assert logs == expected_logs
357
370
358
371
ourlogs_consumer .assert_empty ()
@@ -383,6 +396,10 @@ def test_ourlog_extraction_with_sentry_logs_with_missing_fields(
383
396
384
397
relay .send_envelope (project_id , envelope )
385
398
399
+ start_timestamp_nanos = int ((start .timestamp () - 1 ) * 1e9 )
400
+ end = datetime .now (timezone .utc )
401
+ end_timestamp_nanos = int ((end .timestamp () + 1 ) * 1e9 )
402
+
386
403
timestamp_nanos = int (timestamp * 1e6 ) * 1000
387
404
timestamp_proto = Timestamp ()
388
405
@@ -405,9 +422,6 @@ def test_ourlog_extraction_with_sentry_logs_with_missing_fields(
405
422
"sentry.body" : AnyValue (string_value = "Example log record 2" ),
406
423
"sentry.browser.name" : AnyValue (string_value = "Python Requests" ),
407
424
"sentry.browser.version" : AnyValue (string_value = "2.32" ),
408
- "sentry.observed_timestamp_nanos" : AnyValue (
409
- string_value = str (timestamp_nanos )
410
- ),
411
425
"sentry.severity_number" : AnyValue (int_value = 13 ),
412
426
"sentry.severity_text" : AnyValue (string_value = "warn" ),
413
427
"sentry.timestamp_nanos" : AnyValue (
@@ -426,11 +440,18 @@ def test_ourlog_extraction_with_sentry_logs_with_missing_fields(
426
440
logs = [MessageToDict (log ) for log in ourlogs_consumer .get_ourlogs ()]
427
441
428
442
for log , expected_log in zip (logs , expected_logs ):
429
- # we can't generate uuid7 with a specific timestamp
430
- # in Python just yet so we're overriding it
431
443
expected_log ["itemId" ] = log ["itemId" ]
432
444
expected_log ["received" ] = time_within_delta ()
433
445
446
+ observed_timestamp_str = log ["attributes" ]["sentry.observed_timestamp_nanos" ][
447
+ "stringValue"
448
+ ]
449
+ observed_timestamp = int (observed_timestamp_str )
450
+ assert observed_timestamp > 0
451
+ assert start_timestamp_nanos < observed_timestamp < end_timestamp_nanos
452
+
453
+ del log ["attributes" ]["sentry.observed_timestamp_nanos" ]
454
+
434
455
assert logs == expected_logs
435
456
436
457
ourlogs_consumer .assert_empty ()
@@ -469,8 +490,8 @@ def test_ourlog_extraction_is_disabled_without_feature(
469
490
"131.0.0" ,
470
491
),
471
492
(
472
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" ,
473
- "Chrome " ,
493
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0 " ,
494
+ "Edge " ,
474
495
"120.0.0" ,
475
496
),
476
497
# Firefox desktop
@@ -544,6 +565,10 @@ def test_browser_name_version_extraction(
544
565
545
566
relay .send_envelope (project_id , envelope , headers = {"User-Agent" : user_agent })
546
567
568
+ start_timestamp_nanos = int ((start .timestamp () - 1 ) * 1e9 )
569
+ end = datetime .now (timezone .utc )
570
+ end_timestamp_nanos = int ((end .timestamp () + 1 ) * 1e9 )
571
+
547
572
timestamp_nanos = int (timestamp * 1e6 ) * 1000
548
573
timestamp_proto = Timestamp ()
549
574
@@ -571,9 +596,6 @@ def test_browser_name_version_extraction(
571
596
"sentry.severity_text" : AnyValue (string_value = "error" ),
572
597
"sentry.span_id" : AnyValue (string_value = "eee19b7ec3c1b175" ),
573
598
"sentry.trace_flags" : AnyValue (int_value = 0 ),
574
- "sentry.observed_timestamp_nanos" : AnyValue (
575
- string_value = str (timestamp_nanos )
576
- ),
577
599
"sentry.timestamp_precise" : AnyValue (int_value = timestamp_nanos ),
578
600
"sentry.timestamp_nanos" : AnyValue (string_value = str (timestamp_nanos )),
579
601
},
@@ -588,11 +610,18 @@ def test_browser_name_version_extraction(
588
610
assert len (logs ) == 1
589
611
log = logs [0 ]
590
612
591
- # we can't generate uuid7 with a specific timestamp
592
- # in Python just yet so we're overriding it
593
613
expected_log ["itemId" ] = log ["itemId" ]
594
614
expected_log ["received" ] = time_within_delta ()
595
615
616
+ observed_timestamp_str = log ["attributes" ]["sentry.observed_timestamp_nanos" ][
617
+ "stringValue"
618
+ ]
619
+ observed_timestamp = int (observed_timestamp_str )
620
+ assert observed_timestamp > 0
621
+ assert start_timestamp_nanos < observed_timestamp < end_timestamp_nanos
622
+
623
+ del log ["attributes" ]["sentry.observed_timestamp_nanos" ]
624
+
596
625
assert log == expected_log
597
626
598
627
ourlogs_consumer .assert_empty ()
0 commit comments