From aaa0c4742e55b3626f7f173c4f5f1aeb79439486 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 00:27:36 +0000 Subject: [PATCH 1/4] chore(deps-dev): bump mysql2 from 3.11.4 to 3.11.5 Bumps [mysql2](https://github.com/sidorares/node-mysql2) from 3.11.4 to 3.11.5. - [Release notes](https://github.com/sidorares/node-mysql2/releases) - [Changelog](https://github.com/sidorares/node-mysql2/blob/master/Changelog.md) - [Commits](https://github.com/sidorares/node-mysql2/compare/v3.11.4...v3.11.5) --- updated-dependencies: - dependency-name: mysql2 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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", From 2add167b424599ffdd514e84c3f4f6e38be89af8 Mon Sep 17 00:00:00 2001 From: David Luna Date: Wed, 4 Dec 2024 09:58:46 +0100 Subject: [PATCH 2/4] fix(mysql2): fix instrumentation for mysql2@3.11.5 --- lib/instrumentation/modules/mysql2.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/instrumentation/modules/mysql2.js b/lib/instrumentation/modules/mysql2.js index b75d663b03..f810436e4f 100644 --- a/lib/instrumentation/modules/mysql2.js +++ b/lib/instrumentation/modules/mysql2.js @@ -27,8 +27,19 @@ 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 shouldPatchBase = typeof baseClass.prototype === 'object'; + + if (shouldPatchBase) { + shimmer.wrap(baseClass.prototype, 'query', wrapQuery); + shimmer.wrap(baseClass.prototype, 'execute', wrapQuery); + } else { + shimmer.wrap(mysql2.Connection.prototype, 'query', wrapQuery); + shimmer.wrap(mysql2.Connection.prototype, 'execute', wrapQuery); + } return mysql2; From 7f8500b902b612213ee0896b848acbec005b1996 Mon Sep 17 00:00:00 2001 From: David Luna Date: Wed, 4 Dec 2024 18:38:32 +0100 Subject: [PATCH 3/4] chore(mysl2): improve how to resolve the prototype --- lib/instrumentation/modules/mysql2.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/instrumentation/modules/mysql2.js b/lib/instrumentation/modules/mysql2.js index f810436e4f..b7e6bf6fc5 100644 --- a/lib/instrumentation/modules/mysql2.js +++ b/lib/instrumentation/modules/mysql2.js @@ -31,7 +31,9 @@ module.exports = function (mysql2, agent, { version, enabled }) { // 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 shouldPatchBase = typeof baseClass.prototype === 'object'; + const hasQuery = typeof baseClass.prototype?.query === 'function'; + const hasExec = typeof baseClass.prototype?.exec === 'function'; + const shouldPatchBase = hasQuery && hasExec; if (shouldPatchBase) { shimmer.wrap(baseClass.prototype, 'query', wrapQuery); From 3ea42433bd8772db6e8922b465bcd3ce12e159fc Mon Sep 17 00:00:00 2001 From: David Luna Date: Thu, 5 Dec 2024 11:20:35 +0100 Subject: [PATCH 4/4] chore(mysl2): fix last commit --- lib/instrumentation/modules/mysql2.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/instrumentation/modules/mysql2.js b/lib/instrumentation/modules/mysql2.js index b7e6bf6fc5..46f031fb23 100644 --- a/lib/instrumentation/modules/mysql2.js +++ b/lib/instrumentation/modules/mysql2.js @@ -31,13 +31,14 @@ module.exports = function (mysql2, agent, { version, enabled }) { // 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 hasQuery = typeof baseClass.prototype?.query === 'function'; - const hasExec = typeof baseClass.prototype?.exec === 'function'; + const baseProto = baseClass.prototype; + const hasQuery = typeof baseProto?.query === 'function'; + const hasExec = typeof baseProto?.execute === 'function'; const shouldPatchBase = hasQuery && hasExec; if (shouldPatchBase) { - shimmer.wrap(baseClass.prototype, 'query', wrapQuery); - shimmer.wrap(baseClass.prototype, 'execute', wrapQuery); + 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);