createErrorDataModel()

in packages/rum-core/src/error-logging/error-logging.js [80:157]


  createErrorDataModel(errorEvent, opts) {
    const frames = createStackTraces(stackParser, errorEvent)
    const filteredFrames = filterInvalidFrames(frames)

    // If filename empty, assume inline script
    let culprit = '(inline script)'
    const lastFrame = filteredFrames[filteredFrames.length - 1]
    if (lastFrame && lastFrame.filename) {
      culprit = lastFrame.filename
    }

    const { message, error } = errorEvent
    let errorMessage = message
    let errorType = ''
    let errorContext = {}
    if (error && typeof error === 'object') {
      errorMessage = errorMessage || error.message
      errorType = error.name
      const customProperties = getErrorProperties(error)
      if (customProperties) {
        errorContext.custom = customProperties
      }
    }
    if (opts && opts.labels) {
      var keys = Object.keys(opts.labels)
      errorContext.tags = {}
      keys.forEach(k => setLabel(k, opts.labels[k], errorContext.tags))
    }

    if (!errorType) {
      /**
       * Try to extract type from message formatted like
       * 'ReferenceError: Can't find variable: initHighlighting'
       */
      if (errorMessage && errorMessage.indexOf(':') > -1) {
        errorType = errorMessage.split(':')[0]
      }
    }
    const currentTransaction = this._transactionService.getCurrentTransaction()
    const transactionContext = currentTransaction
      ? currentTransaction.context
      : {}
    // eslint-disable-next-line no-unused-vars
    const { tags, ...configContext } = this._configService.get('context')
    const pageContext = getPageContext()

    const context = merge(
      {},
      pageContext,
      transactionContext,
      configContext,
      errorContext
    )

    let errorObject = {
      id: generateRandomId(),
      culprit,
      exception: {
        message: errorMessage,
        stacktrace: filteredFrames,
        type: errorType
      },
      context
    }

    if (currentTransaction) {
      errorObject = extend(errorObject, {
        trace_id: currentTransaction.traceId,
        parent_id: currentTransaction.id,
        transaction_id: currentTransaction.id,
        transaction: {
          type: currentTransaction.type,
          sampled: currentTransaction.sampled
        }
      })
    }
    return truncateModel(ERROR_MODEL, errorObject)
  }