Skip to content

Commit e41a49a

Browse files
committed
test fix
1 parent d9a3a8e commit e41a49a

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

packages/datadog-plugin-mongodb-core/test/core.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,10 @@ describe('Plugin', () => {
662662

663663
it('DBM propagation should inject full mode with traceparent as comment', done => {
664664
agent
665-
.assertSomeTraces(traces => {
666-
const span = traces[0][0]
665+
.assertFirstTraceSpan(span => {
667666
const traceId = span.meta['_dd.p.tid'] + span.trace_id.toString(16).padStart(16, '0')
668667
const spanId = span.span_id.toString(16).padStart(16, '0')
668+
const samplingPriotrity = span.metrics._sampling_priority_v1 > 0 ? '01' : '00'
669669

670670
assert.strictEqual(startSpy.called, true)
671671
const { comment } = startSpy.getCall(0).args[0].ops
@@ -677,7 +677,7 @@ describe('Plugin', () => {
677677
`ddps='${encodeURIComponent(span.meta.service)}',` +
678678
`ddpv='${ddpv}',` +
679679
`ddprs='${encodeURIComponent(span.meta['peer.service'])}',` +
680-
`traceparent='00-${traceId}-${spanId}-01'`
680+
`traceparent='00-${traceId}-${spanId}-${samplingPriotrity}'`
681681
)
682682
})
683683
.then(done)

packages/datadog-plugin-mongodb-core/test/mongodb.spec.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe('Plugin', () => {
5151
let db
5252
let BSON
5353
let startSpy
54+
let injectCommentSpy
5455
let usesDelete
5556

5657
describe('mongodb-core', () => {
@@ -564,9 +565,7 @@ describe('Plugin', () => {
564565

565566
describe('with dbmPropagationMode full', () => {
566567
before(() => {
567-
return agent.load('mongodb-core', {
568-
dbmPropagationMode: 'full'
569-
})
568+
return agent.load('mongodb-core', { dbmPropagationMode: 'full' })
570569
})
571570

572571
after(() => {
@@ -579,21 +578,25 @@ describe('Plugin', () => {
579578
collection = db.collection(collectionName)
580579

581580
startSpy = sinon.spy(MongodbCorePlugin.prototype, 'start')
581+
injectCommentSpy = sinon.spy(MongodbCorePlugin.prototype, 'injectDbmComment')
582582
})
583583

584584
afterEach(() => {
585585
startSpy?.restore()
586+
injectCommentSpy?.restore()
586587
})
587588

588589
it('DBM propagation should inject full mode with traceparent as comment', done => {
589590
agent
590-
.assertSomeTraces(traces => {
591-
const span = traces[0][0]
591+
.assertFirstTraceSpan(span => {
592592
const traceId = span.meta['_dd.p.tid'] + span.trace_id.toString(16).padStart(16, '0')
593593
const spanId = span.span_id.toString(16).padStart(16, '0')
594+
const samplingPriotrity = span.metrics._sampling_priority_v1 > 0 ? '01' : '00'
594595

595596
assert.strictEqual(startSpy.called, true)
596-
const { comment } = startSpy.getCall(0).args[0].ops
597+
assert.strictEqual(injectCommentSpy.called, true)
598+
599+
const comment = injectCommentSpy.getCall(0).returnValue
597600
assert.strictEqual(comment,
598601
`dddb='${encodeURIComponent(span.meta['db.name'])}',` +
599602
'dddbs=\'test-mongodb\',' +
@@ -602,7 +605,7 @@ describe('Plugin', () => {
602605
`ddps='${encodeURIComponent(span.meta.service)}',` +
603606
`ddpv='${ddpv}',` +
604607
`ddprs='${encodeURIComponent(span.meta['peer.service'])}',` +
605-
`traceparent='00-${traceId}-${spanId}-01'`
608+
`traceparent='00-${traceId}-${spanId}-${samplingPriotrity}'`
606609
)
607610
})
608611
.then(done)

0 commit comments

Comments
 (0)