File tree 2 files changed +25
-6
lines changed 2 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -348,17 +348,15 @@ def emit(self, record):
348
348
if not client .options ["_experiments" ].get ("enable_logs" , False ):
349
349
return
350
350
351
- SentryLogsHandler ._capture_log_from_record (client , record )
351
+ self ._capture_log_from_record (client , record )
352
352
353
- @staticmethod
354
- def _capture_log_from_record (client , record ):
353
+ def _capture_log_from_record (self , client , record ):
355
354
# type: (BaseClient, LogRecord) -> None
356
355
scope = sentry_sdk .get_current_scope ()
357
356
otel_severity_number , otel_severity_text = _python_level_to_otel (record .levelno )
358
357
project_root = client .options ["project_root" ]
359
- attrs = {
360
- "sentry.origin" : "auto.logger.log" ,
361
- } # type: dict[str, str | bool | float | int]
358
+ attrs = self ._extra_from_record (record )
359
+ attrs ["sentry.origin" ] = "auto.logger.log"
362
360
if isinstance (record .msg , str ):
363
361
attrs ["sentry.message.template" ] = record .msg
364
362
if record .args is not None :
Original file line number Diff line number Diff line change @@ -393,6 +393,27 @@ 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 ):
397
+ """
398
+ The python logger should be able to log extra data
399
+ """
400
+ sentry_init (_experiments = {"enable_logs" : True })
401
+ envelopes = capture_envelopes ()
402
+
403
+ python_logger = logging .Logger ("test-logger" )
404
+ python_logger .warning (
405
+ "log #%d" ,
406
+ 1 ,
407
+ extra = {"foo" : "bar" , "numeric" : 42 , "more_complex" : {"nested" : "data" }},
408
+ )
409
+ get_client ().flush ()
410
+
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"}'
415
+
416
+
396
417
def test_auto_flush_logs_after_100 (sentry_init , capture_envelopes ):
397
418
"""
398
419
If you log >100 logs, it should automatically trigger a flush.
You can’t perform that action at this time.
0 commit comments