Skip to content

Commit 554b4bf

Browse files
committed
fix: Updated shim.createSegment and shim.handleMqTracingHeaders to be backwards compatible with the changes to context manager (#2844)
1 parent 436c63d commit 554b4bf

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

lib/shim/message-shim/subscribe-consume.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ function createConsumerWrapper({ shim, spec, consumer }) {
213213
}
214214
}
215215
if (msgDesc.headers) {
216-
shim.handleMqTracingHeaders(msgDesc.headers, tx.baseSegment, tx, shim._transportType)
216+
shim.handleMqTracingHeaders(msgDesc.headers, tx.baseSegment, shim._transportType, tx)
217217
}
218218

219219
shim.logger.trace('Started message transaction %s named %s', tx.id, txName)

lib/shim/shim.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,7 @@ function createSegment(name, recorder, parent) {
13141314
}
13151315

13161316
const transaction = this.tracer.getTransaction()
1317+
parent = parent || this.getActiveSegment()
13171318
const spec = new specs.SegmentSpec(opts)
13181319
return _rawCreateSegment({ shim: this, spec, parent, transaction })
13191320
}

lib/shim/transaction-shim.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function setTransactionName(name) {
184184
/**
185185
* Retrieves whatever CAT headers may be in the given headers.
186186
*
187-
* - `handleMqTracingHeaders(headers [, segment [, transportType]])`
187+
* - `handleMqTracingHeaders(headers [, segment ] [, transportType], [, transaction])`
188188
*
189189
* @memberof TransactionShim.prototype
190190
*
@@ -195,11 +195,11 @@ function setTransactionName(name) {
195195
* @param {TraceSegment} [segment]
196196
* The trace segment to associate the header data with. If no segment is
197197
* provided then the currently active segment is used.
198-
* @param {Transaction} transaction active transaction
199198
* @param {string} [transportType]
200199
* The transport type that brought the headers. Usually `HTTP` or `HTTPS`.
200+
* @param {Transaction} transaction active transaction
201201
*/
202-
function handleMqTracingHeaders(headers, segment, transaction, transportType) {
202+
function handleMqTracingHeaders(headers, segment, transportType, transaction) {
203203
// TODO: replace functionality when CAT fully removed.
204204

205205
if (!headers) {
@@ -216,6 +216,7 @@ function handleMqTracingHeaders(headers, segment, transaction, transportType) {
216216

217217
// Check that we're in an active transaction.
218218
const currentSegment = segment || this.getSegment()
219+
transaction = transaction || this.tracer.getTransaction()
219220
if (!currentSegment || !transaction.isActive()) {
220221
this.logger.trace('Not processing headers for CAT or DT, not in an active transaction.')
221222
return

test/unit/shim/shim.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2113,7 +2113,7 @@ test('Shim', async function (t) {
21132113
helper.runInTransaction(agent, function (tx) {
21142114
const args = [wrappable.getActiveSegment]
21152115
const segment = wrappable.getActiveSegment()
2116-
const parent = shim.createSegment({ name: 'test segment', parent: segment })
2116+
const parent = shim.createSegment('test-segment')
21172117
shim.bindCallbackSegment({}, args, shim.LAST, parent)
21182118
const cbSegment = args[0]()
21192119

test/unit/shim/transaction-shim.test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ test('TransactionShim', async function (t) {
441441
assert.ok(!segment.catTransaction)
442442
assert.ok(!segment.getAttributes().transaction_guid)
443443

444-
shim.handleMqTracingHeaders(headers, segment, tx)
444+
shim.handleMqTracingHeaders(headers, segment, null, tx)
445445

446446
assert.ok(!tx.incomingCatId)
447447
assert.ok(!tx.referringTransactionGuid)
@@ -465,7 +465,7 @@ test('TransactionShim', async function (t) {
465465
assert.ok(!segment.catTransaction)
466466
assert.ok(!segment.getAttributes().transaction_guid)
467467

468-
shim.handleMqTracingHeaders(headers, segment, tx)
468+
shim.handleMqTracingHeaders(headers, segment, null, tx)
469469

470470
assert.ok(!tx.incomingCatId)
471471
assert.ok(!tx.referringTransactionGuid)
@@ -488,7 +488,7 @@ test('TransactionShim', async function (t) {
488488
assert.ok(!segment.getAttributes().transaction_guid)
489489

490490
assert.doesNotThrow(function () {
491-
shim.handleMqTracingHeaders(null, segment, tx)
491+
shim.handleMqTracingHeaders(null, segment, null, tx)
492492
})
493493

494494
assert.ok(!tx.incomingCatId)
@@ -516,7 +516,7 @@ test('TransactionShim', async function (t) {
516516

517517
helper.runInTransaction(agent, shim.BG, function (tx2) {
518518
assert.notEqual(tx2, tx)
519-
shim.handleMqTracingHeaders(headers, segment, tx)
519+
shim.handleMqTracingHeaders(headers, segment, null, tx)
520520
})
521521

522522
assert.equal(tx.incomingCatId, '9876#id')
@@ -541,7 +541,7 @@ test('TransactionShim', async function (t) {
541541
assert.ok(!tx.tripId)
542542
assert.ok(!tx.referringPathHash)
543543

544-
shim.handleMqTracingHeaders(headers, null, tx)
544+
shim.handleMqTracingHeaders(headers)
545545

546546
assert.equal(tx.incomingCatId, '9876#id')
547547
assert.equal(tx.referringTransactionGuid, 'trans id')
@@ -568,7 +568,7 @@ test('TransactionShim', async function (t) {
568568

569569
helper.runInTransaction(agent, shim.BG, function (tx2) {
570570
assert.notEqual(tx2, tx)
571-
shim.handleMqTracingHeaders(headers, segment, tx)
571+
shim.handleMqTracingHeaders(headers, segment, null, tx)
572572
})
573573

574574
assert.equal(tx.incomingCatId, '9876#id')
@@ -592,7 +592,7 @@ test('TransactionShim', async function (t) {
592592
helper.runInTransaction(agent, function (tx) {
593593
const headers = { traceparent, tracestate }
594594
const segment = shim.getSegment()
595-
shim.handleMqTracingHeaders(headers, segment, tx)
595+
shim.handleMqTracingHeaders(headers, segment)
596596

597597
const outboundHeaders = {}
598598
tx.insertDistributedTraceHeaders(outboundHeaders)
@@ -615,7 +615,7 @@ test('TransactionShim', async function (t) {
615615
helper.runInTransaction(agent, function (tx) {
616616
const headers = { traceparent }
617617
const segment = shim.getSegment()
618-
shim.handleMqTracingHeaders(headers, segment, tx)
618+
shim.handleMqTracingHeaders(headers, segment, null, tx)
619619

620620
const outboundHeaders = {}
621621
tx.insertDistributedTraceHeaders(outboundHeaders)
@@ -638,7 +638,7 @@ test('TransactionShim', async function (t) {
638638
helper.runInTransaction(agent, function (tx) {
639639
const headers = { traceparent, tracestate }
640640
const segment = shim.getSegment()
641-
shim.handleMqTracingHeaders(headers, segment, tx)
641+
shim.handleMqTracingHeaders(headers, segment, null, tx)
642642

643643
const outboundHeaders = {}
644644
tx.insertDistributedTraceHeaders(outboundHeaders)
@@ -660,7 +660,7 @@ test('TransactionShim', async function (t) {
660660
helper.runInTransaction(agent, function (tx) {
661661
const headers = { traceparent, tracestate }
662662
const segment = shim.getSegment()
663-
shim.handleMqTracingHeaders(headers, segment, tx)
663+
shim.handleMqTracingHeaders(headers, segment, null, tx)
664664

665665
const outboundHeaders = {}
666666
tx.insertDistributedTraceHeaders(outboundHeaders)
@@ -687,7 +687,7 @@ test('TransactionShim', async function (t) {
687687

688688
helper.runInTransaction(agent, shim.BG, function (tx2) {
689689
assert.notEqual(tx2, tx)
690-
shim.handleMqTracingHeaders(headers, segment, tx2)
690+
shim.handleMqTracingHeaders(headers, segment, null, tx2)
691691
})
692692

693693
assert.equal(segment.catId, '6789#app')
@@ -712,7 +712,7 @@ test('TransactionShim', async function (t) {
712712
assert.ok(!segment.catTransaction)
713713
assert.ok(!segment.getAttributes().transaction_guid)
714714

715-
shim.handleMqTracingHeaders(headers, null, tx)
715+
shim.handleMqTracingHeaders(headers, null, null, tx)
716716

717717
assert.equal(segment.catId, '6789#app')
718718
assert.equal(segment.catTransaction, 'app data transaction name')
@@ -738,7 +738,7 @@ test('TransactionShim', async function (t) {
738738

739739
helper.runInTransaction(agent, shim.BG, function (tx2) {
740740
assert.notEqual(tx2, tx)
741-
shim.handleMqTracingHeaders(headers, segment, tx2)
741+
shim.handleMqTracingHeaders(headers, segment, null, tx2)
742742
})
743743

744744
assert.equal(segment.catId, '6789#app')
@@ -764,7 +764,7 @@ test('TransactionShim', async function (t) {
764764
assert.ok(!segment.catTransaction)
765765
assert.ok(!segment.getAttributes().transaction_guid)
766766

767-
shim.handleMqTracingHeaders(headers, null, tx)
767+
shim.handleMqTracingHeaders(headers, null, null, tx)
768768

769769
assert.ok(!segment.catId)
770770
assert.ok(!segment.catTransaction)

0 commit comments

Comments
 (0)