@@ -8,6 +8,7 @@ const { rawExpectedSchema } = require('./sqs-naming')
88
99const queueName = 'SQS_QUEUE_NAME'
1010const queueNameDSM = 'SQS_QUEUE_NAME_DSM'
11+ const queueNameDSMConsumerOnly = 'SQS_QUEUE_NAME_DSM_CONSUMER_ONLY'
1112
1213const getQueueParams = ( queueName ) => {
1314 return {
@@ -20,6 +21,7 @@ const getQueueParams = (queueName) => {
2021
2122const queueOptions = getQueueParams ( queueName )
2223const queueOptionsDsm = getQueueParams ( queueNameDSM )
24+ const queueOptionsDsmConsumerOnly = getQueueParams ( queueNameDSMConsumerOnly )
2325
2426describe ( 'Plugin' , ( ) => {
2527 describe ( 'aws-sdk (sqs)' , function ( ) {
@@ -30,6 +32,7 @@ describe('Plugin', () => {
3032 let sqs
3133 const QueueUrl = 'http://127.0.0.1:4566/00000000000000000000/SQS_QUEUE_NAME'
3234 const QueueUrlDsm = 'http://127.0.0.1:4566/00000000000000000000/SQS_QUEUE_NAME_DSM'
35+ const QueueUrlDsmConsumerOnly = 'http://127.0.0.1:4566/00000000000000000000/SQS_QUEUE_NAME_DSM_CONSUMER_ONLY'
3336 let tracer
3437
3538 const sqsClientName = moduleName === '@aws-sdk/smithy-client' ? '@aws-sdk/client-sqs' : 'aws-sdk'
@@ -412,10 +415,25 @@ describe('Plugin', () => {
412415 } )
413416 } )
414417
418+ before ( done => {
419+ AWS = require ( `../../../versions/${ sqsClientName } @${ version } ` ) . get ( )
420+
421+ sqs = new AWS . SQS ( { endpoint : 'http://127.0.0.1:4566' , region : 'us-east-1' } )
422+ sqs . createQueue ( queueOptionsDsmConsumerOnly , ( err , res ) => {
423+ if ( err ) return done ( err )
424+
425+ done ( )
426+ } )
427+ } )
428+
415429 after ( done => {
416430 sqs . deleteQueue ( { QueueUrl : QueueUrlDsm } , done )
417431 } )
418432
433+ after ( done => {
434+ sqs . deleteQueue ( { QueueUrl : QueueUrlDsmConsumerOnly } , done )
435+ } )
436+
419437 after ( ( ) => {
420438 return agent . close ( { ritmReset : false } )
421439 } )
@@ -546,6 +564,28 @@ describe('Plugin', () => {
546564 } )
547565 } )
548566
567+ it ( 'Should emit DSM stats when receiving a message when the producer was not instrumented' , done => {
568+ agent . expectPipelineStats ( dsmStats => {
569+ let statsPointsReceived = 0
570+ // we should have 2 dsm stats points
571+ dsmStats . forEach ( ( timeStatsBucket ) => {
572+ if ( timeStatsBucket && timeStatsBucket . Stats ) {
573+ timeStatsBucket . Stats . forEach ( ( statsBuckets ) => {
574+ statsPointsReceived += statsBuckets . Stats . length
575+ } )
576+ }
577+ } )
578+ expect ( statsPointsReceived ) . to . equal ( 1 )
579+ expect ( agent . dsmStatsExistWithParentHash ( agent , '0' ) ) . to . equal ( true )
580+ } ) . then ( done , done )
581+
582+ agent . reload ( 'aws-sdk' , { sqs : { dsmEnabled : false } } , { dsmEnabled : false } )
583+ sqs . sendMessage ( { MessageBody : 'test DSM' , QueueUrl : QueueUrlDsmConsumerOnly } , ( ) => {
584+ agent . reload ( 'aws-sdk' , { sqs : { dsmEnabled : true } } , { dsmEnabled : true } )
585+ sqs . receiveMessage ( { QueueUrl : QueueUrlDsmConsumerOnly , MessageAttributeNames : [ '.*' ] } , ( ) => { } )
586+ } )
587+ } )
588+
549589 it ( 'Should emit DSM stats to the agent when sending batch messages' , done => {
550590 // we need to stub Date.now() to ensure a new stats bucket is created for each call
551591 // otherwise, all stats checkpoints will be combined into a single stats points
0 commit comments