-
Notifications
You must be signed in to change notification settings - Fork 2
/
propagator_test.go
120 lines (111 loc) · 2.42 KB
/
propagator_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package datadog
import (
"testing"
"go.opentelemetry.io/otel/trace"
"github.com/stretchr/testify/assert"
)
var (
// 000000000000000079d48a391a778fa6
traceID = trace.TraceID{0, 0, 0, 0, 0, 0, 0, 0, 0x79, 0xd4, 0x8a, 0x39, 0x1a, 0x77, 0x8f, 0xa6}
ddTraceID = "8778793551513751462"
// 53995c3f42cd8ad8
spanID = trace.SpanID{0x53, 0x99, 0x5c, 0x3f, 0x42, 0xcd, 0x8a, 0xd8}
ddParentID = "6023947403358210776"
// 000000000000000000000000075bcd15
traceIDSmall = trace.TraceID{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x07, 0x5b, 0xcd, 0x15}
ddTraceIDSmall = "123456789"
// 000000003ade68b1
spanIDSmall = trace.SpanID{0, 0, 0, 0, 0x3a, 0xde, 0x68, 0xb1}
ddParentIDSmall = "987654321"
)
func TestExtractMultiple(t *testing.T) {
tests := []struct {
traceID string
spanID string
sampled string
expected trace.SpanContextConfig
err error
}{
{
ddTraceID, ddParentID, notSampled,
trace.SpanContextConfig{
TraceID: traceID,
SpanID: spanID,
},
nil,
},
{
ddTraceID, ddParentID, isSampled,
trace.SpanContextConfig{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.FlagsSampled,
},
nil,
},
{
ddTraceIDSmall, ddParentIDSmall, "",
trace.SpanContextConfig{},
errInvalidSamplingPriorityHeader,
},
{
"", ddParentID, "",
trace.SpanContextConfig{},
errMalformedTraceID,
},
{
ddTraceID, "", "",
trace.SpanContextConfig{},
errMalformedSpanID,
},
{
"0000000000000000000", ddParentID, "",
trace.SpanContextConfig{},
errInvalidTraceIDHeader,
},
{
ddTraceID, "0000000000000000000", "",
trace.SpanContextConfig{},
errInvalidSpanIDHeader,
},
{
ddTraceID, ddParentID, "foo",
trace.SpanContextConfig{},
errInvalidSamplingPriorityHeader,
},
{
ddTraceID, ddParentID, "2",
trace.SpanContextConfig{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.FlagsSampled,
},
nil,
},
{
ddTraceID, ddParentID, "-1",
trace.SpanContextConfig{
TraceID: traceID,
SpanID: spanID,
},
nil,
},
}
for _, test := range tests {
actual, err := extract(
test.traceID,
test.spanID,
test.sampled,
)
info := []interface{}{
"trace ID: %q, span ID: %q, sampled: %q",
test.traceID,
test.spanID,
test.sampled,
}
if !assert.Equal(t, test.err, err, info...) {
continue
}
assert.Equal(t, trace.NewSpanContext(test.expected), actual, info...)
}
}