diff --git a/lib/instrumentation/modules/mysql2.js b/lib/instrumentation/modules/mysql2.js index b75d663b03..46f031fb23 100644 --- a/lib/instrumentation/modules/mysql2.js +++ b/lib/instrumentation/modules/mysql2.js @@ -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); + // mysql2@3.11.5 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; diff --git a/package-lock.json b/package-lock.json index 889d9317ba..f8f3b669c9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12581,9 +12581,9 @@ } }, "node_modules/mysql2": { - "version": "3.11.4", - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.11.4.tgz", - "integrity": "sha512-Z2o3tY4Z8EvSRDwknaC40MdZ3+m0sKbpnXrShQLdxPrAvcNli7jLrD2Zd2IzsRMw4eK9Yle500FDmlkIqp+krg==", + "version": "3.11.5", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.11.5.tgz", + "integrity": "sha512-0XFu8rUmFN9vC0ME36iBvCUObftiMHItrYFhlCRvFWbLgpNqtC4Br/NmZX1HNCszxT0GGy5QtP+k3Q3eCJPaYA==", "dev": true, "dependencies": { "aws-ssl-profiles": "^1.1.1", @@ -26168,9 +26168,9 @@ } }, "mysql2": { - "version": "3.11.4", - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.11.4.tgz", - "integrity": "sha512-Z2o3tY4Z8EvSRDwknaC40MdZ3+m0sKbpnXrShQLdxPrAvcNli7jLrD2Zd2IzsRMw4eK9Yle500FDmlkIqp+krg==", + "version": "3.11.5", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.11.5.tgz", + "integrity": "sha512-0XFu8rUmFN9vC0ME36iBvCUObftiMHItrYFhlCRvFWbLgpNqtC4Br/NmZX1HNCszxT0GGy5QtP+k3Q3eCJPaYA==", "dev": true, "requires": { "aws-ssl-profiles": "^1.1.1",