collect(transaction, exception = new Exception({})) {
    if (!this._isValidException(exception, transaction)) {
      return false
    }

    if (this.errorGroupCallback) {
      exception.errorGroupCallback = this.errorGroupCallback
    }

    const errorTrace = createError(transaction, exception, this.config)
    this._maybeRecordErrorMetrics(errorTrace, transaction)

    // defaults true in config/index. can be modified server-side
    if (this.config.collect_errors) {
      this.traceAggregator.add(errorTrace)
    }

    if (this.config.error_collector.capture_events === true) {
      // eslint-disable-next-line sonarjs/pseudo-random
      const priority = (transaction && transaction.priority) || Math.random()
      const event = createEvent(transaction, errorTrace, exception.timestamp, this.config)
      this.eventAggregator.add(event, priority)
    }

    return true
  }
Collects the error and also creates the error event.

This function uses an array of seen exceptions to ensure errors don't get double-counted. It
can also be used as an unofficial means of marking that user errors shouldn't be traced.

For an error to be traced, at least one of the transaction or the error must be present.

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

@param  {?Transaction}  transaction  Transaction associated with the error.
@param  {?Exception}  exception  The Exception object to be traced.
@returns  {boolean}  True if the error was collected.