GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Incorrect span timing in trace view · Issue #12281 · getsentry/sentry-javascript

Incorrect span timing in trace view #12281

New issue
Copy link
New issue
Copy link
Closed
#12648
Closed
Incorrect span timing in trace view#12281
#12648
Copy link
Labels
Next.js

Description

@purplecandy
purplecandy
opened on May 29, 2024
Issue body actions

Is there an existing issue for this?

  • I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • I have reviewed the documentation https://docs.sentry.io/
  • I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

7.110.0

Framework Version

NextJS 12

Link to Sentry event

https://gosprinto.sentry.io/performance/trace/9e6329bd84a84c7a81c70e04a36601f3/?fov=0%2C5903.199951171875&node=trace-root&search=intranet&statsPeriod=1h&timestamp=1716992863

SDK Setup

  Sentry.init({
    dsn: SENTRY_DSN,
    integrations: [
      new Sentry.browserTracingIntegration({
        heartbeatInterval: 10000,
        idleTimeout: 5000,
      }),
      new Sentry.Integrations.Breadcrumbs({
        console: false,
      }),
    ],
    tracesSampleRate: 0.8,

    beforeSend: (event, hints) => {
      const location = window?.location?.href
      const area = getAreaFromUrl(location)
      event.tags.area = area
      return event
    },

    ignoreErrors: [
      // Ignore all `ResizeObserver loop limit exceeded` errors
      'ResizeObserver loop limit exceeded',
      'ResizeObserver loop completed with undelivered notifications',
    ],
  })

Steps to Reproduce

I'm trying to understand why some of our traces have a large period. Upon closer inspection, it seems like the span browser-request should represent the correct TTFB metric which is 867ms but in the Trace View, it reports the TTFB is 2.8s.

Also, when you look at the trace view's JSON payload, you can't find this leading time. The event start time and the browser request start time closely match. So, not sure how Sentry is calculating these metrics on the dashboard.

Expected Result

The correct trace view should be like this.
image

Actual Result

Now, in the initial 2s, as shown in the screenshot, nothing is taking place and when you look at Sentry Replays, no indicator suggests why there should be this delay. It has completely ruined the aggregated metrics for us because it's not the case with all traces, 30% of the time it captures traces like this with an initial leading time.

image

Activity

  1. purplecandy
    added
    Type: Bug
    on May 29, 2024
  2. getsantry
    added
    Waiting for: Product Owner
    on May 29, 2024
  3. getsantry
    added this to GitHub Issues with 👀 3on May 29, 2024
  4. getsantry
    moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on May 29, 2024
  5. github-actions
    added
    Package: nextjs
    on May 29, 2024
  6. Lms24 commented on Jun 3, 2024

    @Lms24
    Lms24
    on Jun 3, 2024
    Member
    More actions

    Hi @purplecandy thanks for writing in!

    I took a look at the code that's collecting the TTFB measurement and we don't do anything in terms of modifying the value other than taking what the browser reports via its performance API. So In your example, it seems like the browser did indeed report 2.8s for TTFB.

    I'm still a bit unsure as to why all spans except for the root pageload and hydration spans are starting with this initial 1.5S delay though. This seems off but I'm not sure what exactly is causing this. @lforst any ideas if this is something NextJS specific?

  7. getsantry
    removed
    Waiting for: Product Owner
    on Jun 3, 2024
  8. getsantry
    moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jun 3, 2024
  9. lforst commented on Jun 4, 2024

    @lforst
    lforst
    on Jun 4, 2024
    Contributor
    More actions

    This looks funky as hell. I think Next.js might be emitting a performance measurement that we pick up. It's not unrealistic that the measurement is faulty and because of that it will skew the entire duration of the transaction. I think the TTFB (wrongly) comes to be at 2796.299ms because we add cache, connect, tls, and request time to first bite PLUS and this is where we get it wrong, the 1768ms leading time from the Next.js measurement.

    If we subtract the leading Next.js measurement from the TTFB we get 1010.299ms. If we add all the stuff up that should contribute to TTFB we get 1010.3ms.

    So I think the value is just wrong, because of the wrong Next.js performance measurement. We should probably add an allow-list for what measurements we permit. We cannot allow 3rd parties to intervene in the data.


    Side-note: The rendering of the TTFB bar also seems to be completely off. We may also have rounding errors. Seems like a rendering error. Forwarded it to the right team.

    Reacted by Lukas Stracke and Vishal Sanserwal
  10. lforst
    self-assigned this
    on Jun 4, 2024
  11. AbhiPrasad
    assigned
    AbhiPrasad
    and unassigned
    lforst
    on Jun 24, 2024
  12. AbhiPrasad
    closed this as completedin #12648on Jun 27, 2024
  13. cobyeastwood183 commented on Aug 13, 2025

    @cobyeastwood183
    cobyeastwood183
    on Aug 13, 2025
    More actions

    Have a customer who is noticing the same thing happening on a recent nextjs SDK version 10+
    https://sentry.zendesk.com/agent/tickets/159977

  14. cobyeastwood183
    reopened this on Aug 13, 2025
  15. linear commented on Aug 13, 2025

    @linear
    linearBot
    on Aug 13, 2025 – with Linear
    More actions

    JS-859 Incorrect span timing in trace view

  16. Lms24 commented on Aug 14, 2025

    @Lms24
    Lms24
    on Aug 14, 2025
    Member
    More actions

    Looking at the linked trace, I don't see an immediate "wrong" behaviour from our end. As already stated above, we simply take the values for LCP, FCP, TTFB, etc that the browser emits. To be more precise, the browser emits raw performance entries. What we take is from the official web-vitals library which our SDK uses and we just recently updated to the newest version.

    All of the browser spans also come directly from emitted browser data. So my suspicion here is that the browser emitted an incorrect performance.timeOrigin value. We can further see this by examining the timeOrigin value, which we track as an attribute and comparing it to the pageload span start timestamp:

    Image Image

    As we can see, the values are identical, meaning we started the pageload span exactly when the browser told us that it started to load the page. Which IMHO is correct behaviour.

    That leaves us with the question why this ~800ms gap between the timeOrigin and the first browser request span (browser.TLS/SSL) happened. Frankly, I don't know. Some guesses:

    • the value is wrong (we've received similar reports about this a while ago)
    • for some reason the browser actually waited with kicking off the request
    • Some NextJS weirdness? I don't know anything about the linked app but if these are static sites where the page was loaded because a user clicked a link that caused a hard page load for the new page, chances are that Next allows for prefetching of the clicked page. We did some research about how this influences recorded timing. And we did find that such periods of inactivity could happen. But frankly, I think this is only something the browser can "fix". Need more information though, and ideally a reproduction.
  17. cobyeastwood183 commented on Aug 18, 2025

    @cobyeastwood183
    cobyeastwood183
    on Aug 18, 2025
    More actions

    Hey @Lms24, appreciate the help! Something they are mentioning is navigation to the page causing this gap could happen from an iframe, not sure if that would lead to gaps between root span and child spans though.

  18. AbhiPrasad
    removed their assignment
    on Aug 29, 2025
  19. cobyeastwood183 commented on Sep 4, 2025

    @cobyeastwood183
    cobyeastwood183
    on Sep 4, 2025
    More actions

    Adding notes, they decided to circle back to this at a later time. Keeping this open in case initial gaps reappear with other customers.

  20. Lms24 commented on Sep 17, 2025

    @Lms24
    Lms24
    on Sep 17, 2025
    Member
    More actions

    Since this isn't really actionable from our end, I'm going to close this for the moment. If we get more information, we can of course revisit this. What we need is a minimal reproducible example.

    Reacted by cobyeastwood183
  21. Lms24
    closed this as completedon Sep 17, 2025
  22. vsanse commented on Dec 2, 2025

    @vsanse
    vsanse
    on Dec 2, 2025
    More actions

    Seeing similar issues in CSR react basesd product [Non-NextJS]

    Image

    TTFB should ideally show 67-70ms but in data it shows up as 2.24s

    Image
  23. chargome
    added
    Next.js
    and removed
    Package: nextjs
    on Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Next.js

    Projects

    • GitHub Issues with 👀 3
      Status
      No status
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.