@@ -223,6 +223,34 @@ func TestExtensionEndInvocationError(t *testing.T) {
223
223
assert .Contains (t , logOutput , "could not send end invocation payload to the extension" )
224
224
}
225
225
226
+ type mockSpanContext struct {
227
+ ddtrace.SpanContext
228
+ }
229
+
230
+ func (m mockSpanContext ) TraceID () uint64 { return 123 }
231
+ func (m mockSpanContext ) SpanID () uint64 { return 456 }
232
+ func (m mockSpanContext ) SamplingPriority () (int , bool ) { return - 1 , true }
233
+
234
+ type mockSpan struct { ddtrace.Span }
235
+
236
+ func (m mockSpan ) Context () ddtrace.SpanContext { return mockSpanContext {} }
237
+
238
+ func TestExtensionEndInvocationSamplingPriority (t * testing.T ) {
239
+ headers := http.Header {}
240
+ em := & ExtensionManager {httpClient : capturingClient {hdr : headers }}
241
+ span := & mockSpan {}
242
+
243
+ // When priority in context, use that value
244
+ ctx := context .WithValue (context .Background (), DdTraceId , "123" )
245
+ ctx = context .WithValue (ctx , DdSamplingPriority , "2" )
246
+ em .SendEndInvocationRequest (ctx , span , ddtrace.FinishConfig {})
247
+ assert .Equal (t , "2" , headers .Get ("X-Datadog-Sampling-Priority" ))
248
+
249
+ // When no context, get priority from span
250
+ em .SendEndInvocationRequest (context .Background (), span , ddtrace.FinishConfig {})
251
+ assert .Equal (t , "-1" , headers .Get ("X-Datadog-Sampling-Priority" ))
252
+ }
253
+
226
254
type capturingClient struct {
227
255
hdr http.Header
228
256
}
0 commit comments