Skip to content

Commit f172a56

Browse files
feat(instrumentation-mongodb): added support for mongodb v7
1 parent 53a6c94 commit f172a56

File tree

7 files changed

+879
-11
lines changed

7 files changed

+879
-11
lines changed

package-lock.json

Lines changed: 90 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/instrumentation-mongodb/.tav.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ mongodb:
2222
mode: max-7
2323
node: '>=15.0.0'
2424
commands: npm run test-v5-v6
25+
- versions:
26+
include: ">=7 <8"
27+
mode: max-7
28+
node: '>=20.19.0'
29+
commands: npm run test-v7

packages/instrumentation-mongodb/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ npm install --save @opentelemetry/instrumentation-mongodb
1717

1818
### Supported Versions
1919

20-
- [`mongodb`](https://www.npmjs.com/package/mongodb) version `>=3.3.0 <7`
20+
- [`mongodb`](https://www.npmjs.com/package/mongodb) version `>=3.3.0 <8`
2121

2222
## Usage
2323

packages/instrumentation-mongodb/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/instrumentation-mongodb",
1717
"compile": "tsc -p .",
1818
"prepublishOnly": "npm run compile",
19-
"tdd": "npm run test-v5-v6-run -- --watch-extensions ts --watch",
20-
"test": "npm run test-v5-v6 && npm run test-unit",
19+
"tdd": "npm run test-v7 -- --watch-extensions ts --watch",
20+
"test": "npm run test-v7 && npm run test-unit",
2121
"test-unit": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/**/unit/*.test.ts'",
2222
"test-v3": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/**/mongodb-v3.test.ts'",
23-
"test-v4": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v4.test.ts'",
24-
"test-v5-v6": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v5-v6.test.ts'",
23+
"test-v4": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6-v7.metrics.test.ts' 'test/**/mongodb-v4.test.ts'",
24+
"test-v5-v6": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6-v7.metrics.test.ts' 'test/**/mongodb-v5-v6.test.ts'",
25+
"test-v7": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6-v7.metrics.test.ts' 'test/**/mongodb-v7.test.ts'",
2526
"test:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm test",
2627
"test-all-versions": "tav",
2728
"test-all-versions:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm run test-all-versions",
@@ -61,7 +62,7 @@
6162
"@opentelemetry/sdk-trace-base": "^2.0.0",
6263
"@opentelemetry/sdk-trace-node": "^2.0.0",
6364
"@types/bson": "4.0.5",
64-
"mongodb": "6.19.0"
65+
"mongodb": "7.0.0"
6566
},
6667
"dependencies": {
6768
"@opentelemetry/instrumentation": "^0.208.0"

packages/instrumentation-mongodb/src/instrumentation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class MongoDBInstrumentation extends InstrumentationBase<MongoDBInstrumen
118118
),
119119
new InstrumentationNodeModuleDefinition(
120120
'mongodb',
121-
['>=4.0.0 <7'],
121+
['>=4.0.0 <8'],
122122
undefined,
123123
undefined,
124124
[
@@ -130,7 +130,7 @@ export class MongoDBInstrumentation extends InstrumentationBase<MongoDBInstrumen
130130
),
131131
new InstrumentationNodeModuleFile(
132132
'mongodb/lib/cmap/connection.js',
133-
['>=6.4.0 <7'],
133+
['>=6.4.0 <8'],
134134
v4PatchConnectionPromise,
135135
v4UnpatchConnection
136136
),
@@ -142,13 +142,13 @@ export class MongoDBInstrumentation extends InstrumentationBase<MongoDBInstrumen
142142
),
143143
new InstrumentationNodeModuleFile(
144144
'mongodb/lib/cmap/connect.js',
145-
['>=4.0.0 <7'],
145+
['>=4.0.0 <8'],
146146
v4PatchConnect,
147147
v4UnpatchConnect
148148
),
149149
new InstrumentationNodeModuleFile(
150150
'mongodb/lib/sessions.js',
151-
['>=4.0.0 <7'],
151+
['>=4.0.0 <8'],
152152
v4PatchSessions,
153153
v4UnpatchSessions
154154
),

packages/instrumentation-mongodb/test/mongodb-v4-v5-v6.metrics.test.ts renamed to packages/instrumentation-mongodb/test/mongodb-v4-v5-v6-v7.metrics.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const instrumentation = registerInstrumentationTesting(
4848
import { accessCollection, DEFAULT_MONGO_HOST } from './utils';
4949
import type { MongoClient, Collection } from 'mongodb';
5050
import * as assert from 'assert';
51+
import * as semver from 'semver';
5152

5253
async function waitForNumberOfExports(
5354
exporter: InMemoryMetricExporter,
@@ -77,6 +78,14 @@ describe('MongoDBInstrumentation-Metrics', () => {
7778
shouldTest = false;
7879
}
7980

81+
// MongoDB v7 requires Node.js >= 20.19.0
82+
if (!semver.satisfies(process.version, '>=20.19.0')) {
83+
console.log(
84+
`Skipping mongodb v7 tests. Node.js ${process.version} does not meet minimum requirement of >=20.19.0`
85+
);
86+
shouldTest = false;
87+
}
88+
8089
const HOST = process.env.MONGODB_HOST || DEFAULT_MONGO_HOST;
8190
const PORT = process.env.MONGODB_PORT || 27017;
8291
const DB_NAME = process.env.MONGODB_DB || 'opentelemetry-tests-metrics';

0 commit comments

Comments
 (0)