@@ -34,7 +34,7 @@ func TestPackMetadata(t *testing.T) {
34
34
}
35
35
}
36
36
37
- func TestOpenTelemetryContextNotSmapled (t * testing.T ) {
37
+ func TestAddOtelSpanContextToContext_NotSmapled (t * testing.T ) {
38
38
r := httptest .NewRequest ("GET" , "/foo" , nil )
39
39
r .Header .Set (headerRequestID , dummyRequestID )
40
40
r .Header .Set (b3 .ParentSpanID , "0716f381a10c2a9b" )
@@ -46,8 +46,7 @@ func TestOpenTelemetryContextNotSmapled(t *testing.T) {
46
46
data , err := ExtractHTTP (r )
47
47
assert .Nil (t , err )
48
48
49
- ctx , err = addOtelSpanContextToContext (ctx , data )
50
- assert .Nil (t , err )
49
+ ctx = addOtelSpanContextToContext (ctx , data )
51
50
52
51
spanContext := trace .RemoteSpanContextFromContext (ctx )
53
52
@@ -57,7 +56,7 @@ func TestOpenTelemetryContextNotSmapled(t *testing.T) {
57
56
assert .Equal (t , spanContext .TraceID .String (), data .TraceSpan .TraceID .String ())
58
57
}
59
58
60
- func TestOpenTelemetryContextSmapled (t * testing.T ) {
59
+ func TestAddOtelSpanContextToContext_Smapled (t * testing.T ) {
61
60
r := httptest .NewRequest ("GET" , "/foo" , nil )
62
61
r .Header .Set (headerRequestID , dummyRequestID )
63
62
r .Header .Set (b3 .ParentSpanID , "0716f381a10c2a9b" )
@@ -69,8 +68,7 @@ func TestOpenTelemetryContextSmapled(t *testing.T) {
69
68
data , err := ExtractHTTP (r )
70
69
assert .Nil (t , err )
71
70
72
- ctx , err = addOtelSpanContextToContext (ctx , data )
73
- assert .Nil (t , err )
71
+ ctx = addOtelSpanContextToContext (ctx , data )
74
72
75
73
spanContext := trace .RemoteSpanContextFromContext (ctx )
76
74
@@ -80,6 +78,28 @@ func TestOpenTelemetryContextSmapled(t *testing.T) {
80
78
assert .Equal (t , spanContext .TraceID .String (), data .TraceSpan .TraceID .String ())
81
79
}
82
80
81
+ func TestAddOtelSpanContextToContext_InvalidParent (t * testing.T ) {
82
+ r := httptest .NewRequest ("GET" , "/foo" , nil )
83
+ r .Header .Set (headerRequestID , dummyRequestID )
84
+ r .Header .Set (b3 .ParentSpanID , "" )
85
+ r .Header .Set (b3 .Sampled , "1" )
86
+ r .Header .Set (b3 .SpanID , "" )
87
+ r .Header .Set (b3 .TraceID , "" )
88
+
89
+ ctx := context .Background ()
90
+ data , err := ExtractHTTP (r )
91
+ assert .Nil (t , err )
92
+
93
+ ctx = addOtelSpanContextToContext (ctx , data )
94
+
95
+ // If there's no spanContext in the ctx, default EmptySpanContext is returned
96
+ spanContext := trace .RemoteSpanContextFromContext (ctx )
97
+
98
+ assert .NotNil (t , spanContext )
99
+ assert .False (t , spanContext .IsValid ())
100
+ assert .Equal (t , spanContext , trace .EmptySpanContext ())
101
+ }
102
+
83
103
func TestExtractHTTP (t * testing.T ) {
84
104
r := httptest .NewRequest ("GET" , "/foo" , nil )
85
105
r .Header .Set (headerRequestID , dummyRequestID )
0 commit comments