Skip to content

Commit

Permalink
feat(mongodb): add support for v5
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDeconinck committed May 11, 2023
1 parent 79cd677 commit c4efc68
Show file tree
Hide file tree
Showing 6 changed files with 581 additions and 8 deletions.
4 changes: 3 additions & 1 deletion plugins/node/opentelemetry-instrumentation-mongodb/.tav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ mongodb:
- versions: ">=3.3 <4"
commands: npm run test
- versions: ">=4 <5"
commands: npm run test-new-versions
commands: npm run test-v4
- versions: ">=5 <6"
commands: npm run test-v5

# Fix missing `contrib-test-utils` package
pretest: npm run --prefix ../../../ lerna:link
11 changes: 6 additions & 5 deletions plugins/node/opentelemetry-instrumentation-mongodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"scripts": {
"docker:start": "docker run -e MONGODB_DB=opentelemetry-tests -e MONGODB_PORT=27017 -e MONGODB_HOST=127.0.0.1 -p 27017:27017 --rm mongo",
"test": "nyc ts-mocha -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/**/mongodb-v3.test.ts'",
"test-new-versions": "nyc ts-mocha -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/**mongodb-v4.test.ts'",
"test-v4": "nyc ts-mocha -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/**/mongodb-v4.test.ts'",
"test-v5": "nyc ts-mocha -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/**/mongodb-v5.test.ts'",
"test-all-versions": "tav",
"tdd": "npm run test -- --watch-extensions ts --watch",
"clean": "rimraf build/*",
Expand Down Expand Up @@ -51,16 +52,16 @@
},
"devDependencies": {
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/contrib-test-utils": "^0.33.2",
"@opentelemetry/context-async-hooks": "^1.8.0",
"@opentelemetry/contrib-test-utils": "^0.33.2",
"@opentelemetry/sdk-trace-base": "^1.8.0",
"@opentelemetry/sdk-trace-node": "^1.8.0",
"@types/bson": "4.0.5",
"@types/mocha": "7.0.2",
"@types/mongodb": "3.6.20",
"@types/node": "18.11.7",
"mocha": "7.2.0",
"mongodb": "3.6.11",
"@types/mongodb": "3.6.20",
"@types/bson": "4.0.5",
"nyc": "15.1.0",
"rimraf": "4.2.0",
"test-all-versions": "5.0.1",
Expand All @@ -72,4 +73,4 @@
"@opentelemetry/semantic-conventions": "^1.0.0"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mongodb#readme"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ export class MongoDBInstrumentation extends InstrumentationBase {
),
]
),
new InstrumentationNodeModuleDefinition<any>(
'mongodb',
['5.*'],
undefined,
undefined,
[
new InstrumentationNodeModuleFile<V4Connection>(
'mongodb/lib/cmap/connection.js',
['5.*'],
v4Patch,
v4Unpatch
),
]
),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('MongoDBInstrumentation', () => {
}
// Non traced insertion of basic data to perform tests
const insertData = [{ a: 1 }, { a: 2 }, { a: 3 }];
collection.insertMany(insertData, (err, result) => {
collection.insertMany(insertData, (err: any, result: any) => {
resetMemoryExporter();
done();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('MongoDBInstrumentation', () => {
}
// Non traced insertion of basic data to perform tests
const insertData = [{ a: 1 }, { a: 2 }, { a: 3 }];
collection.insertMany(insertData, (err, result) => {
collection.insertMany(insertData, (err: any, result: any) => {
resetMemoryExporter();
done();
});
Expand Down
Loading

0 comments on commit c4efc68

Please sign in to comment.