Skip to content

feat(otel): extract inbound W3C traceparent so request spans join client traces #65

Description

@amondnet

Context

Follow-up from PR #64 (opt-in OpenTelemetry export). The trace exporter uses a ParentBased(TraceIdRatioBased) sampler, which honors a parent only if a parent span context is already on the current context. shunt does not yet extract an inbound W3C traceparent header from incoming requests, so every proxy_request span is currently a root — a client that propagates a trace (e.g. via traceparent) will not have its trace connected through the gateway.

Raised by cubic on PR #64 (src/telemetry.rs sampler).

Proposed work

  • Install a global text-map propagator (opentelemetry_sdk::propagation::TraceContextPropagator).
  • In src/proxy.rs, extract the parent Context from the request HeaderMap (e.g. opentelemetry_http::HeaderExtractor) and set it as the parent of the proxy_request span via tracing_opentelemetry::OpenTelemetrySpanExt::set_parent.
  • Consider whether inbound trace ids should be trusted unconditionally at a gateway boundary, or gated (a client could inject arbitrary trace ids). Document the choice.
  • Add a test covering extraction + parenting.

Out of scope for #64

#64 is the initial opt-in export surface; inbound propagation is a distinct enhancement with its own trust/security considerations, so it was deferred here (the misleading 'traceparent is honored' comment was corrected in #64).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions