adjustTransactionTime()

in packages/rum-core/src/performance-monitoring/transaction-service.js [402:439]


  adjustTransactionTime(transaction) {
    /**
     * Adjust start time of the transaction
     */
    const spans = transaction.spans
    const earliestSpan = getEarliestSpan(spans)

    if (earliestSpan && earliestSpan._start < transaction._start) {
      transaction._start = earliestSpan._start
    }

    const latestSpan = getLatestNonXHRSpan(spans) || {}
    const latestSpanEnd = latestSpan._end || 0

    // Before ending the page-load transaction we are adding a delay to monitor events such as LCP and network requests.
    // We need to make sure that we are not adding that extra time to the transaction end time
    // if nothing has been monitored or if the last monitored event end time is less than the delay.
    if (transaction.type === PAGE_LOAD) {
      const transactionEndWithoutDelay = transaction._end - PAGE_LOAD_DELAY
      const lcp = metrics.lcp || 0
      const latestXHRSpan = getLatestXHRSpan(spans) || {}
      const latestXHRSpanEnd = latestXHRSpan._end || 0

      transaction._end = Math.max(
        latestSpanEnd,
        latestXHRSpanEnd,
        lcp,
        transactionEndWithoutDelay
      )
    } else if (latestSpanEnd > transaction._end) {
      /**
       * Adjust end time of the transaction to match the span end value
       */
      transaction._end = latestSpanEnd
    }

    this.truncateSpans(spans, transaction._end)
  }