Skip to content

Commit 9e985ff

Browse files
authored
Fix bug where MongoDB comment is improperly set to null when dbmPropagationMode is disabled (#5353)
1 parent 974cc39 commit 9e985ff

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

packages/datadog-plugin-mongodb-core/src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class MongodbCorePlugin extends DatabasePlugin {
2525
'out.port': options.port
2626
}
2727
})
28-
ops.comment = this.injectDbmComment(span, ops.comment, service)
28+
const comment = this.injectDbmComment(span, ops.comment, service)
29+
if (comment) {
30+
ops.comment = comment
31+
}
2932
}
3033

3134
getPeerService (tags) {

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

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,113 @@ describe('Plugin', () => {
403403
)
404404
})
405405

406+
describe('with dbmPropagationMode disabled by default', () => {
407+
before(() => {
408+
return agent.load('mongodb-core')
409+
})
410+
411+
after(() => {
412+
return agent.close({ ritmReset: false })
413+
})
414+
415+
beforeEach(done => {
416+
const Server = getServer()
417+
418+
server = new Server({
419+
host: '127.0.0.1',
420+
port: 27017,
421+
reconnect: false
422+
})
423+
424+
server.on('connect', () => done())
425+
server.on('error', done)
426+
427+
server.connect()
428+
429+
startSpy = sinon.spy(MongodbCorePlugin.prototype, 'start')
430+
})
431+
432+
afterEach(() => {
433+
startSpy?.restore()
434+
})
435+
436+
it('DBM propagation should not inject comment', done => {
437+
agent
438+
.use(traces => {
439+
expect(startSpy.called).to.be.true
440+
const ops = startSpy.getCall(0).args[0].ops
441+
expect(ops).to.not.have.property('comment')
442+
})
443+
.then(done)
444+
.catch(done)
445+
446+
server.insert(`test.${collection}`, [{ a: 1 }], () => {})
447+
})
448+
})
449+
450+
describe('with dbmPropagationMode explicitly disabled', () => {
451+
before(() => {
452+
return agent.load('mongodb-core', { dbmPropagationMode: 'disabled' })
453+
})
454+
455+
after(() => {
456+
return agent.close({ ritmReset: false })
457+
})
458+
459+
beforeEach(done => {
460+
const Server = getServer()
461+
462+
server = new Server({
463+
host: '127.0.0.1',
464+
port: 27017,
465+
reconnect: false
466+
})
467+
468+
server.on('connect', () => done())
469+
server.on('error', done)
470+
471+
server.connect()
472+
473+
startSpy = sinon.spy(MongodbCorePlugin.prototype, 'start')
474+
})
475+
476+
afterEach(() => {
477+
startSpy?.restore()
478+
})
479+
480+
it('DBM propagation should not inject comment', done => {
481+
agent
482+
.use(traces => {
483+
expect(startSpy.called).to.be.true
484+
const { comment } = startSpy.getCall(0).args[0].ops
485+
expect(comment).to.be.undefined
486+
})
487+
.then(done)
488+
.catch(done)
489+
490+
server.insert(`test.${collection}`, [{ a: 1 }], () => {})
491+
})
492+
493+
it('DBM propagation should not alter existing comment', done => {
494+
agent
495+
.use(traces => {
496+
expect(startSpy.called).to.be.true
497+
const { comment } = startSpy.getCall(0).args[0].ops
498+
expect(comment).to.equal('test comment')
499+
})
500+
.then(done)
501+
.catch(done)
502+
503+
server.command(`test.${collection}`, {
504+
find: `test.${collection}`,
505+
query: {
506+
_id: Buffer.from('1234')
507+
},
508+
comment: 'test comment'
509+
}, () => {})
510+
})
511+
})
512+
406513
describe('with dbmPropagationMode service', () => {
407514
before(() => {
408515
return agent.load('mongodb-core', { dbmPropagationMode: 'service' })

0 commit comments

Comments
 (0)