-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtracing_test.go
More file actions
81 lines (72 loc) · 2 KB
/
tracing_test.go
File metadata and controls
81 lines (72 loc) · 2 KB
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
package telemetry
import (
"testing"
"go.opentelemetry.io/otel/attribute"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)
func TestFilterSampler_ShouldSample(t *testing.T) {
tests := []struct {
name string
params sdktrace.SamplingParameters
wantDrop bool
baseSample sdktrace.SamplingResult
}{
{
name: "should drop span with drop attribute",
params: sdktrace.SamplingParameters{
Name: "test-span",
Attributes: []attribute.KeyValue{DropSpanAttribute},
},
wantDrop: true,
},
{
name: "should drop BatchWriteSpans",
params: sdktrace.SamplingParameters{
Name: "google.devtools.cloudtrace.v2.TraceService/BatchWriteSpans",
},
wantDrop: true,
},
{
name: "should not drop regular span",
params: sdktrace.SamplingParameters{
Name: "test-span",
},
wantDrop: false,
baseSample: sdktrace.SamplingResult{Decision: sdktrace.RecordAndSample},
},
{
name: "should not drop span with drop=false",
params: sdktrace.SamplingParameters{
Name: "test-span",
Attributes: []attribute.KeyValue{
attribute.Bool("drop", false),
},
},
wantDrop: false,
baseSample: sdktrace.SamplingResult{Decision: sdktrace.RecordAndSample},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
sampler := &filterSampler{
baseSampler: &testSampler{result: tt.baseSample},
}
got := sampler.ShouldSample(tt.params)
if tt.wantDrop && got.Decision != sdktrace.Drop {
t.Errorf("filterSampler.ShouldSample() = %v, want Drop", got.Decision)
} else if !tt.wantDrop && got.Decision != tt.baseSample.Decision {
t.Errorf("filterSampler.ShouldSample() = %v, want %v", got.Decision, tt.baseSample.Decision)
}
})
}
}
// testSampler is a mock sampler for testing
type testSampler struct {
result sdktrace.SamplingResult
}
func (s *testSampler) ShouldSample(parameters sdktrace.SamplingParameters) sdktrace.SamplingResult {
return s.result
}
func (s *testSampler) Description() string {
return "test sampler"
}