Skip to content

Commit 3e615aa

Browse files
chore(deps-dev): bump mysql2 from 3.11.4 to 3.11.5 (#4334)
Add instrumentation for the new BaseConnection class.
1 parent 03a5f2f commit 3e615aa

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

lib/instrumentation/modules/mysql2.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,22 @@ module.exports = function (mysql2, agent, { version, enabled }) {
2727

2828
var ins = agent._instrumentation;
2929

30-
shimmer.wrap(mysql2.Connection.prototype, 'query', wrapQuery);
31-
shimmer.wrap(mysql2.Connection.prototype, 'execute', wrapQuery);
30+
// [email protected] added BaseConnection class which is extended by Connection
31+
// but is not in the public API so we need to extract it via prototype chain
32+
// ref: https://github.com/sidorares/node-mysql2/pull/3081
33+
const baseClass = Object.getPrototypeOf(mysql2.Connection);
34+
const baseProto = baseClass.prototype;
35+
const hasQuery = typeof baseProto?.query === 'function';
36+
const hasExec = typeof baseProto?.execute === 'function';
37+
const shouldPatchBase = hasQuery && hasExec;
38+
39+
if (shouldPatchBase) {
40+
shimmer.wrap(baseProto, 'query', wrapQuery);
41+
shimmer.wrap(baseProto, 'execute', wrapQuery);
42+
} else {
43+
shimmer.wrap(mysql2.Connection.prototype, 'query', wrapQuery);
44+
shimmer.wrap(mysql2.Connection.prototype, 'execute', wrapQuery);
45+
}
3246

3347
return mysql2;
3448

package-lock.json

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)