mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-20 03:30:02 +02:00
Merge branch 'master' into zipkin_mock_addr
This commit is contained in:
commit
83af6cea64
@ -31,7 +31,7 @@ const (
|
||||
B3ParentSpanIDHeader = "X-B3-ParentSpanId"
|
||||
)
|
||||
|
||||
// B3 propagator serializes core.SpanContext to/from B3 Headers.
|
||||
// B3 propagator serializes SpanContext to/from B3 Headers.
|
||||
// This propagator supports both version of B3 headers,
|
||||
// 1. Single Header :
|
||||
// X-B3: {TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
|
||||
@ -87,8 +87,15 @@ func (b3 B3) Extract(ctx context.Context, supplier propagation.HTTPSupplier) con
|
||||
return ContextWithRemoteSpanContext(ctx, sc)
|
||||
}
|
||||
|
||||
func fixB3TID(in string) string {
|
||||
if len(in) == 16 {
|
||||
in = strings.Repeat("0", 16) + in
|
||||
}
|
||||
return in
|
||||
}
|
||||
|
||||
func (b3 B3) extract(supplier propagation.HTTPSupplier) SpanContext {
|
||||
tid, err := IDFromHex(supplier.Get(B3TraceIDHeader))
|
||||
tid, err := IDFromHex(fixB3TID(supplier.Get(B3TraceIDHeader)))
|
||||
if err != nil {
|
||||
return EmptySpanContext()
|
||||
}
|
||||
@ -139,7 +146,7 @@ func (b3 B3) extractSingleHeader(supplier propagation.HTTPSupplier) SpanContext
|
||||
}
|
||||
|
||||
var err error
|
||||
sc.TraceID, err = IDFromHex(parts[0])
|
||||
sc.TraceID, err = IDFromHex(fixB3TID(parts[0]))
|
||||
if err != nil {
|
||||
return EmptySpanContext()
|
||||
}
|
||||
|
@ -24,6 +24,10 @@ type extractTest struct {
|
||||
wantSc trace.SpanContext
|
||||
}
|
||||
|
||||
var (
|
||||
traceID64bitPadded = mustTraceIDFromHex("0000000000000000a3ce929d0e0e4736")
|
||||
)
|
||||
|
||||
var extractMultipleHeaders = []extractTest{
|
||||
{
|
||||
name: "sampling state defer",
|
||||
@ -125,6 +129,17 @@ var extractMultipleHeaders = []extractTest{
|
||||
},
|
||||
wantSc: trace.EmptySpanContext(),
|
||||
},
|
||||
{
|
||||
name: "left-padding 64-bit traceID",
|
||||
headers: map[string]string{
|
||||
trace.B3TraceIDHeader: "a3ce929d0e0e4736",
|
||||
trace.B3SpanIDHeader: "00f067aa0ba902b7",
|
||||
},
|
||||
wantSc: trace.SpanContext{
|
||||
TraceID: traceID64bitPadded,
|
||||
SpanID: spanID,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var extractSingleHeader = []extractTest{
|
||||
@ -188,6 +203,16 @@ var extractSingleHeader = []extractTest{
|
||||
},
|
||||
wantSc: trace.EmptySpanContext(),
|
||||
},
|
||||
{
|
||||
name: "left-padding 64-bit traceID",
|
||||
headers: map[string]string{
|
||||
trace.B3SingleHeader: "a3ce929d0e0e4736-00f067aa0ba902b7",
|
||||
},
|
||||
wantSc: trace.SpanContext{
|
||||
TraceID: traceID64bitPadded,
|
||||
SpanID: spanID,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var extractInvalidB3MultipleHeaders = []extractTest{
|
||||
|
Loading…
x
Reference in New Issue
Block a user