function _wrapThen(then, name, useAllParams) {
    // Don't wrap non-functions.
    if (typeof then !== 'function' || then.name === '__NR_wrappedThen') {
      return then
    }

    // eslint-disable-next-line camelcase
    return function __NR_wrappedThen() {
      if (!(this instanceof Promise)) {
        return then.apply(this, arguments)
      }

      const segmentNamePrefix = 'Promise#' + name + ' '
      const thenSegment = agent.tracer.getSegment()
      const transaction = agent.tracer.getTransaction()
      const promise = this
      const ctx = { next: undefined, useAllParams, isWrapped: false, segmentNamePrefix }

      // Wrap up the arguments and execute the real then.
      const args = [].map.call(arguments, wrapHandler.bind(this, ctx))
      ctx.next = then.apply(this, args)

      // If we got a promise (which we should have), link the parent's context.
      if (!ctx.isWrapped && ctx.next instanceof Promise && ctx.next !== promise) {
        Contextualizer.link(promise, ctx.next, thenSegment, transaction)
      }
      return ctx.next
    }
  }
Creates a wrapper for promise chain extending methods.

@param {Function} then
 The function we are to wrap as a chain extender.
@param {string} name name of function being wrapped
@param {boolean} useAllParams
 When true, all parameters which are functions will be wrapped. Otherwise,
 only the last parameter will be wrapped.
@returns {Function} A wrapped version of the function.