Skip to content

Skip formatting log records when Sentry logs are off - #7422

Merged
sentrivana merged 2 commits into
getsentry:masterfrom
gyanu2507:logs-handler-skip-format
Sep 9, 2026
Merged

Skip formatting log records when Sentry logs are off#7422
sentrivana merged 2 commits into
getsentry:masterfrom
gyanu2507:logs-handler-skip-format

Conversation

@gyanu2507

@gyanu2507 gyanu2507 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

SentryLogsHandler.emit called format() before checking whether logs are enabled. Every stdlib record paid for a Formatter even with the feature off.

Format after the capture check.

Fixes #7402

SentryLogsHandler.emit called format() before the capture check, so every
record paid for a Formatter even with the feature off.
@gyanu2507
gyanu2507 requested a review from a team as a code owner September 8, 2026 06:11

@sentrivana sentrivana left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gyanu2507, the change looks good to me, please have a look at the suggestion I left.



def test_sentry_logs_handler_skips_format_when_disabled(sentry_init):
sentry_init()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to be explicit here to not have this break if the default changes:

Suggested change
sentry_init()
sentry_init(integrations=[LoggingIntegration(capture_sentry_logs=False)])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. The test now passes LoggingIntegration(capture_sentry_logs=False) so it still holds if the default flips.

The default is off today. Pinning it keeps the test honest if that changes.
@sentrivana
sentrivana enabled auto-merge (squash) September 9, 2026 07:28
@sentrivana
sentrivana merged commit ea8c77a into getsentry:master Sep 9, 2026
159 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SentryLogsHandler.emit formats every log record before checking has_logs_enabled

2 participants