lib/instrumentation/modules/ioredis.js
function wrapInitPromise (original) {
    return function wrappedInitPromise () {
      var command = this
      var cb = this.callback

      if (typeof cb === 'function') {
        this.callback = agent._instrumentation.bindFunction(function wrappedCallback () {
          var span = command[spanSym]
          if (span && !span.ended) span.end()
          return cb.apply(this, arguments)
        })
      }

      return original.apply(this, arguments)
    }
  }
function wrapInitPromise (original) {
    return function wrappedInitPromise () {
      var command = this
      var cb = this.callback

      if (typeof cb === 'function') {
        this.callback = agent._instrumentation.bindFunction(function wrappedCallback () {
          var span = command[spanSym]
          if (span && !span.ended) span.end()
          return cb.apply(this, arguments)
        })
      }

      return original.apply(this, arguments)
    }
  }
function wrapInitPromise ( original ) { return function wrappedInitPromise ( ) { var command = this var cb = this . callback if ( typeof cb === 'function' ) { this . callback = agent . _instrumentation . bindFunction ( function wrappedCallback ( ) { var span = command [ spanSym ] if ( span && ! span . ended ) span . end ( ) return cb . apply ( this , arguments ) } ) } return original . apply ( this , arguments ) } }
wrap initPromise to allow us to get notified when the callback to a command is called. If we don't do this we will still get notified because we register a callback with command.promise.finally the wrappedSendCommand, but the finally call will not get fired until the tick after the command.callback have fired, so if the transaction is ended in the same tick as the call to command.callback, we'll lose the last span as it hasn't yet ended.
wrap initPromise to allow us to get notified when the callback to a command is called . If we don t do this we will still get notified because we register a callback with command . promise . finally the wrappedSendCommand but the finally call will not get fired until the tick after the command . callback have fired so if the transaction is ended in the same tick as the call to command . callback we ll lose the last span as it hasn t yet ended .