Skip to content

Commit

Permalink
Special-case extract from ot.HTTPHeadersCarrier
Browse files Browse the repository at this point in the history
Values stored in http.Header get title-cased, i.e. `traceparent` will
turn into `Traceparent`. Since HTTPHeadersCarrier.ForeachKey does not
undo this change, special-case that one type with a different wrapper
that will allow the value to be fetched.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
  • Loading branch information
bboreham committed Apr 18, 2022
1 parent 0e16e36 commit fcb9b2a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions bridge/opentracing/bridge.go
Expand Up @@ -701,14 +701,20 @@ func (t *BridgeTracer) Extract(format interface{}, carrier interface{}) (ot.Span
if builtinFormat, ok := format.(ot.BuiltinFormat); !ok || builtinFormat != ot.HTTPHeaders {
return nil, ot.ErrUnsupportedFormat
}
// If carrier implements the required interface directly, use that
tmCarrier, ok := carrier.(propagation.TextMapCarrier)
if !ok {
tmReader, ok := carrier.(ot.TextMapReader) // otherwise see if we can wrap it
if !ok {
return nil, ot.ErrInvalidCarrier
}
tmCarrier = textMapAdapter{r: tmReader}
var tmCarrier propagation.TextMapCarrier
switch typedCarrier := carrier.(type) {
case propagation.TextMapCarrier:
// If carrier implements the required interface directly, use that.
tmCarrier = typedCarrier
case ot.HTTPHeadersCarrier:
// HTTPHeadersCarrier requires special wrapping, because Set() title-cases the key.
header := http.Header(typedCarrier)
tmCarrier = propagation.HeaderCarrier(header)
case ot.TextMapReader:
// We can wrap anything corresponding to TextMapReader.
tmCarrier = textMapAdapter{r: typedCarrier}
default:
return nil, ot.ErrInvalidCarrier
}
ctx := t.getPropagator().Extract(context.Background(), tmCarrier)
baggage := baggage.FromContext(ctx)
Expand Down

0 comments on commit fcb9b2a

Please sign in to comment.