Skip to content

Commit

Permalink
fix(instr-mongodb): fix instr to no longer break mongodb >=6.4.0 (#3897)
Browse files Browse the repository at this point in the history
* chore(deps-dev): bump mongodb from 6.3.0 to 6.4.0

Co-authored-by: Trent Mick <[email protected]>
  • Loading branch information
dependabot[bot] and trentm authored Mar 5, 2024
1 parent ec41c97 commit b83a75b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .tav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mongodb:
node: '>=14.20.1'
commands: node test/instrumentation/modules/mongodb/mongodb.test.js
- versions: '>=6 <7'
node: '>=15.0.0'
node: '>=16.20.1'
commands: node test/instrumentation/modules/mongodb/mongodb.test.js

# Bluebird is effectively deprecated (https://github.com/petkaantonov/bluebird#%EF%B8%8Fnote%EF%B8%8F).
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ See the <<upgrade-to-v4>> guide.
[float]
===== Bug fixes
* Fix instrumentation of mongodb to not break [email protected]. Mongodb v6.4.0
included changes that resulted in the APM agent's instrumentation breaking it.
({pull}3897[#3897])
[float]
===== Chores
Expand Down
11 changes: 6 additions & 5 deletions lib/instrumentation/modules/mongodb/lib/cmap/connection_pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ const semver = require('semver');

module.exports = (mod, agent, { version, enabled }) => {
if (!enabled) return mod;
if (!semver.satisfies(version, '>=3.3 <7.0')) {
agent.logger.debug(
'mongodb version %s not instrumented (mongodb <3.3 is instrumented via mongodb-core)',
version,
);
if (!semver.satisfies(version, '>=3.3 <6.4.0')) {
// - mongodb <3.3 is instrumented via mongodb-core
// - mongodb >=6.4.0 now longer requires ConnectionPool#checkOut to be
// patched to fix async context tracking. See discussion at
// https://github.com/elastic/apm-agent-nodejs/pull/3897
return mod;
}
agent.logger.debug('instrumenting mongodb ConnectionPool#checkOut');

if (mod.ConnectionPool) {
class ConnectionPoolTraced extends mod.ConnectionPool {
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/_is_mongodb_incompat.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function isMongodbIncompat() {
return msg;
}
} else if (semver.satisfies(mongodbVer, '>=6.0.0')) {
if (!semver.satisfies(nodeVer, '>=15.0.0')) {
if (!semver.satisfies(nodeVer, '>=16.20.1')) {
return msg;
}
}
Expand Down

0 comments on commit b83a75b

Please sign in to comment.