Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading