Skip to content

Commit 8159cae

Browse files
authored
tests: General logs tests should use Sentry logs API (#5262)
The Sentry Logs functionality is currently tested in three places: 1. general logs functionality in `test_logs.py` 2. Loguru logs functionality in `integrations/loguru/test_loguru.py` 3. stdlib logging integration in `integrations/logging/test_logging.py` The idea is that 1. checks the general Sentry logs feature, while 2. and 3. check the Sentry logs integration with logging/Loguru. **This PR** changes the log calls in 1. to use the Sentry logs API directly (instead of the stdlib `logging` API) to make this distinction clearer.
1 parent d7aebef commit 8159cae

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

tests/test_logs.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,16 +342,16 @@ def test_logs_tied_to_spans(sentry_init, capture_envelopes):
342342
assert logs[0]["span_id"] == span.span_id
343343

344344

345+
@minimum_python_37
345346
def test_auto_flush_logs_after_100(sentry_init, capture_envelopes):
346347
"""
347348
If you log >100 logs, it should automatically trigger a flush.
348349
"""
349350
sentry_init(enable_logs=True)
350351
envelopes = capture_envelopes()
351352

352-
python_logger = logging.Logger("test-logger")
353353
for i in range(200):
354-
python_logger.warning("log #%d", i)
354+
sentry_sdk.logger.warning("log")
355355

356356
for _ in range(500):
357357
time.sleep(1.0 / 100.0)
@@ -361,15 +361,15 @@ def test_auto_flush_logs_after_100(sentry_init, capture_envelopes):
361361
raise AssertionError("200 logs were never flushed after five seconds")
362362

363363

364+
@minimum_python_37
364365
def test_log_user_attributes(sentry_init, capture_envelopes):
365366
"""User attributes are sent if enable_logs is True and send_default_pii is True."""
366367
sentry_init(enable_logs=True, send_default_pii=True)
367368

368369
sentry_sdk.set_user({"id": "1", "email": "[email protected]", "username": "test"})
369370
envelopes = capture_envelopes()
370371

371-
python_logger = logging.Logger("test-logger")
372-
python_logger.warning("Hello, world!")
372+
sentry_sdk.logger.warning("Hello, world!")
373373

374374
get_client().flush()
375375

@@ -384,15 +384,15 @@ def test_log_user_attributes(sentry_init, capture_envelopes):
384384
}
385385

386386

387+
@minimum_python_37
387388
def test_log_no_user_attributes_if_no_pii(sentry_init, capture_envelopes):
388389
"""User attributes are not if PII sending is off."""
389390
sentry_init(enable_logs=True, send_default_pii=False)
390391

391392
sentry_sdk.set_user({"id": "1", "email": "[email protected]", "username": "test"})
392393
envelopes = capture_envelopes()
393394

394-
python_logger = logging.Logger("test-logger")
395-
python_logger.warning("Hello, world!")
395+
sentry_sdk.logger.warning("Hello, world!")
396396

397397
get_client().flush()
398398

@@ -412,8 +412,7 @@ def test_auto_flush_logs_after_5s(sentry_init, capture_envelopes):
412412
sentry_init(enable_logs=True)
413413
envelopes = capture_envelopes()
414414

415-
python_logger = logging.Logger("test-logger")
416-
python_logger.warning("log #%d", 1)
415+
sentry_sdk.logger.warning("log")
417416

418417
for _ in range(100):
419418
time.sleep(1.0 / 10.0)

0 commit comments

Comments
 (0)