Skip to content

Commit ef1b611

Browse files
authored
fix: Updated message consumer subscribers to properly time the consumption actions (#3660)
1 parent ae84b62 commit ef1b611

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

lib/subscribers/message-consumer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class MessageConsumerSubscriber extends Subscriber {
105105
*/
106106
asyncStart() {
107107
const ctx = this.agent.tracer.getContext()
108-
const tx = ctx?.transaction
108+
const tx = ctx.transaction
109109
tx.setPartialName(this.name)
110110
// Note: this is not using `Subscriber.createSegment`
111111
// this is because it enters the segment and returns a new ctx
@@ -117,6 +117,7 @@ class MessageConsumerSubscriber extends Subscriber {
117117
parent: tx.trace.root,
118118
transaction: tx
119119
})
120+
tx.baseSegment.start()
120121

121122
this.addConsumeParameters(tx)
122123

test/versioned/amqplib/callback.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ test('amqplib callback instrumentation', async function (t) {
480480
agent.on('transactionFinished', function (tx) {
481481
amqpUtils.verifyConsumeTransaction(tx, exchange, queue, 'consume-tx-key')
482482
assert.ok(tx.trace.getDurationInMillis() >= PROMISE_WAIT, 'transaction should account for async work')
483+
484+
assert.ok(tx.baseSegment.getDurationInMillis() >= PROMISE_WAIT, 'base segment should account for async work')
483485
end()
484486
})
485487

test/versioned/amqplib/promises.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ test('amqplib promise instrumentation', async function (t) {
457457
process.nextTick(() => {
458458
amqpUtils.verifyConsumeTransaction(tx, amqpUtils.DIRECT_EXCHANGE, queue, 'consume-tx-key')
459459
assert.ok(tx.trace.getDurationInMillis() >= PROMISE_WAIT, 'transaction should account for async work')
460+
assert.ok(tx.baseSegment.getDurationInMillis() >= PROMISE_WAIT, 'base segment should account for async work')
460461
})
461462
})
462463

0 commit comments

Comments
 (0)