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

Merged
SK
23d ago
+88-1

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.