-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add mongodb connection pool patch (#3665)
- Loading branch information
1 parent
d968537
commit 517174f
Showing
10 changed files
with
1,046 additions
and
376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
lib/instrumentation/modules/mongodb/lib/cmap/connection_pool.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and other contributors where applicable. | ||
* Licensed under the BSD 2-Clause License; you may not use this file except in | ||
* compliance with the BSD 2-Clause License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const { AsyncResource } = require('async_hooks'); | ||
|
||
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, | ||
); | ||
return mod; | ||
} | ||
|
||
if (mod.ConnectionPool) { | ||
class ConnectionPoolTraced extends mod.ConnectionPool { | ||
checkOut(callback) { | ||
return super.checkOut(AsyncResource.bind(callback)); | ||
} | ||
} | ||
|
||
Object.defineProperty(mod, 'ConnectionPool', { | ||
enumerable: true, | ||
get: function () { | ||
return ConnectionPoolTraced; | ||
}, | ||
}); | ||
|
||
return mod; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.