Skip to content

feat: surface X-Logfire-Warning / X-Logfire-Error response headers#1906

Open
adriangb wants to merge 1 commit intomainfrom
add-server-response-headers
Open

feat: surface X-Logfire-Warning / X-Logfire-Error response headers#1906
adriangb wants to merge 1 commit intomainfrom
add-server-response-headers

Conversation

@adriangb
Copy link
Copy Markdown
Member

@adriangb adriangb commented May 5, 2026

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.py module installs a requests response 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:

Header Effect
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> Raises 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

  • New tests/test_server_response.py covers warning emission, dedup, error raising, and end-to-end propagation through LogfireClient.
  • make format lint typecheck clean.
  • 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

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>
@adriangb adriangb requested review from Viicos and alexmojaki May 5, 2026 14:24
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

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

View logs

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 7 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant