Skip to content

fix(logs): format non-ASCII binary formats in the error backend - #1283

Open
pcbeingused33 wants to merge 2 commits into
getsentry:masterfrom
pcbeingused33:fix/error-backend-binary-format
Open

pcbeingused33 wants to merge 2 commits into
getsentry:masterfrom
pcbeingused33:fix/error-backend-binary-format

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

Description

With capture_log_messages enabled, a {format, args} log whose format is a UTF-8 binary is reported with the wrong characters. :io_lib.format/2 reads that binary byte by byte, so "café request failed: ~p" with [:timeout] is captured as "café request failed: timeout". A charlist format for the same text was already captured as "café request failed: timeout".

Sentry.LogEvent already turns the format into a charlist before calling :io_lib.format/2 (see #1281). Sentry.LoggerHandler.ErrorBackend still passed the binary through, which is the path used for captured events. It now converts a format with String.to_charlist/1 only when that format is a valid UTF-8 binary. Atoms and other io:format() values, including non-UTF-8 binaries, are passed through unchanged, so an atom format such as :hello is still captured as "hello".

Reproduction

:logger.error("café request failed: ~p", [:timeout]) with capture_log_messages: true.

Test

test/sentry/logger_handler_test.exs logs that binary format and the same text as a charlist, and expects "café request failed: timeout" for both. It also expects an atom format :hello to be captured as "hello" and a Latin-1 binary format to still be reported. On master the UTF-8 binary assertion fails. With this change that test passes, and mix test test/sentry/logger_handler_test.exs passes on Elixir 1.20 / OTP 29.

Issues

None filed. Related to #1281, which fixed only Sentry.LogEvent.

This change was generated with assistance from an AI coding agent.

pcbeingused33 and others added 2 commits December 1, 2026 11:34
:io_lib.format/2 reads a binary format byte by byte, so a UTF-8
format such as "café request failed: ~p" was captured as
"café request failed: timeout" when capture_log_messages is set.
Convert the format to a charlist first, matching the logs path.

Co-Authored-By: Grok 4.7 <noreply@x.ai>
IO.chardata_to_string/1 rejects atom formats and non-UTF-8 binaries.
Leave those for :io_lib.format/2 and turn only valid UTF-8 binaries
into charlists, so the handler rescue does not drop the event.

Co-Authored-By: Grok 4.7 <noreply@x.ai>
@pcbeingused33
pcbeingused33 requested review from a team, solnic and whatyouhide as code owners December 1, 2026 16:17
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit 84bd7da.

Main concerns: data sent to Sentry, reach, 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