@@ -346,7 +346,6 @@ def test_logging_errors(sentry_init, capture_envelopes):
346346 error_event_2 = envelopes [1 ].items [0 ].payload .json
347347 assert error_event_2 ["level" ] == "error"
348348
349- print (envelopes )
350349 logs = envelopes_to_logs (envelopes )
351350 assert logs [0 ]["severity_text" ] == "error"
352351 assert "sentry.message.template" not in logs [0 ]["attributes" ]
@@ -364,6 +363,36 @@ def test_logging_errors(sentry_init, capture_envelopes):
364363 assert len (logs ) == 2
365364
366365
366+ def test_log_strips_project_root (sentry_init , capture_envelopes ):
367+ """
368+ The python logger should strip project roots from the log record path
369+ """
370+ sentry_init (
371+ _experiments = {"enable_logs" : True },
372+ project_root = "/custom/test" ,
373+ )
374+ envelopes = capture_envelopes ()
375+
376+ python_logger = logging .Logger ("test-logger" )
377+ python_logger .handle (
378+ logging .LogRecord (
379+ name = "test-logger" ,
380+ level = logging .WARN ,
381+ pathname = "/custom/test/blah/path.py" ,
382+ lineno = 123 ,
383+ msg = "This is a test log with a custom pathname" ,
384+ args = (),
385+ exc_info = None ,
386+ )
387+ )
388+ get_client ().flush ()
389+
390+ logs = envelopes_to_logs (envelopes )
391+ assert len (logs ) == 1
392+ attrs = logs [0 ]["attributes" ]
393+ assert attrs ["code.file.path" ] == "blah/path.py"
394+
395+
367396def test_auto_flush_logs_after_100 (sentry_init , capture_envelopes ):
368397 """
369398 If you log >100 logs, it should automatically trigger a flush.
0 commit comments