diff --git a/sentry_sdk/integrations/logging.py b/sentry_sdk/integrations/logging.py index dddcc17334..75848bc985 100644 --- a/sentry_sdk/integrations/logging.py +++ b/sentry_sdk/integrations/logging.py @@ -119,7 +119,10 @@ def sentry_patched_callhandlers(self, record): # the integration. Otherwise we have a high chance of getting # into a recursion error when the integration is resolved # (this also is slower). - if ignored_loggers is not None and record.name not in ignored_loggers: + if ( + ignored_loggers is not None + and record.name.strip() not in ignored_loggers + ): integration = sentry_sdk.get_client().get_integration( LoggingIntegration ) @@ -164,7 +167,7 @@ def _can_record(self, record): # type: (LogRecord) -> bool """Prevents ignored loggers from recording""" for logger in _IGNORED_LOGGERS: - if fnmatch(record.name, logger): + if fnmatch(record.name.strip(), logger): return False return True diff --git a/tests/integrations/logging/test_logging.py b/tests/integrations/logging/test_logging.py index c08e960c00..557f3fc1b1 100644 --- a/tests/integrations/logging/test_logging.py +++ b/tests/integrations/logging/test_logging.py @@ -230,6 +230,18 @@ def test_ignore_logger(sentry_init, capture_events): assert not events +def test_ignore_logger_whitespace_padding(sentry_init, capture_events): + """Here we test insensitivity to whitespace padding of ignored loggers""" + sentry_init(integrations=[LoggingIntegration()], default_integrations=False) + events = capture_events() + + ignore_logger("testfoo") + + padded_logger = logging.getLogger(" testfoo ") + padded_logger.error("hi") + assert not events + + def test_ignore_logger_wildcard(sentry_init, capture_events): sentry_init(integrations=[LoggingIntegration()], default_integrations=False) events = capture_events()