Skip to content

fix(logs): don't drop the log batch when a message template can't be formatted - #3250

Open
pcbeingused333 wants to merge 1 commit into
getsentry:masterfrom
pcbeingused333:fix/log-template-format-error
Open

pcbeingused333 wants to merge 1 commit into
getsentry:masterfrom
pcbeingused333:fix/log-template-format-error

Conversation

@pcbeingused333

Copy link
Copy Markdown

One structured log whose message template can't be formatted makes the SDK lose every log buffered with it.

Sentry.logger.info("Disk 100% full on %{host}", host: "web-1")
Sentry.logger.info("%s is 100% done", ["import"])
Sentry.logger.info("%{user} logged in from %{ip}", user: "jane")

Cause: LogEvent#to_h formats the body with % / sprintf at flush time. These calls raise (ArgumentError, TypeError, KeyError), the error propagates out of TelemetryEventBuffer#send_items after the pending items have already been taken from the buffer, and the whole batch is lost.

Fix: if formatting fails, send the raw body and write a debug message to the SDK logger. The template and parameter attributes are still attached.

Tests: three new cases in log_event_spec.rb fail without the change and pass with it. RuboCop passes on the touched files.

This change was prepared with AI assistance.

…formatted

A literal % next to a placeholder, or a %{token} without its attribute,
raised from LogEvent#to_h during flush and lost every buffered log.
Send the raw body in that case.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pcbeingused333
pcbeingused333 requested review from a team and solnic as code owners November 29, 2026 00:08
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit 2b3b2a8.

Main concerns: reach, data sent to Sentry, host performance.

This label is a hint for reviewers, not an approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant