Repository navigation
Skip f-string inspection for spans and logs that logfire opens itself - #2775
Merged
alexmojaki merged 2 commits intoNov 10, 2026
Merged
Conversation
Spans and logs opened by logfire itself, such as Variable.get(), never pass a user f-string, but with inspect_arguments enabled the call site still went through executing, which parses the calling module on the first call. In tests, the magic still runs for these calls and asserts the template is unchanged, so an internal f-string call fails the suite. Closes pydantic#2771
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
An error while re-evaluating an internal f-string's expression was caught along with everything else, so the check passed without reaching the assertion. KnownFormattingError only comes from formatting a plain template, so catch just that and let anything else fail the test.
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.
Closes #2771
With
inspect_arguments=True,Logfire._spanandLogfire.loghand the caller's frame tologfire_format_with_magic, which runsexecutingon the call site to see whether the message is an f-string. When the caller is logfire itself (Variable.get(), integrations), that parses the logfire module's source on the first call, even though the message is never a user f-string.Following the suggestion in the issue,
logfire_format_with_magicnow drops the frame when the call site is inside the logfire package, the same asinspect_arguments=False. Doing it there covers_spanandlogand every internal caller at once. For the nice-to-have: whenPYTEST_CURRENT_TESTis set (the same signallog_internal_erroruses), the magic still runs for these calls and asserts the template is unchanged, so an internal call with an f-string fails the tests instead of silently producing a span name per value.With the reproduction from the issue, the first
get()went from 9.3 ms to 1.4 ms (macOS arm64, Python 3.13), andexecutingno longer parsesvariables/variable.py.test_logfire_calls_skip_fstring_magicfails on main becausevariable.pygets inspected.test_logfire_fstring_call_fails_in_testscovers the test-time check.