@@ -346,7 +346,6 @@ def test_logging_errors(sentry_init, capture_envelopes):
346
346
error_event_2 = envelopes [1 ].items [0 ].payload .json
347
347
assert error_event_2 ["level" ] == "error"
348
348
349
- print (envelopes )
350
349
logs = envelopes_to_logs (envelopes )
351
350
assert logs [0 ]["severity_text" ] == "error"
352
351
assert "sentry.message.template" not in logs [0 ]["attributes" ]
@@ -364,6 +363,36 @@ def test_logging_errors(sentry_init, capture_envelopes):
364
363
assert len (logs ) == 2
365
364
366
365
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
+
367
396
def test_auto_flush_logs_after_100 (sentry_init , capture_envelopes ):
368
397
"""
369
398
If you log >100 logs, it should automatically trigger a flush.
0 commit comments