From 1ecc763dad5f6ba6872b908857d904368d4b0c02 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Tue, 16 Nov 2021 14:30:13 -0800 Subject: [PATCH] fix: drop no-longer-necessary half-disabling of instrumentations When disableInstrumentations support was added in #353 it only half-disabled these instrumentations, briefly mentioning "continuation patches". I believe this was about user-land callback queue handling that should no longer be necessary after run-context and #2430 work. --- lib/instrumentation/modules/ioredis.js | 3 +-- lib/instrumentation/modules/mysql.js | 5 ++--- lib/instrumentation/modules/pg.js | 9 ++++----- lib/instrumentation/modules/redis.js | 5 +++-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/instrumentation/modules/ioredis.js b/lib/instrumentation/modules/ioredis.js index e906fc9e3f..e60c7452bc 100644 --- a/lib/instrumentation/modules/ioredis.js +++ b/lib/instrumentation/modules/ioredis.js @@ -7,6 +7,7 @@ var shimmer = require('../shimmer') var spanSym = Symbol('elasticAPMSpan') module.exports = function (ioredis, agent, { version, enabled }) { + if (!enabled) return ioredis if (!semver.satisfies(version, '>=2.0.0 <5.0.0')) { agent.logger.debug('ioredis version %s not supported - aborting...', version) return ioredis @@ -15,8 +16,6 @@ module.exports = function (ioredis, agent, { version, enabled }) { agent.logger.debug('shimming ioredis.Command.prototype.initPromise') shimmer.wrap(ioredis.Command && ioredis.Command.prototype, 'initPromise', wrapInitPromise) - if (!enabled) return ioredis - agent.logger.debug('shimming ioredis.prototype.sendCommand') shimmer.wrap(ioredis.prototype, 'sendCommand', wrapSendCommand) diff --git a/lib/instrumentation/modules/mysql.js b/lib/instrumentation/modules/mysql.js index d473883033..98d410189d 100644 --- a/lib/instrumentation/modules/mysql.js +++ b/lib/instrumentation/modules/mysql.js @@ -10,6 +10,7 @@ var symbols = require('../../symbols') var { getDBDestination } = require('../context') module.exports = function (mysql, agent, { version, enabled }) { + if (!enabled) return mysql if (!semver.satisfies(version, '^2.0.0')) { agent.logger.debug('mysql version %s not supported - aborting...', version) return mysql @@ -21,8 +22,6 @@ module.exports = function (mysql, agent, { version, enabled }) { agent.logger.debug('shimming mysql.createPoolCluster') shimmer.wrap(mysql, 'createPoolCluster', wrapCreatePoolCluster) - if (!enabled) return mysql - agent.logger.debug('shimming mysql.createConnection') shimmer.wrap(mysql, 'createConnection', wrapCreateConnection) @@ -75,7 +74,7 @@ module.exports = function (mysql, agent, { version, enabled }) { if (typeof cb === 'function') { arguments[0] = agent._instrumentation.bindFunction(function wrapedCallback (err, connection) { // eslint-disable-line handle-callback-err - if (connection && enabled) wrapQueryable(connection, 'getConnection() > connection', agent) + if (connection) wrapQueryable(connection, 'getConnection() > connection', agent) return cb.apply(this, arguments) }) } diff --git a/lib/instrumentation/modules/pg.js b/lib/instrumentation/modules/pg.js index 5fed898176..2ed3da039d 100644 --- a/lib/instrumentation/modules/pg.js +++ b/lib/instrumentation/modules/pg.js @@ -10,12 +10,13 @@ var symbols = require('../../symbols') var { getDBDestination } = require('../context') module.exports = function (pg, agent, { version, enabled }) { + if (!enabled) return pg if (!semver.satisfies(version, '>=4.0.0 <9.0.0')) { agent.logger.debug('pg version %s not supported - aborting...', version) return pg } - patchClient(pg.Client, 'pg.Client', agent, enabled) + patchClient(pg.Client, 'pg.Client', agent) // Trying to access the pg.native getter will trigger and log the warning // "Cannot find module 'pg-native'" to STDERR if the module isn't installed. @@ -29,7 +30,7 @@ module.exports = function (pg, agent, { version, enabled }) { pg.__defineGetter__('native', function () { var native = getter() if (native && native.Client) { - patchClient(native.Client, 'pg.native.Client', agent, enabled) + patchClient(native.Client, 'pg.native.Client', agent) } return native }) @@ -38,9 +39,7 @@ module.exports = function (pg, agent, { version, enabled }) { return pg } -function patchClient (Client, klass, agent, enabled) { - if (!enabled) return - +function patchClient (Client, klass, agent) { agent.logger.debug('shimming %s.prototype.query', klass) shimmer.wrap(Client.prototype, 'query', wrapQuery) diff --git a/lib/instrumentation/modules/redis.js b/lib/instrumentation/modules/redis.js index 54dfa3fa09..7da5c733d0 100644 --- a/lib/instrumentation/modules/redis.js +++ b/lib/instrumentation/modules/redis.js @@ -6,6 +6,7 @@ var shimmer = require('../shimmer') var { getDBDestination } = require('../context') module.exports = function (redis, agent, { version, enabled }) { + if (!enabled) return redis if (!semver.satisfies(version, '>=2.0.0 <4.0.0')) { agent.logger.debug('redis version %s not supported - aborting...', version) return redis @@ -43,7 +44,7 @@ module.exports = function (redis, agent, { version, enabled }) { function wrapInternalSendCommand (original) { return function wrappedInternalSendCommand (commandObj) { - var span = enabled && agent.startSpan(null, 'cache', 'redis') + var span = agent.startSpan(null, 'cache', 'redis') var id = span && span.transaction.id var command = commandObj && commandObj.command @@ -71,7 +72,7 @@ module.exports = function (redis, agent, { version, enabled }) { function wrapSendCommand (original) { return function wrappedSendCommand (command) { - var span = enabled && agent.startSpan(null, 'cache', 'redis') + var span = agent.startSpan(null, 'cache', 'redis') var id = span && span.transaction.id var args = Array.prototype.slice.call(arguments)