@@ -30,7 +30,7 @@ def _convert_attr(attr):
30
30
return attr ["value" ]
31
31
if attr ["value" ].startswith ("{" ):
32
32
try :
33
- return json .loads (attr ["stringValue " ])
33
+ return json .loads (attr ["value " ])
34
34
except ValueError :
35
35
pass
36
36
return str (attr ["value" ])
@@ -393,9 +393,9 @@ def test_log_strips_project_root(sentry_init, capture_envelopes):
393
393
assert attrs ["code.file.path" ] == "blah/path.py"
394
394
395
395
396
- def test_extra_data (sentry_init , capture_envelopes ):
396
+ def test_logger_with_all_attributes (sentry_init , capture_envelopes ):
397
397
"""
398
- The python logger should be able to log extra data
398
+ The python logger should be able to log all attributes, including extra data.
399
399
"""
400
400
sentry_init (_experiments = {"enable_logs" : True })
401
401
envelopes = capture_envelopes ()
@@ -409,9 +409,60 @@ def test_extra_data(sentry_init, capture_envelopes):
409
409
get_client ().flush ()
410
410
411
411
logs = envelopes_to_logs (envelopes )
412
- assert logs [0 ]["attributes" ]["foo" ] == "bar"
413
- assert logs [0 ]["attributes" ]["numeric" ] == 42
414
- assert logs [0 ]["attributes" ]["more_complex" ] == '{"nested": "data"}'
412
+
413
+ attributes = logs [0 ]["attributes" ]
414
+
415
+ assert "process.pid" in attributes
416
+ assert isinstance (attributes ["process.pid" ], int )
417
+ del attributes ["process.pid" ]
418
+
419
+ assert "sentry.release" in attributes
420
+ assert isinstance (attributes ["sentry.release" ], str )
421
+ del attributes ["sentry.release" ]
422
+
423
+ assert "server.address" in attributes
424
+ assert isinstance (attributes ["server.address" ], str )
425
+ del attributes ["server.address" ]
426
+
427
+ assert "thread.id" in attributes
428
+ assert isinstance (attributes ["thread.id" ], int )
429
+ del attributes ["thread.id" ]
430
+
431
+ assert "code.file.path" in attributes
432
+ assert isinstance (attributes ["code.file.path" ], str )
433
+ del attributes ["code.file.path" ]
434
+
435
+ assert "code.function.name" in attributes
436
+ assert isinstance (attributes ["code.function.name" ], str )
437
+ del attributes ["code.function.name" ]
438
+
439
+ assert "code.line.number" in attributes
440
+ assert isinstance (attributes ["code.line.number" ], int )
441
+ del attributes ["code.line.number" ]
442
+
443
+ assert "process.executable.name" in attributes
444
+ assert isinstance (attributes ["process.executable.name" ], str )
445
+ del attributes ["process.executable.name" ]
446
+
447
+ assert "thread.name" in attributes
448
+ assert isinstance (attributes ["thread.name" ], str )
449
+ del attributes ["thread.name" ]
450
+
451
+ # Assert on the remaining non-dynamic attributes.
452
+ assert attributes == {
453
+ "foo" : "bar" ,
454
+ "numeric" : 42 ,
455
+ "more_complex" : "{'nested': 'data'}" ,
456
+ "logger.name" : "test-logger" ,
457
+ "sentry.origin" : "auto.logger.log" ,
458
+ "sentry.message.template" : "log #%d" ,
459
+ "sentry.message.parameters.0" : 1 ,
460
+ "sentry.environment" : "production" ,
461
+ "sentry.sdk.name" : "sentry.python" ,
462
+ "sentry.sdk.version" : VERSION ,
463
+ "sentry.severity_number" : 13 ,
464
+ "sentry.severity_text" : "warn" ,
465
+ }
415
466
416
467
417
468
def test_auto_flush_logs_after_100 (sentry_init , capture_envelopes ):
0 commit comments