function wrapHandler(ctx, fn, i, arr) {
    if (
      typeof fn !== 'function' || // Not a function
      fn.name === '__NR_wrappedThenHandler' || // Already wrapped
      (!ctx.useAllParams && i !== arr.length - 1) // Don't want all and not last
    ) {
      ctx.isWrapped = fn && fn.name === '__NR_wrappedThenHandler'
      return fn
    }

    // eslint-disable-next-line camelcase
    return function __NR_wrappedThenHandler() {
      if (!ctx.next || !ctx.next[symbols.context]) {
        return fn.apply(this, arguments)
      }

      let promSegment = ctx.next[symbols.context].getSegment()
      const segmentName = ctx.segmentNamePrefix + (fn.name || ANONYMOUS)
      const transaction = ctx.next[symbols.context].getTransaction()
      const segment = _createSegment({ name: segmentName, parent: promSegment, transaction })
      if (segment && segment !== promSegment) {
        ctx.next[symbols.context].setSegment(segment)
        promSegment = segment
      }

      let context = agent.tracer.getContext()
      context = context.enterSegment({ transaction, segment: promSegment })

      let ret = null
      try {
        ret = agent.tracer.bindFunction(fn, context, true).apply(this, arguments)
      } finally {
        if (ret && typeof ret.then === 'function') {
          // eslint-disable-next-line sonarjs/no-dead-store
          ret = ctx.next[symbols.context].continue(ret)
        }
      }
      return ret
    }
  }
Wraps every function passed to .then

@param {object} ctx context to pass data from caller to callee and back
@param {Function} fn function reference
@param {number} i position of function in .then handler
@param {Array} arr all args passed to .then
@returns {Function} wraps every function pass to then