feat: surface X-Logfire-Warning / X-Logfire-Error response headers#1906
Open
feat: surface X-Logfire-Warning / X-Logfire-Error response headers#1906
Conversation
Adds a `requests` response hook that the SDK installs on every Logfire-bound HTTP session (OTLP exporters, token validation, CRUD client, variables provider, CLI). The hook reads two custom headers the server attaches to responses: * `X-Logfire-Warning` -> `warnings.warn(..., LogfireServerWarning)`. Python's default filter dedupes identical messages within a process, so a chatty server only warns once. * `X-Logfire-Error` -> raises `LogfireServerError`. OTLP/variables paths already swallow exceptions from their HTTP calls; CRUD/CLI propagate the error to the user. This gives the backend an out-of-band channel to deprecate endpoints or signal hard failures without piggy-backing on response bodies. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Deploying logfire-docs with
|
| Latest commit: |
9fbfb44
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://bf22b0e1.logfire-docs.pages.dev |
| Branch Preview URL: | https://add-server-response-headers.logfire-docs.pages.dev |
adriangb
added a commit
that referenced
this pull request
May 5, 2026
Per review (#1905#discussion_r3189043209), the X-Logfire-Warning / X-Logfire-Error response-hook handling is logically independent from the X-Logfire-Telemetry request header — they just happened to be introduced together. Moved that code (plus its exceptions, install calls, and tests) to a separate PR (#1906) so each can be reviewed and landed on its own. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
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.
Summary
Split out from #1905 (per review).
Gives the Logfire backend an out-of-band channel — independent of response bodies — to deprecate endpoints or signal hard failures to any client running this SDK.
A new
logfire/_internal/server_response.pymodule installs arequestsresponse hook on every Logfire-bound HTTP session (OTLP exporters, token validation, CRUD client, variables provider, CLI). Each Logfire response is checked for two custom headers:X-Logfire-Warning: <message>warnings.warn(message, LogfireServerWarning). Python's default filter dedupes identical messages within a process, so a chatty server only warns once.X-Logfire-Error: <message>LogfireServerError. OTLP/variables paths already swallow exceptions from their HTTP calls; CRUD and CLI propagate the error to the user.Both headers are optional — absent headers are silently ignored, so the existing wire format is unaffected for clients running an older SDK.
Test plan
tests/test_server_response.pycovers warning emission, dedup, error raising, and end-to-end propagation throughLogfireClient.make format lint typecheckclean.uv run pytest tests/test_server_response.py tests/test_configure.py tests/test_client.py tests/test_variables.py tests/test_cli.py(451 tests) passes.🤖 Generated with Claude Code