Skip to content

Commit 90a9dcc

Browse files
committed
Add mongodb v3 tests
1 parent ff03fc3 commit 90a9dcc

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v3.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,49 @@ describe('MongoDBInstrumentation-Tracing-v3', () => {
669669
});
670670
});
671671

672+
describe('requireParentSpan', () => {
673+
// Resetting the behavior to default to avoid flakes in other tests
674+
beforeEach(() => {
675+
instrumentation.setConfig();
676+
});
677+
678+
afterEach(() => {
679+
instrumentation.setConfig();
680+
});
681+
682+
it('should not create spans without parent span when requireParentSpan is explicitly set to true', done => {
683+
context.with(trace.deleteSpan(context.active()), () => {
684+
collection
685+
.insertOne({ a: 1 })
686+
.then(() => {
687+
assert.strictEqual(getTestSpans().length, 0);
688+
done();
689+
})
690+
.catch(err => {
691+
done(err);
692+
});
693+
});
694+
});
695+
696+
it('should create spans without parent span when requireParentSpan is false', done => {
697+
instrumentation.setConfig({
698+
requireParentSpan: false,
699+
});
700+
701+
context.with(trace.deleteSpan(context.active()), () => {
702+
collection
703+
.insertOne({ a: 1 })
704+
.then(() => {
705+
assert.strictEqual(getTestSpans().length, 1);
706+
done();
707+
})
708+
.catch(err => {
709+
done(err);
710+
});
711+
});
712+
});
713+
});
714+
672715
/** Should intercept command */
673716
describe('Removing Instrumentation', () => {
674717
it('should unpatch plugin', () => {

0 commit comments

Comments
 (0)