Skip to content

Commit

Permalink
fix: drop no-longer-necessary half-disabling of instrumentations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
trentm committed Nov 16, 2021
1 parent bf76048 commit 1ecc763
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
3 changes: 1 addition & 2 deletions lib/instrumentation/modules/ioredis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions lib/instrumentation/modules/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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)
})
}
Expand Down
9 changes: 4 additions & 5 deletions lib/instrumentation/modules/pg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
})
Expand All @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions lib/instrumentation/modules/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 1ecc763

Please sign in to comment.