Skip to content

feat(HttpClient): add span-customization hook #8053

Description

@anatolzak

What is the problem this feature would solve?

The client span that HttpClient creates is almost entirely fixed. Today you can only customize the span name, whitelisted headers, and redacted headers.

So short of replacing the whole client, none of the following is possible per request:

  • Add attributes to just the client span. Effect.annotateSpans reaches it, but it propagates to every span created in scope, so the attribute also lands on nested spans. Effect.annotateCurrentSpan only touches the current span, but the client span is created inside the client call and is never the current span at your call site, so it can't reach it either.
  • Add http.route or another low-cardinality template attribute.
  • Override or redact url.full / url.query / url.path. Query strings and path segments are captured verbatim.
  • Set span status for non-2xx. HttpClient returns 4xx/5xx as a successful response, so the span carries a status_code attribute but no error status.
  • Change the span kind, for example a producer-style fire-and-forget.

What is the feature you are proposing to solve the problem?

A span-customization hook on HttpClient that receives the span along with the request (and the response when available) and can do anything to the span: set or overwrite any attribute (including the built-in url.* ones), add peer.service / http.route / arbitrary attributes, set span status, and set the span kind.

In addition to the hook, maybe we should also provide URL query redaction control, symmetric with CurrentRedactedNames for headers.

What alternatives have you considered?

  • Disable HttpClient's built-in tracing and instrument the calls by hand.
  • Collector-side processors. But it's out of process and the sensitive data leaves your app, so you're relying on the collector to prune it before it's stored or forwarded.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions