Skip to content

Commit e1ee9b6

Browse files
committed
Lint and add a true test case.
1 parent 18e815f commit e1ee9b6

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,8 @@ export class MongoDBInstrumentation extends InstrumentationBase<MongoDBInstrumen
449449

450450
const hasNoParentSpan = currentSpan === undefined;
451451
const requireParentSpan = instrumentation.getConfig().requireParentSpan;
452-
const skipInstrumentation = requireParentSpan === true && hasNoParentSpan;
452+
const skipInstrumentation =
453+
requireParentSpan === true && hasNoParentSpan;
453454

454455
const resultHandler =
455456
typeof options === 'function' ? options : callback;
@@ -506,7 +507,8 @@ export class MongoDBInstrumentation extends InstrumentationBase<MongoDBInstrumen
506507

507508
const hasNoParentSpan = currentSpan === undefined;
508509
const requireParentSpan = instrumentation.getConfig().requireParentSpan;
509-
const skipInstrumentation = requireParentSpan === true && hasNoParentSpan;
510+
const skipInstrumentation =
511+
requireParentSpan === true && hasNoParentSpan;
510512

511513
const resultHandler =
512514
typeof options === 'function' ? options : callback;
@@ -655,7 +657,8 @@ export class MongoDBInstrumentation extends InstrumentationBase<MongoDBInstrumen
655657

656658
const hasNoParentSpan = currentSpan === undefined;
657659
const requireParentSpan = instrumentation.getConfig().requireParentSpan;
658-
const skipInstrumentation = requireParentSpan === true && hasNoParentSpan;
660+
const skipInstrumentation =
661+
requireParentSpan === true && hasNoParentSpan;
659662

660663
const resultHandler =
661664
typeof options === 'function' ? options : callback;
@@ -725,7 +728,8 @@ export class MongoDBInstrumentation extends InstrumentationBase<MongoDBInstrumen
725728

726729
const hasNoParentSpan = currentSpan === undefined;
727730
const requireParentSpan = instrumentation.getConfig().requireParentSpan;
728-
const skipInstrumentation = requireParentSpan === true && hasNoParentSpan;
731+
const skipInstrumentation =
732+
requireParentSpan === true && hasNoParentSpan;
729733

730734
const resultHandler =
731735
typeof options === 'function' ? options : callback;

plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v5-v6.test.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,22 @@ describe('MongoDBInstrumentation-Tracing-v5', () => {
653653
});
654654

655655
describe('requireParentSpan', () => {
656+
it('should not create spans without parent span when requireParentSpan is explicitly set to true', done => {
657+
create({
658+
requireParentSpan: true,
659+
});
660+
661+
collection
662+
.insertOne({ a: 1 })
663+
.then(() => {
664+
assert.strictEqual(getTestSpans().length, 0);
665+
done();
666+
})
667+
.catch(err => {
668+
done(err);
669+
});
670+
});
671+
656672
it('should create spans without parent span when requireParentSpan is false', done => {
657673
create({
658674
requireParentSpan: false,
@@ -669,7 +685,7 @@ describe('MongoDBInstrumentation-Tracing-v5', () => {
669685
});
670686
});
671687

672-
it('should not create spans without parent span when requireParentSpan is set to false by setConfig', done => {
688+
it('should create spans without parent span when requireParentSpan is set to false by setConfig', done => {
673689
create();
674690

675691
instrumentation.setConfig({
@@ -686,7 +702,7 @@ describe('MongoDBInstrumentation-Tracing-v5', () => {
686702
done(err);
687703
});
688704
});
689-
})
705+
});
690706

691707
/** Should intercept command */
692708
describe('Removing Instrumentation', () => {

0 commit comments

Comments
 (0)