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
{{ message }}
Repository navigation
SentryLogsHandler.emit formats every log record before checking has_logs_enabled #7402
SentryLogsHandler.emit calls self.format(record) before it checks whether Sentry Logs are enabled, so every logging record in the process pays a full Formatter.format even when the feature is off. Measured at ~1.9 µs per log record on CPython 3.14 / Apple M2.
Where
sentry_sdk/integrations/logging.py:
classSentryLogsHandler(_BaseHandler):
defemit(self, record):
withcapture_internal_exceptions():
self.format(record) # <-- unconditionalifnotself._can_record(record):
returnclient=sentry_sdk.get_client()
ifnotclient.is_active():
returnifnothas_logs_enabled(client.options): # <-- the cheap check comes lastreturnself._capture_log_from_record(client, record)
LoggingIntegration.__init__ defaults sentry_logs_level=DEFAULT_LEVEL (INFO), so the handler is installed for every user, and LoggingIntegration is a default integration. Applications that never set enable_logs - the default - format every INFO+ record for nothing.
BreadcrumbHandler.emit has the same shape, but there the formatting is actually used to build the breadcrumb, so only this one is wasted work.
The first delta (6.8 µs over three records) is this bug. Small per record, but it scales with log volume and applies to every application that has not opted into Sentry Logs.
Environment: CPython 3.14.7, sentry-sdk 2.67.1, fastapi 0.141.1, Apple M2.
Activity
linear-code commentedon Sep 7, 2026
PY-2768
Skip formatting log records when Sentry logs are off (getsentry#7422)