File tree Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Expand file tree Collapse file tree 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):
348348 if not client .options ["_experiments" ].get ("enable_logs" , False ):
349349 return
350350
351- SentryLogsHandler ._capture_log_from_record (client , record )
351+ self ._capture_log_from_record (client , record )
352352
353- @staticmethod
354- def _capture_log_from_record (client , record ):
353+ def _capture_log_from_record (self , client , record ):
355354 # type: (BaseClient, LogRecord) -> None
356355 scope = sentry_sdk .get_current_scope ()
357356 otel_severity_number , otel_severity_text = _python_level_to_otel (record .levelno )
358357 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"
362360 if isinstance (record .msg , str ):
363361 attrs ["sentry.message.template" ] = record .msg
364362 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):
393393 assert attrs ["code.file.path" ] == "blah/path.py"
394394
395395
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+
396417def test_auto_flush_logs_after_100 (sentry_init , capture_envelopes ):
397418 """
398419 If you log >100 logs, it should automatically trigger a flush.
You can’t perform that action at this time.
0 commit comments