@@ -23,6 +23,7 @@ import (
23
23
v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
24
24
"github.com/stretchr/testify/require"
25
25
"google.golang.org/grpc"
26
+ "google.golang.org/grpc/metadata"
26
27
)
27
28
28
29
func TestAppSec (t * testing.T ) {
@@ -273,6 +274,45 @@ func TestGeneratedSpan(t *testing.T) {
273
274
require .Equal (t , "server" , span .Tag ("span.kind" ))
274
275
require .Equal (t , "Mistake Not..." , span .Tag ("http.useragent" ))
275
276
})
277
+
278
+ t .Run ("span-with-injected-context" , func (t * testing.T ) {
279
+ client , mt , cleanup := setup ()
280
+ defer cleanup ()
281
+
282
+ ctx := context .Background ()
283
+
284
+ // add metadata to the context
285
+ ctx = metadata .AppendToOutgoingContext (ctx ,
286
+ "x-datadog-trace-id" , "12345" ,
287
+ "x-datadog-parent-id" , "67890" ,
288
+ )
289
+
290
+ stream , err := client .Process (ctx )
291
+ require .NoError (t , err )
292
+
293
+ end2EndStreamRequest (t , stream , "/../../../resource-span/.?id=test" , "GET" , map [string ]string {"user-agent" : "Mistake Not..." , "test-key" : "test-value" }, map [string ]string {"response-test-key" : "response-test-value" }, false )
294
+
295
+ err = stream .CloseSend ()
296
+ require .NoError (t , err )
297
+ stream .Recv () // to flush the spans
298
+
299
+ finished := mt .FinishedSpans ()
300
+ require .Len (t , finished , 1 )
301
+
302
+ // Check for tags
303
+ span := finished [0 ]
304
+ require .Equal (t , "http.request" , span .OperationName ())
305
+ require .Equal (t , "https://datadoghq.com/../../../resource-span/.?id=test" , span .Tag ("http.url" ))
306
+ require .Equal (t , "GET" , span .Tag ("http.method" ))
307
+ require .Equal (t , "datadoghq.com" , span .Tag ("http.host" ))
308
+ require .Equal (t , "GET /resource-span" , span .Tag ("resource.name" ))
309
+ require .Equal (t , "server" , span .Tag ("span.kind" ))
310
+ require .Equal (t , "Mistake Not..." , span .Tag ("http.useragent" ))
311
+
312
+ // Check for trace context
313
+ require .Equal (t , uint64 (12345 ), span .Context ().TraceID ())
314
+ require .Equal (t , uint64 (67890 ), span .ParentID ())
315
+ })
276
316
}
277
317
278
318
func TestXForwardedForHeaderClientIp (t * testing.T ) {
0 commit comments