add(transaction, error, customAttributes, segment) {
    if (!error) {
      return
    }

    const shouldCollectErrors = this._shouldCollectErrors()
    if (!shouldCollectErrors) {
      logger.trace('error_collector.enabled is false, dropping application error.')
      return
    }

    if (errorHelper.shouldIgnoreError(transaction, error, this.config)) {
      logger.trace('Ignoring error')
      return
    }

    const timestamp = Date.now()
    const exception = new Exception({ error, timestamp, customAttributes })

    if (transaction) {
      transaction.addException(exception, segment)
    } else {
      this.collect(transaction, exception)
    }
  }
This function collects the error right away when transaction is not supplied. Otherwise it
delays collecting the error until the transaction ends.

NOTE: this interface is unofficial and may change in future.

@param {?Transaction}  transaction  Transaction associated with the error.
@param {Error}  error  The error to be traced.
@param {?object}  customAttributes  Custom attributes associated with the request (optional).
@param {object} segment The segment associated with the error (optional). Only used in otel bridge.