function _makeNestedTransWrapper(shim, func, name, spec) {
  return function nestedTransactionWrapper() {
    if (!shim.agent.canCollectData()) {
      return func.apply(this, arguments)
    }

    let context = shim.tracer.getContext()
    let transaction = shim.tracer.getTransaction()

    // Only create a new transaction if we either do not have a current
    // transaction _or_ the current transaction is not of the type we want.
    if (!transaction || spec.type !== transaction?.type) {
      shim.logger.trace('Creating new nested %s transaction for %s', spec.type, name)
      transaction = new Transaction(shim.agent)
      transaction.type = spec.type
      context = context.enterTransaction(transaction)
    }

    return shim.applyContext({ func, context, full: false, boundThis: this, args: arguments })
  }
}
Creates a function that binds transactions to the execution of the function.

The created transaction may be nested within an existing transaction if
`spec.type` is not the same as the current transaction's type.

@private
@param {Shim} shim
 The shim used for the binding.
@param {Function} func
 The function link with the transaction.
@param {string} name
 The name of the wrapped function.
@param {TransactionSpec} spec
 The spec for the transaction to create.
@returns {Function} A function which wraps `fn` and creates potentially nested
 transactions linked to its execution.