[propagator] Set sample bitmask when sampling decision is debug for B3 Propagator. (#369)
According to the spec. Debug sampling decision implies accept(sampled) decision. But we didn't set sample bitmask. So when trace state is debug, `IsSampled` method will still return false, which is different from spec. Now we make sure when debug bitmask is set, sample bitmask will also be set. Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
parent
9dc5e0c25b
commit
71b6d7fc42
|
|
@ -144,7 +144,7 @@ var extractHeaders = []extractTest{
|
|||
wantSc: trace.SpanContext{
|
||||
TraceID: traceID,
|
||||
SpanID: spanID,
|
||||
TraceFlags: trace.FlagsDeferred | trace.FlagsDebug,
|
||||
TraceFlags: trace.FlagsSampled | trace.FlagsDebug,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -163,8 +163,7 @@ var extractHeaders = []extractTest{
|
|||
},
|
||||
{
|
||||
// spec explicitly states "Debug implies an accept decision, so don't
|
||||
// also send the X-B3-Sampled header", make sure sampling is
|
||||
// deferred.
|
||||
// also send the X-B3-Sampled header", make sure sampling is set in this case.
|
||||
name: "multiple: debug flag set and sampling state is deny",
|
||||
headers: map[string]string{
|
||||
b3TraceID: traceIDStr,
|
||||
|
|
@ -175,7 +174,7 @@ var extractHeaders = []extractTest{
|
|||
wantSc: trace.SpanContext{
|
||||
TraceID: traceID,
|
||||
SpanID: spanID,
|
||||
TraceFlags: trace.FlagsDebug,
|
||||
TraceFlags: trace.FlagsDebug | trace.FlagsSampled,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -251,7 +250,7 @@ var extractHeaders = []extractTest{
|
|||
wantSc: trace.SpanContext{
|
||||
TraceID: traceID,
|
||||
SpanID: spanID,
|
||||
TraceFlags: trace.FlagsDebug,
|
||||
TraceFlags: trace.FlagsDebug | trace.FlagsSampled,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -208,10 +208,14 @@ func extractMultiple(traceID, spanID, parentSpanID, sampled, flags string) (trac
|
|||
return empty, errInvalidSampledHeader
|
||||
}
|
||||
|
||||
// The only accepted value for Flags is "1". This will set Debug to
|
||||
// true. All other values and omission of header will be ignored.
|
||||
// The only accepted value for Flags is "1". This will set Debug bitmask and
|
||||
// sampled bitmask to 1 since debug implicitly means sampled. All other
|
||||
// values and omission of header will be ignored. According to the spec. User
|
||||
// shouldn't send X-B3-Sampled header along with X-B3-Flags header. Thus we will
|
||||
// ignore X-B3-Sampled header when X-B3-Flags header is sent and valid.
|
||||
if flags == "1" {
|
||||
sc.TraceFlags |= trace.FlagsDebug
|
||||
sc.TraceFlags |= trace.FlagsDebug | trace.FlagsSampled
|
||||
sc.TraceFlags &= ^trace.FlagsDeferred
|
||||
}
|
||||
|
||||
if traceID != "" {
|
||||
|
|
@ -331,7 +335,7 @@ func extractSingle(contextHeader string) (trace.SpanContext, error) {
|
|||
case "":
|
||||
sc.TraceFlags = trace.FlagsDeferred
|
||||
case "d":
|
||||
sc.TraceFlags = trace.FlagsDebug
|
||||
sc.TraceFlags = trace.FlagsDebug | trace.FlagsSampled
|
||||
case "1":
|
||||
sc.TraceFlags = trace.FlagsSampled
|
||||
case "0":
|
||||
|
|
|
|||
|
|
@ -56,12 +56,12 @@ func TestExtractMultiple(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"", "", "", "", "1",
|
||||
trace.SpanContext{TraceFlags: trace.FlagsDeferred | trace.FlagsDebug},
|
||||
trace.SpanContext{TraceFlags: trace.FlagsSampled | trace.FlagsDebug},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"", "", "", "0", "1",
|
||||
trace.SpanContext{TraceFlags: trace.FlagsDebug},
|
||||
trace.SpanContext{TraceFlags: trace.FlagsDebug | trace.FlagsSampled},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
|
|
@ -214,7 +214,7 @@ func TestExtractSingle(t *testing.T) {
|
|||
}{
|
||||
{"0", trace.SpanContext{}, nil},
|
||||
{"1", trace.SpanContext{TraceFlags: trace.FlagsSampled}, nil},
|
||||
{"d", trace.SpanContext{TraceFlags: trace.FlagsDebug}, nil},
|
||||
{"d", trace.SpanContext{TraceFlags: trace.FlagsDebug | trace.FlagsSampled}, nil},
|
||||
{"a", empty, errInvalidSampledByte},
|
||||
{"3", empty, errInvalidSampledByte},
|
||||
{"000000000000007b", empty, errInvalidScope},
|
||||
|
|
|
|||
Loading…
Reference in New Issue