@@ -11,6 +11,7 @@ const API = require('../../../api')
11
11
const DESTINATIONS = require ( '../../../lib/config/attribute-filter' ) . DESTINATIONS
12
12
const hashes = require ( '../../../lib/util/hashes' )
13
13
const helper = require ( '../../lib/agent_helper' )
14
+ const { findSegment } = require ( '#testlib/metrics_helper.js' )
14
15
const MessageShim = require ( '../../../lib/shim/message-shim' )
15
16
const { MessageSpec, MessageSubscribeSpec } = require ( '../../../lib/shim/specs' )
16
17
const {
@@ -369,6 +370,27 @@ test('MessageShim', async function (t) {
369
370
} )
370
371
} )
371
372
373
+ await t . test ( 'should insert DT request headers' , function ( t , end ) {
374
+ const { agent, shim, wrappable } = t . nr
375
+ agent . config . cross_application_tracer . enabled = false
376
+ agent . config . distributed_tracing . enabled = true
377
+ const headers = { }
378
+ shim . recordProduce ( wrappable , 'getActiveSegment' , function ( ) {
379
+ return new MessageSpec ( { headers } )
380
+ } )
381
+
382
+ helper . runInTransaction ( agent , function ( tx ) {
383
+ wrappable . getActiveSegment ( )
384
+ const segment = findSegment ( tx . trace , tx . trace . root , 'MessageBroker/RabbitMQ/Exchange/Produce/Temp' )
385
+ const [ version , traceId , parentSpanId , sampledFlag ] = headers . traceparent . split ( '-' )
386
+ assert . equal ( version , '00' )
387
+ assert . equal ( traceId , tx . traceId )
388
+ assert . equal ( parentSpanId , segment . id )
389
+ assert . equal ( sampledFlag , '01' )
390
+ end ( )
391
+ } )
392
+ } )
393
+
372
394
await t . test ( 'should insert distributed trace headers in all messages' , async function ( t ) {
373
395
const plan = tspl ( t , { plan : 1 } )
374
396
const { agent, shim, wrappable } = t . nr
@@ -393,26 +415,27 @@ test('MessageShim', async function (t) {
393
415
)
394
416
395
417
let called = 0
396
- agent . on ( 'transactionFinished' , ( ) => {
418
+ agent . on ( 'transactionFinished' , ( tx ) => {
397
419
called ++
420
+ const segment = findSegment ( tx . trace , tx . trace . root , 'MessageBroker/RabbitMQ/Exchange/Produce/Temp' )
398
421
match ( messages , [
399
422
{
400
423
headers : {
401
424
newrelic : '' ,
402
- traceparent : / ^ 0 0 - /
425
+ traceparent : ` 00-${ tx . traceId } - ${ segment . id } -01`
403
426
}
404
427
} ,
405
428
{
406
429
headers : {
407
430
newrelic : '' ,
408
- traceparent : / ^ 0 0 - / ,
431
+ traceparent : ` 00-${ tx . traceId } - ${ segment . id } -01` ,
409
432
foo : 'foo'
410
433
}
411
434
} ,
412
435
{
413
436
headers : {
414
437
newrelic : '' ,
415
- traceparent : / ^ 0 0 - /
438
+ traceparent : ` 00-${ tx . traceId } - ${ segment . id } -01`
416
439
}
417
440
}
418
441
] )
0 commit comments