Skip to content

Add user agent to query client - #1875

Merged
alexmojaki merged 1 commit into
mainfrom
vp/query-client-ua
Apr 21, 2026
Merged

alexmojaki merged 1 commit into
mainfrom
vp/query-client-ua

Conversation

@Viicos

@Viicos Viicos commented Apr 21, 2026

Copy link
Copy Markdown
Member

No description provided.

@Viicos
Viicos requested a review from alexmojaki April 21, 2026 14:56
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: cec1d6a
Status: ✅  Deploy successful!
Preview URL: https://ff82c0b6.logfire-docs.pages.dev
Branch Preview URL: https://vp-query-client-ua.logfire-docs.pages.dev

View logs

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@alexmojaki
alexmojaki merged commit ff5c802 into main Apr 21, 2026
18 checks passed
@alexmojaki
alexmojaki deleted the vp/query-client-ua branch April 21, 2026 18:40
@Viicos Viicos mentioned this pull request May 5, 2026
3 tasks done
adriangb added a commit that referenced this pull request May 5, 2026
This reverts commit ff5c802. With X-Logfire-Telemetry now carrying SDK
version, Python version, implementation and OS, the custom User-Agent on
the query client is duplicate plumbing for the same product analytics
question. Letting httpx send its default UA again, and the next commit
adds the telemetry header here.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
adriangb added a commit that referenced this pull request May 13, 2026
This reverts commit ff5c802. With X-Logfire-Telemetry now carrying SDK
version, Python version, implementation and OS, the custom User-Agent on
the query client is duplicate plumbing for the same product analytics
question. Letting httpx send its default UA again, and the next commit
adds the telemetry header here.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
adriangb added a commit that referenced this pull request May 13, 2026
Adds an `X-Logfire-Telemetry: key=val,...` header to every request the SDK
sends (OTLP exports, token validation, CRUD calls, variable provider, CLI),
carrying the SDK version and a curated set of non-sensitive `_LogfireConfigData`
fields so the backend can drive product analytics and deprecation decisions.
Tokens, API keys, service name, environment, etc. are explicitly excluded.

Also installs a response hook on every Logfire SDK session that surfaces
`X-Logfire-Warning` headers via `warnings.warn` (deduplicated by Python's
default filter) and raises `LogfireServerError` on `X-Logfire-Error` headers,
so the server can deprecate endpoints or signal hard failures out-of-band.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

trim telemetry pairs, add service.instance.id, document rationale per field

* Limit `_LogfireConfigData`-derived pairs to `code_source_set`,
  `variables_set`, and `token_count` — the only ones with a concrete product
  question they answer. Each remaining field now has an inline comment
  explaining why we send it.
* Carry the resolved `service.instance.id` (UUID generated inside `_initialize`,
  shared with OTLP resource attributes) so the backend can correlate the
  header on non-OTLP requests with the spans this SDK instance exports.
* Drop the `None` branch of `_format_value` and the idempotency guard in
  `install_logfire_response_hook` — both were unreachable, which was tripping
  the coverage gate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

move service_instance_id into _config_telemetry_pairs

It only ships when a LogfireConfig is available, so it belongs in the
config-derived group rather than the always-sent base group.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Revert "Add user agent to query client (#1875)"

This reverts commit ff5c802. With X-Logfire-Telemetry now carrying SDK
version, Python version, implementation and OS, the custom User-Agent on
the query client is duplicate plumbing for the same product analytics
question. Letting httpx send its default UA again, and the next commit
adds the telemetry header here.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

address review: JSON header value, implementation field, cache base pairs, query client

- Encode the X-Logfire-Telemetry value as compact JSON instead of a
  comma-separated key=val list. Removes a silent footgun if any value
  ever contains "," or "=", and lets us send native bool/int instead of
  formatting them as strings.
- Rename the `runtime` field to `implementation` to match Python's own
  wording for `sys.implementation.name`.
- Cache `_base_telemetry_pairs()` with `functools.cache` since the value
  is constant per-process.
- Wire the same telemetry header into the experimental query client now
  that the previous custom User-Agent has been reverted.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

split out response-header handling into its own PR

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.

2 participants