You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(logging): Strip log record.name for more robust matching (#4411)
Hi! In the Python SDK, more specifically
`sentry_sdk/integrations/logging.py`, a couple of loggers are ignored to
avoid recursion errors.
```py
_IGNORED_LOGGERS = set(
["sentry_sdk.errors", "urllib3.connectionpool", "urllib3.connection"]
)
```
Log records from these loggers are discarded, using an exact match on
`record.name`. Unforunately, this breaks if the user modifies
`record.name`, e.g. for formatting, which is what we were doing for log
display (before becoming aware that Sentry relied on it after
investigating an infinite recursion issue).
```py
class _LengthFormatter(logging.Formatter):
def format(self, record):
"""
Format a log record's header to a constant length
"""
if len(record.name) > _MAX_LOGGER_NAME_LENGTH:
sep = "..."
cut = _MAX_LOGGER_NAME_LENGTH // 3 - len(sep)
record.name = record.name[:cut] + sep + record.name[-(_MAX_LOGGER_NAME_LENGTH - cut - len(sep)) :]
record.name = record.name.ljust(_MAX_LOGGER_NAME_LENGTH)
record.levelname = record.levelname.ljust(_MAX_LOGGER_LEVEL_NAME_LENGTH)
return super().format(record)
```
As you can see, `record.name` is right-padded with blank spaces. We have
found a workaround since, but given that it has taken us quite some time
to find the issue, I thought that maybe it could affect others. This PR
proposes matching `record.name.strip()` instead for increased
robustness.
0 commit comments