← Back to Pull requests

Skip f-string inspection for spans and logs that logfire opens itself #2775

Closed
unknown closed this pull request without merging on Nov 10, 2026 18:30 UTC
View on GitHub
unknown unknown commented on Nov 10, 2026 15:23 UTC
Author

Closes #2771

With inspect_arguments=True, Logfire._span and Logfire.log hand the caller's frame to logfire_format_with_magic, which runs executing on 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_magic now drops the frame when the call site is inside the logfire package, the same as inspect_arguments=False. Doing it there covers _span and log and every internal caller at once. For the nice-to-have: when PYTEST_CURRENT_TEST is set (the same signal log_internal_error uses), 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), and executing no longer parses variables/variable.py.

test_logfire_calls_skip_fstring_magic fails on main because variable.py gets inspected. test_logfire_fstring_call_fails_in_tests covers the test-time check.

<!-- This is an auto-generated description by cubic. -->
<a href="https://cubic.dev/pr/pydantic/logfire/pull/2775?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->

Diff: 232 lines (+174 / -58) across 2 files Reviewer: ska2704 Review duration: 186m
All Vouch review confidence checks passed
Residual risk 0.15 = Change Risk (0.37) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 232 lines diff across 2 files
0.37
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.326
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #2775"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 37.1% (MEDIUM) · Higher = larger blast radius
37.1%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 14.6% · Safe to merge
14.6%