Repository navigation
fix(exceptions): send truncated source lines instead of null - #1265
Open
Toraastrta wants to merge 1 commit into
Open
Toraastrta wants to merge 1 commit into
Toraastrta wants to merge 1 commit into
Conversation
get_lines_from_file passed each line through strip_string, which wraps a truncated line in an AnnotatedValue. Nothing unwrapped it, so clean() turned it into None and lines over 1024 bytes reached the event as null in context_line, pre_context and post_context. Keep only the truncated string.
This branch has not been deployed
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.
💡 Motivation and Context
When a source line in a stack frame is longer than 1024 bytes, exception autocapture sends
nullfor it incontext_line,pre_contextorpost_context, instead of the truncated line.get_lines_from_fileruns each line throughstrip_string, which returns anAnnotatedValue(copied from Sentry) when it truncates. Nothing unwraps it, soclean()turns the object intoNone. The truncated text, ending in..., never reaches the event. The capture-exception spec types these fields as strings.This keeps only the truncated string, and updates the two return type comments that still allowed
AnnotatedValue.💚 How did you test it?
test_source_context_truncates_long_lines_to_stringstoposthog/test/test_exception_utils.py. It fails onmain(anAnnotatedValuecomes back) and passes with the fix.$exceptionfrom a module whose raising line is 1,100 characters to a local HTTP server, usingPosthog(..., host="http://127.0.0.1:<port>", sync_mode=True), and read the posted batch. Onmainthe frame'scontext_lineisnull. With the fix it is the 1,024-character truncated line ending in.... Short lines are unchanged.ruff format --check .,ruff check .,mypy ... | mypy-baseline filterandpython -W error -c "import posthog"pass. The fullpytestrun passes except 3 fork tests intest_metrics_autocapture.py, which fail the same way onmainon my machine (macOS).📝 Checklist
If releasing new changes
.sampo/changesets/exception-long-context-lines.md(written by hand in the formatsampo addproduces,pypi/posthog: patch)🤖 Agent context
Autonomy: Human-driven (agent-assisted)
strip_stringitself, but kept the fix inget_lines_from_file, its only caller, so the Sentry-derived helper stays as it is.