2020-03-24 07:41:10 +02:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2019-10-08 19:22:15 +02:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2020-08-10 22:35:15 +02:00
|
|
|
package tracetest_test
|
2019-10-08 19:22:15 +02:00
|
|
|
|
|
|
|
import (
|
2020-07-08 01:38:52 +02:00
|
|
|
"fmt"
|
|
|
|
|
2020-01-28 20:13:46 +02:00
|
|
|
"go.opentelemetry.io/otel/api/trace"
|
2019-10-08 19:22:15 +02:00
|
|
|
)
|
|
|
|
|
2020-07-08 01:38:52 +02:00
|
|
|
const (
|
|
|
|
b3Context = "b3"
|
|
|
|
b3Flags = "x-b3-flags"
|
|
|
|
b3TraceID = "x-b3-traceid"
|
|
|
|
b3SpanID = "x-b3-spanid"
|
|
|
|
b3Sampled = "x-b3-sampled"
|
|
|
|
b3ParentSpanID = "x-b3-parentspanid"
|
|
|
|
)
|
|
|
|
|
2019-10-08 19:22:15 +02:00
|
|
|
type extractTest struct {
|
|
|
|
name string
|
|
|
|
headers map[string]string
|
2020-05-02 14:17:11 +02:00
|
|
|
wantSc trace.SpanContext
|
2019-10-08 19:22:15 +02:00
|
|
|
}
|
|
|
|
|
2020-05-05 20:20:09 +02:00
|
|
|
var (
|
|
|
|
traceID64bitPadded = mustTraceIDFromHex("0000000000000000a3ce929d0e0e4736")
|
|
|
|
)
|
|
|
|
|
2020-07-08 01:38:52 +02:00
|
|
|
var extractHeaders = []extractTest{
|
|
|
|
{
|
|
|
|
name: "empty",
|
|
|
|
headers: map[string]string{},
|
|
|
|
wantSc: trace.EmptySpanContext(),
|
|
|
|
},
|
2019-10-08 19:22:15 +02:00
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: sampling state defer",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-05-02 14:17:11 +02:00
|
|
|
wantSc: trace.SpanContext{
|
2020-07-08 01:38:52 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsDeferred,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: sampling state deny",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Sampled: "0",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-05-02 14:17:11 +02:00
|
|
|
wantSc: trace.SpanContext{
|
2019-10-08 19:22:15 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: sampling state accept",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Sampled: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-05-02 14:17:11 +02:00
|
|
|
wantSc: trace.SpanContext{
|
2019-10-08 19:22:15 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
2020-05-05 19:41:54 +02:00
|
|
|
TraceFlags: trace.FlagsSampled,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: sampling state as a boolean: true",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Sampled: "true",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-05-02 14:17:11 +02:00
|
|
|
wantSc: trace.SpanContext{
|
2019-10-08 19:22:15 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
2020-05-05 19:41:54 +02:00
|
|
|
TraceFlags: trace.FlagsSampled,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: sampling state as a boolean: false",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Sampled: "false",
|
|
|
|
},
|
|
|
|
wantSc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple: debug flag set",
|
|
|
|
headers: map[string]string{
|
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Flags: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-05-02 14:17:11 +02:00
|
|
|
wantSc: trace.SpanContext{
|
2019-10-08 19:22:15 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
2020-07-08 01:38:52 +02:00
|
|
|
TraceFlags: trace.FlagsDeferred | trace.FlagsDebug,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: debug flag set to not 1 (ignored)",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Sampled: "1",
|
|
|
|
b3Flags: "2",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-05-02 14:17:11 +02:00
|
|
|
wantSc: trace.SpanContext{
|
2019-10-08 19:22:15 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
2020-05-05 19:41:54 +02:00
|
|
|
TraceFlags: trace.FlagsSampled,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
// spec explicitly states "Debug implies an accept decision, so don't
|
|
|
|
// also send the X-B3-Sampled header", make sure sampling is
|
|
|
|
// deferred.
|
|
|
|
name: "multiple: debug flag set and sampling state is deny",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Sampled: "0",
|
|
|
|
b3Flags: "1",
|
|
|
|
},
|
|
|
|
wantSc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsDebug,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple: with parent span id",
|
|
|
|
headers: map[string]string{
|
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Sampled: "1",
|
|
|
|
b3ParentSpanID: "00f067aa0ba90200",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-05-02 14:17:11 +02:00
|
|
|
wantSc: trace.SpanContext{
|
2019-10-08 19:22:15 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
2020-05-05 19:41:54 +02:00
|
|
|
TraceFlags: trace.FlagsSampled,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: with only sampled state header",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Sampled: "0",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-05-02 14:17:11 +02:00
|
|
|
wantSc: trace.EmptySpanContext(),
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-05-05 20:20:09 +02:00
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: left-padding 64-bit traceID",
|
2020-05-05 20:20:09 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: "a3ce929d0e0e4736",
|
|
|
|
b3SpanID: spanIDStr,
|
2020-05-05 20:20:09 +02:00
|
|
|
},
|
|
|
|
wantSc: trace.SpanContext{
|
2020-07-08 01:38:52 +02:00
|
|
|
TraceID: traceID64bitPadded,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsDeferred,
|
2020-05-05 20:20:09 +02:00
|
|
|
},
|
|
|
|
},
|
2019-10-08 19:22:15 +02:00
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: sampling state defer",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: fmt.Sprintf("%s-%s", traceIDStr, spanIDStr),
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-05-02 14:17:11 +02:00
|
|
|
wantSc: trace.SpanContext{
|
2020-07-08 01:38:52 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsDeferred,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: sampling state deny",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: fmt.Sprintf("%s-%s-0", traceIDStr, spanIDStr),
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-05-02 14:17:11 +02:00
|
|
|
wantSc: trace.SpanContext{
|
2019-10-08 19:22:15 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: sampling state accept",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: fmt.Sprintf("%s-%s-1", traceIDStr, spanIDStr),
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-05-02 14:17:11 +02:00
|
|
|
wantSc: trace.SpanContext{
|
2019-10-08 19:22:15 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
2020-05-05 19:41:54 +02:00
|
|
|
TraceFlags: trace.FlagsSampled,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: sampling state debug",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: fmt.Sprintf("%s-%s-d", traceIDStr, spanIDStr),
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-05-02 14:17:11 +02:00
|
|
|
wantSc: trace.SpanContext{
|
2019-10-08 19:22:15 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
2020-07-08 01:38:52 +02:00
|
|
|
TraceFlags: trace.FlagsDebug,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: with parent span id",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: fmt.Sprintf("%s-%s-1-00000000000000cd", traceIDStr, spanIDStr),
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-05-02 14:17:11 +02:00
|
|
|
wantSc: trace.SpanContext{
|
2019-10-08 19:22:15 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
2020-05-05 19:41:54 +02:00
|
|
|
TraceFlags: trace.FlagsSampled,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: with only sampling state deny",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: "0",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-05-02 14:17:11 +02:00
|
|
|
wantSc: trace.EmptySpanContext(),
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-05-05 20:20:09 +02:00
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: left-padding 64-bit traceID",
|
2020-05-05 20:20:09 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: fmt.Sprintf("a3ce929d0e0e4736-%s", spanIDStr),
|
2020-05-05 20:20:09 +02:00
|
|
|
},
|
|
|
|
wantSc: trace.SpanContext{
|
2020-07-08 01:38:52 +02:00
|
|
|
TraceID: traceID64bitPadded,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsDeferred,
|
2020-05-05 20:20:09 +02:00
|
|
|
},
|
|
|
|
},
|
2019-10-08 19:22:15 +02:00
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "both single and multiple: single priority",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: fmt.Sprintf("%s-%s-1", traceIDStr, spanIDStr),
|
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Sampled: "0",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-07-08 01:38:52 +02:00
|
|
|
wantSc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsSampled,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
2020-07-08 01:38:52 +02:00
|
|
|
// An invalid Single Headers should fallback to multiple.
|
2019-10-08 19:22:15 +02:00
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "both single and multiple: invalid single",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: fmt.Sprintf("%s-%s-", traceIDStr, spanIDStr),
|
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Sampled: "0",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
2020-07-08 01:38:52 +02:00
|
|
|
wantSc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
2020-07-08 01:38:52 +02:00
|
|
|
// Invalid Mult Header should not be noticed as Single takes precedence.
|
2019-10-08 19:22:15 +02:00
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "both single and multiple: invalid multiple",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: fmt.Sprintf("%s-%s-1", traceIDStr, spanIDStr),
|
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Sampled: "invalid",
|
|
|
|
},
|
|
|
|
wantSc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsSampled,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
2020-07-08 01:38:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var extractInvalidHeaders = []extractTest{
|
2019-10-08 19:22:15 +02:00
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: trace ID length > 32",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: "ab00000000000000000000000000000000",
|
|
|
|
b3SpanID: "cd00000000000000",
|
|
|
|
b3Sampled: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: trace ID length >16 and <32",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: "ab0000000000000000000000000000",
|
|
|
|
b3SpanID: "cd00000000000000",
|
|
|
|
b3Sampled: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: trace ID length <16",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: "ab0000000000",
|
|
|
|
b3SpanID: "cd00000000000000",
|
|
|
|
b3Sampled: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: wrong span ID length",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: "ab000000000000000000000000000000",
|
|
|
|
b3SpanID: "cd0000000000000000",
|
|
|
|
b3Sampled: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: wrong sampled flag length",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: "ab000000000000000000000000000000",
|
|
|
|
b3SpanID: "cd00000000000000",
|
|
|
|
b3Sampled: "10",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: bogus trace ID",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: "qw000000000000000000000000000000",
|
|
|
|
b3SpanID: "cd00000000000000",
|
|
|
|
b3Sampled: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: bogus span ID",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: "ab000000000000000000000000000000",
|
|
|
|
b3SpanID: "qw00000000000000",
|
|
|
|
b3Sampled: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: bogus sampled flag",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: "ab000000000000000000000000000000",
|
|
|
|
b3SpanID: "cd00000000000000",
|
|
|
|
b3Sampled: "d",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: upper case trace ID",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: "AB000000000000000000000000000000",
|
|
|
|
b3SpanID: "cd00000000000000",
|
|
|
|
b3Sampled: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: upper case span ID",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: "ab000000000000000000000000000000",
|
|
|
|
b3SpanID: "CD00000000000000",
|
|
|
|
b3Sampled: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: zero trace ID",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: "00000000000000000000000000000000",
|
|
|
|
b3SpanID: "cd00000000000000",
|
|
|
|
b3Sampled: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: zero span ID",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: "ab000000000000000000000000000000",
|
|
|
|
b3SpanID: "0000000000000000",
|
|
|
|
b3Sampled: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: missing span ID",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: "ab000000000000000000000000000000",
|
|
|
|
b3Sampled: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: missing trace ID",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3SpanID: "cd00000000000000",
|
|
|
|
b3Sampled: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "multiple: sampled header set to 1 but trace ID and span ID are missing",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Sampled: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: wrong trace ID length",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: "ab00000000000000000000000000000000-cd00000000000000-1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: wrong span ID length",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: "ab000000000000000000000000000000-cd0000000000000000-1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: wrong sampled state length",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: "00-ab000000000000000000000000000000-cd00000000000000-01",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: wrong parent span ID length",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: "ab000000000000000000000000000000-cd00000000000000-1-cd0000000000000000",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: bogus trace ID",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: "qw000000000000000000000000000000-cd00000000000000-1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: bogus span ID",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: "ab000000000000000000000000000000-qw00000000000000-1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: bogus sampled flag",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: "ab000000000000000000000000000000-cd00000000000000-q",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: bogus parent span ID",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: "ab000000000000000000000000000000-cd00000000000000-1-qw00000000000000",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: upper case trace ID",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: "AB000000000000000000000000000000-cd00000000000000-1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: upper case span ID",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: "ab000000000000000000000000000000-CD00000000000000-1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: upper case parent span ID",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: "ab000000000000000000000000000000-cd00000000000000-1-EF00000000000000",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: zero trace ID and span ID",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: "00000000000000000000000000000000-0000000000000000-1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single: with sampling set to true",
|
2019-10-08 19:22:15 +02:00
|
|
|
headers: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Context: "ab000000000000000000000000000000-cd00000000000000-true",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
type injectTest struct {
|
|
|
|
name string
|
2020-07-08 01:38:52 +02:00
|
|
|
encoding trace.B3Encoding
|
|
|
|
sc trace.SpanContext
|
2019-10-08 19:22:15 +02:00
|
|
|
wantHeaders map[string]string
|
|
|
|
doNotWantHeaders []string
|
|
|
|
}
|
|
|
|
|
2020-07-08 01:38:52 +02:00
|
|
|
var injectHeader = []injectTest{
|
2019-10-08 19:22:15 +02:00
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "none: sampled",
|
|
|
|
sc: trace.SpanContext{
|
2019-10-08 19:22:15 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
2020-05-05 19:41:54 +02:00
|
|
|
TraceFlags: trace.FlagsSampled,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Sampled: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
|
|
|
b3Context,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "none: not sampled",
|
|
|
|
sc: trace.SpanContext{
|
2019-10-08 19:22:15 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Sampled: "0",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
|
|
|
b3Context,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "none: unset sampled",
|
|
|
|
sc: trace.SpanContext{
|
2019-10-08 19:22:15 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
2020-07-08 01:38:52 +02:00
|
|
|
TraceFlags: trace.FlagsDeferred,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Sampled,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
|
|
|
b3Context,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "none: sampled only",
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceFlags: trace.FlagsSampled,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3Sampled: "1",
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3TraceID,
|
|
|
|
b3SpanID,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
|
|
|
b3Context,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "none: debug",
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsDebug,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Flags: "1",
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3Sampled,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Context,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "none: debug omitting sample",
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsSampled | trace.FlagsDebug,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Flags: "1",
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3Sampled,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Context,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple: sampled",
|
|
|
|
encoding: trace.B3MultipleHeader,
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsSampled,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Sampled: "1",
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
|
|
|
b3Context,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple: not sampled",
|
|
|
|
encoding: trace.B3MultipleHeader,
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Sampled: "0",
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
|
|
|
b3Context,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple: unset sampled",
|
|
|
|
encoding: trace.B3MultipleHeader,
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsDeferred,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3Sampled,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
|
|
|
b3Context,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple: sampled only",
|
|
|
|
encoding: trace.B3MultipleHeader,
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceFlags: trace.FlagsSampled,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3Sampled: "1",
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3TraceID,
|
|
|
|
b3SpanID,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
|
|
|
b3Context,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple: debug",
|
|
|
|
encoding: trace.B3MultipleHeader,
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsDebug,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Flags: "1",
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3Sampled,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Context,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple: debug omitting sample",
|
|
|
|
encoding: trace.B3MultipleHeader,
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsSampled | trace.FlagsDebug,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Flags: "1",
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3Sampled,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Context,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "single: sampled",
|
|
|
|
encoding: trace.B3SingleHeader,
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsSampled,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3Context: fmt.Sprintf("%s-%s-1", traceIDStr, spanIDStr),
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3TraceID,
|
|
|
|
b3SpanID,
|
|
|
|
b3Sampled,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "single: not sampled",
|
|
|
|
encoding: trace.B3SingleHeader,
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3Context: fmt.Sprintf("%s-%s-0", traceIDStr, spanIDStr),
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3TraceID,
|
|
|
|
b3SpanID,
|
|
|
|
b3Sampled,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "single: unset sampled",
|
|
|
|
encoding: trace.B3SingleHeader,
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsDeferred,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3Context: fmt.Sprintf("%s-%s", traceIDStr, spanIDStr),
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3TraceID,
|
|
|
|
b3SpanID,
|
|
|
|
b3Sampled,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "single: sampled only",
|
|
|
|
encoding: trace.B3SingleHeader,
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceFlags: trace.FlagsSampled,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3Context: "1",
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3Sampled,
|
|
|
|
b3TraceID,
|
|
|
|
b3SpanID,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
|
|
|
b3Context,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "single: debug",
|
|
|
|
encoding: trace.B3SingleHeader,
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsDebug,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3Context: fmt.Sprintf("%s-%s-d", traceIDStr, spanIDStr),
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3TraceID,
|
|
|
|
b3SpanID,
|
|
|
|
b3Flags,
|
|
|
|
b3Sampled,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Context,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "single: debug omitting sample",
|
|
|
|
encoding: trace.B3SingleHeader,
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsSampled | trace.FlagsDebug,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3Context: fmt.Sprintf("%s-%s-d", traceIDStr, spanIDStr),
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3TraceID,
|
|
|
|
b3SpanID,
|
|
|
|
b3Flags,
|
|
|
|
b3Sampled,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Context,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single+multiple: sampled",
|
|
|
|
encoding: trace.B3SingleHeader | trace.B3MultipleHeader,
|
|
|
|
sc: trace.SpanContext{
|
2019-10-08 19:22:15 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
2020-05-05 19:41:54 +02:00
|
|
|
TraceFlags: trace.FlagsSampled,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Sampled: "1",
|
|
|
|
b3Context: fmt.Sprintf("%s-%s-1", traceIDStr, spanIDStr),
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single+multiple: not sampled",
|
|
|
|
encoding: trace.B3SingleHeader | trace.B3MultipleHeader,
|
|
|
|
sc: trace.SpanContext{
|
2019-10-08 19:22:15 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Sampled: "0",
|
|
|
|
b3Context: fmt.Sprintf("%s-%s-0", traceIDStr, spanIDStr),
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "single+multiple: unset sampled",
|
|
|
|
encoding: trace.B3SingleHeader | trace.B3MultipleHeader,
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsDeferred,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Context: fmt.Sprintf("%s-%s", traceIDStr, spanIDStr),
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3Sampled,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "single+multiple: sampled only",
|
|
|
|
encoding: trace.B3SingleHeader | trace.B3MultipleHeader,
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceFlags: trace.FlagsSampled,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3Context: "1",
|
|
|
|
b3Sampled: "1",
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID,
|
|
|
|
b3SpanID,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-08 01:38:52 +02:00
|
|
|
name: "single+multiple: debug",
|
|
|
|
encoding: trace.B3SingleHeader | trace.B3MultipleHeader,
|
|
|
|
sc: trace.SpanContext{
|
2019-10-08 19:22:15 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
2020-07-08 01:38:52 +02:00
|
|
|
TraceFlags: trace.FlagsDebug,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Flags: "1",
|
|
|
|
b3Context: fmt.Sprintf("%s-%s-d", traceIDStr, spanIDStr),
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
2020-07-08 01:38:52 +02:00
|
|
|
b3Sampled,
|
|
|
|
b3ParentSpanID,
|
2019-10-08 19:22:15 +02:00
|
|
|
},
|
|
|
|
},
|
2020-07-08 01:38:52 +02:00
|
|
|
{
|
|
|
|
name: "single+multiple: debug omitting sample",
|
|
|
|
encoding: trace.B3SingleHeader | trace.B3MultipleHeader,
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsSampled | trace.FlagsDebug,
|
|
|
|
},
|
|
|
|
wantHeaders: map[string]string{
|
|
|
|
b3TraceID: traceIDStr,
|
|
|
|
b3SpanID: spanIDStr,
|
|
|
|
b3Flags: "1",
|
|
|
|
b3Context: fmt.Sprintf("%s-%s-d", traceIDStr, spanIDStr),
|
|
|
|
},
|
|
|
|
doNotWantHeaders: []string{
|
|
|
|
b3Sampled,
|
|
|
|
b3ParentSpanID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var injectInvalidHeaderGenerator = []injectTest{
|
|
|
|
{
|
|
|
|
name: "empty",
|
|
|
|
sc: trace.SpanContext{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "missing traceID",
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
SpanID: spanID,
|
|
|
|
TraceFlags: trace.FlagsSampled,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "missing spanID",
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceID: traceID,
|
|
|
|
TraceFlags: trace.FlagsSampled,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "missing traceID and spanID",
|
|
|
|
sc: trace.SpanContext{
|
|
|
|
TraceFlags: trace.FlagsSampled,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var injectInvalidHeader []injectTest
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// Preform a test for each invalid injectTest with all combinations of
|
|
|
|
// encoding values.
|
|
|
|
injectInvalidHeader = make([]injectTest, 0, len(injectInvalidHeaderGenerator)*4)
|
|
|
|
allHeaders := []string{
|
|
|
|
b3TraceID,
|
|
|
|
b3SpanID,
|
|
|
|
b3Sampled,
|
|
|
|
b3ParentSpanID,
|
|
|
|
b3Flags,
|
|
|
|
b3Context,
|
|
|
|
}
|
|
|
|
// Nothing should be set for any header regardless of encoding.
|
|
|
|
for _, t := range injectInvalidHeaderGenerator {
|
|
|
|
injectInvalidHeader = append(injectInvalidHeader, injectTest{
|
|
|
|
name: "none: " + t.name,
|
|
|
|
sc: t.sc,
|
|
|
|
doNotWantHeaders: allHeaders,
|
|
|
|
})
|
|
|
|
injectInvalidHeader = append(injectInvalidHeader, injectTest{
|
|
|
|
name: "multiple: " + t.name,
|
|
|
|
encoding: trace.B3MultipleHeader,
|
|
|
|
sc: t.sc,
|
|
|
|
doNotWantHeaders: allHeaders,
|
|
|
|
})
|
|
|
|
injectInvalidHeader = append(injectInvalidHeader, injectTest{
|
|
|
|
name: "single: " + t.name,
|
|
|
|
encoding: trace.B3SingleHeader,
|
|
|
|
sc: t.sc,
|
|
|
|
doNotWantHeaders: allHeaders,
|
|
|
|
})
|
|
|
|
injectInvalidHeader = append(injectInvalidHeader, injectTest{
|
|
|
|
name: "single+multiple: " + t.name,
|
|
|
|
encoding: trace.B3SingleHeader | trace.B3MultipleHeader,
|
|
|
|
sc: t.sc,
|
|
|
|
doNotWantHeaders: allHeaders,
|
|
|
|
})
|
|
|
|
}
|
2019-10-23 01:12:45 +02:00
|
|
|
}
|