Repository navigation
fix(logs): format non-ASCII binary formats in the error backend - #1283
Open
pcbeingused33 wants to merge 2 commits into
Open
pcbeingused33 wants to merge 2 commits into
pcbeingused33 wants to merge 2 commits into
Conversation
: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
requested review from
a team,
solnic and
whatyouhide
as code owners
December 1, 2026 16:17
Contributor
PR risk: mediumFor commit Main concerns: data sent to Sentry, reach, host performance. This label is a hint for reviewers, not an approval. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
With
capture_log_messagesenabled, a{format, args}log whose format is a UTF-8 binary is reported with the wrong characters.:io_lib.format/2reads 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.LogEventalready turns the format into a charlist before calling:io_lib.format/2(see #1281).Sentry.LoggerHandler.ErrorBackendstill passed the binary through, which is the path used for captured events. It now converts a format withString.to_charlist/1only when that format is a valid UTF-8 binary. Atoms and otherio:format()values, including non-UTF-8 binaries, are passed through unchanged, so an atom format such as:hellois still captured as"hello".Reproduction
:logger.error("café request failed: ~p", [:timeout])withcapture_log_messages: true.Test
test/sentry/logger_handler_test.exslogs that binary format and the same text as a charlist, and expects"café request failed: timeout"for both. It also expects an atom format:helloto be captured as"hello"and a Latin-1 binary format to still be reported. Onmasterthe UTF-8 binary assertion fails. With this change that test passes, andmix test test/sentry/logger_handler_test.exspasses 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.