Skip to content

Commit

Permalink
chore(deps-dev): bump mysql2 from 3.11.4 to 3.11.5 (#4334)
Browse files Browse the repository at this point in the history
Add instrumentation for the new BaseConnection class.
  • Loading branch information
dependabot[bot] authored Dec 6, 2024
1 parent 03a5f2f commit 3e615aa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
18 changes: 16 additions & 2 deletions lib/instrumentation/modules/mysql2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

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

0 comments on commit 3e615aa

Please sign in to comment.