Skip to content

Support propagation of trace context headers in http gateway #9168

@iand

Description

@iand

Checklist

  • My issue is specific & actionable.
  • I am not suggesting a protocol enhancement.
  • I have searched on the issue tracker for my issue.

Description

The HTTP gateway should support propagation of trace context headers using the W3C Trace Context recommendation.

This consists of supporting two optional HTTP headers traceparent and tracestate on incoming requests, adopting the trace id from the traceparent header for internal traces and emitting updated or new headers on responses.

This will allow:

  1. people using the gateway as a component in their infrastructure to correlate traces that pass through it
  2. gateway providers to trace incoming requests and correlate with logs
  3. performance optimizers to correlate traces with experiments

Of particular use will be the "sampled" flag on the emitted traceparent header that indicates whether the request was sampled for tracing by Kubo.

Implementation Note

This should be as simple as using the opentelemetry TraceContext, roughly:

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    p := propagation.TraceContext{}
    ctx := p.Extract(r.Context(), propagation.HeaderCarrier(r.Header))
    
    // do stuff

   p.Inject(ctx, propagation.HeaderCarrier(w.Header()))
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions