-
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.
chore(deps-dev): bump mysql2 from 3.11.4 to 3.11.5 (#4334)
Add instrumentation for the new BaseConnection class.
- Loading branch information
1 parent
03a5f2f
commit 3e615aa
Showing
2 changed files
with
22 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,22 @@ module.exports = function (mysql2, agent, { version, enabled }) { | |
|
||
var ins = agent._instrumentation; | ||
|
||
shimmer.wrap(mysql2.Connection.prototype, 'query', wrapQuery); | ||
shimmer.wrap(mysql2.Connection.prototype, 'execute', wrapQuery); | ||
// [email protected] added BaseConnection class which is extended by Connection | ||
// but is not in the public API so we need to extract it via prototype chain | ||
// ref: https://github.com/sidorares/node-mysql2/pull/3081 | ||
const baseClass = Object.getPrototypeOf(mysql2.Connection); | ||
const baseProto = baseClass.prototype; | ||
const hasQuery = typeof baseProto?.query === 'function'; | ||
const hasExec = typeof baseProto?.execute === 'function'; | ||
const shouldPatchBase = hasQuery && hasExec; | ||
|
||
if (shouldPatchBase) { | ||
shimmer.wrap(baseProto, 'query', wrapQuery); | ||
shimmer.wrap(baseProto, 'execute', wrapQuery); | ||
} else { | ||
shimmer.wrap(mysql2.Connection.prototype, 'query', wrapQuery); | ||
shimmer.wrap(mysql2.Connection.prototype, 'execute', wrapQuery); | ||
} | ||
|
||
return mysql2; | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.