Skip to content

Commit b7b7282

Browse files
committed
add comprehensive tests
1 parent a81e377 commit b7b7282

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

tests/integrations/loguru/test_loguru.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,103 @@ def test_logger_with_all_attributes(
473473
}
474474

475475

476+
def test_logger_capture_parameters_from_args(
477+
sentry_init, capture_envelopes, uninstall_integration, request
478+
):
479+
# This is currently not supported as regular args don't get added to extra
480+
# (which we use for populating the parameters). Adding this test to make that
481+
# explicit and so that it's easy to change later.
482+
uninstall_integration("loguru")
483+
request.addfinalizer(logger.remove)
484+
485+
sentry_init(enable_logs=True)
486+
envelopes = capture_envelopes()
487+
488+
logger.warning("Task ID: {}", 123)
489+
490+
sentry_sdk.get_client().flush()
491+
492+
logs = envelopes_to_logs(envelopes)
493+
494+
attributes = logs[0]["attributes"]
495+
assert "sentry.message.parameter.0" not in attributes
496+
497+
498+
def test_logger_capture_parameters_from_kwargs(
499+
sentry_init, capture_envelopes, uninstall_integration, request
500+
):
501+
uninstall_integration("loguru")
502+
request.addfinalizer(logger.remove)
503+
504+
sentry_init(enable_logs=True)
505+
envelopes = capture_envelopes()
506+
507+
logger.warning("Task ID: {task_id}", task_id=123)
508+
509+
sentry_sdk.get_client().flush()
510+
511+
logs = envelopes_to_logs(envelopes)
512+
513+
attributes = logs[0]["attributes"]
514+
assert attributes["sentry.message.parameter.task_id"] == 123
515+
516+
517+
def test_logger_capture_parameters_from_contextualize(
518+
sentry_init, capture_envelopes, uninstall_integration, request
519+
):
520+
uninstall_integration("loguru")
521+
request.addfinalizer(logger.remove)
522+
523+
sentry_init(enable_logs=True)
524+
envelopes = capture_envelopes()
525+
526+
with logger.contextualize(task_id=123):
527+
logger.warning("Log")
528+
529+
sentry_sdk.get_client().flush()
530+
531+
logs = envelopes_to_logs(envelopes)
532+
533+
attributes = logs[0]["attributes"]
534+
assert attributes["sentry.message.parameter.task_id"] == 123
535+
536+
537+
def test_logger_capture_parameters_from_bind(
538+
sentry_init, capture_envelopes, uninstall_integration, request
539+
):
540+
uninstall_integration("loguru")
541+
request.addfinalizer(logger.remove)
542+
543+
sentry_init(enable_logs=True)
544+
envelopes = capture_envelopes()
545+
546+
logger.bind(task_id=123).warning("Log")
547+
sentry_sdk.get_client().flush()
548+
549+
logs = envelopes_to_logs(envelopes)
550+
551+
attributes = logs[0]["attributes"]
552+
assert attributes["sentry.message.parameter.task_id"] == 123
553+
554+
555+
def test_logger_capture_parameters_from_patch(
556+
sentry_init, capture_envelopes, uninstall_integration, request
557+
):
558+
uninstall_integration("loguru")
559+
request.addfinalizer(logger.remove)
560+
561+
sentry_init(enable_logs=True)
562+
envelopes = capture_envelopes()
563+
564+
logger.patch(lambda record: record["extra"].update(task_id=123)).warning("Log")
565+
sentry_sdk.get_client().flush()
566+
567+
logs = envelopes_to_logs(envelopes)
568+
569+
attributes = logs[0]["attributes"]
570+
assert attributes["sentry.message.parameter.task_id"] == 123
571+
572+
476573
def test_no_parameters_no_template(
477574
sentry_init, capture_envelopes, uninstall_integration, request
478575
):

0 commit comments

Comments
 (0)