Skip to content

Span timestamps trust performance.timeOrigin without the drift guard from #2590 — drifting monotonic clocks produce past-dated (dropped) transactions #22375

Description

Summary

createUnixTimestampInSecondsFunc() in @sentry/core (packages/core/src/utils/time.ts) builds the span-timestamp clock as:

const timeOrigin = performance.timeOrigin;
return () => (timeOrigin + withRandomSafeContext(() => performance.now())) / ONE_SECOND_IN_MS;

It trusts performance.timeOrigin unconditionally, with a standing // TODO: This does not account for the case where the monotonic clock that powers performance.now() drifts from the wall clock ....

Meanwhile getBrowserTimeOrigin() (added for #2590 / PR #3356) does validate the origin against Date.now() with a 5-minute threshold before trusting it — but that guarded value feeds browserPerformanceTimeOrigin, not the span-timestamp function above. So the class of bug #2590 set out to fix still reaches production through the span-timestamp path. (Still the case on develop as of this writing.)

Impact

When performance.timeOrigin + performance.now() drifts from Date.now() — the monotonic clock stops while the device/computer sleeps, long-lived process, backgrounded tab (the scenarios #2590 itself described) — every span/transaction is timestamped in the past. Ingest accepts the envelope (HTTP 200) and the backend then silently drops/hides it, so tracing appears "broken" with no client-side error. Errors and sessions (which use dateTimestampInSeconds / Date.now()) are unaffected, which makes this especially hard to diagnose.

Real-world reproduction (React Native 0.86)

On React Native 0.86 (iOS), performance.now() advances only while the process/host is awake while performance.timeOrigin stays fixed wall-clock, so on a long-lived process the sum drifts behind Date.now() by the accumulated sleep. Measured in-app:

performance.timeOrigin            ≈ 2026-07-06   (fixed)
performance.now()                 ≈ 63 h
timeOrigin + performance.now()    ≈ 2026-07-10   ← ~7 days behind
Date.now()                        ≈ 2026-07-17

Every navigation / HTTP / app-start transaction was stamped ~7 days in the past and dropped, while errors were fine. Versions: @sentry/react-native 8.7.0, @sentry/core 10.47.0.

We worked around it app-side by forcing @sentry/core onto its Date.now() fallback (shadowing performance.timeOrigin to 0 when drift is detected). The underlying RN clock behavior is tracked at react/react-native#57595 — but the SDK could be made resilient to any drifting platform clock, which is what this issue is about.

Suggested fix

Apply the drift check that getBrowserTimeOrigin() already implements to the span-timestamp path: in createUnixTimestampInSecondsFunc(), if |timeOrigin + performance.now() - Date.now()| exceeds a threshold, fall back to dateTimestampInSeconds (or re-anchor the origin). That closes the gap left open after #2590 / #3356 and makes span timestamps robust to sleep/drift on every platform, not just RN.

Environment

  • @sentry/core 10.47.0 (via @sentry/react-native 8.7.0); the span-timestamp path is unchanged on develop.
  • Trigger platform here: React Native 0.86 / iOS — but not RN-specific in principle; any runtime whose monotonic clock drifts from wall time is affected.

Related: #2590, #3356; react/react-native#57595.

Activity

  1. linear-code commented on Jul 17, 2026

    @linear-code
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 17, 2026
  3. nicohrubec commented on Jul 21, 2026

    @nicohrubec
    Member

    Hey, thanks for writing in. We'll take a look.

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jul 21, 2026
  5. Lms24 commented on Jul 22, 2026

    @Lms24
    Member

    I looked into this a bit and it's not straight forward to fix. Left some observations in #22488 for the moment. We'll discuss this further in the team to see which direction we'll take here.

  6. shahzore-qureshi-usmobile commented on Jul 22, 2026

    @shahzore-qureshi-usmobile
    Author

    thanks!! for now, I patched the library and it works well in my project <3

  7. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 22, 2026
  8. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jul 23, 2026
  9. Lms24 commented on Oct 8, 2026

    @Lms24
    Member

    Hi, I merged #23054 and most of the follow-up PRs to fix span time stamps. The fix was more elaborate, given we not only deal with real time timestamps (where Date.now() would indeed be the simples fix), but also with later surfaced performance event data emitted from the browser. So we had to come up with a system that keeps the time origins in sync. This is gonna be released with the next SDK release this our next week. Please let me know if you experience any issues!

  10. github-actions commented on Oct 8, 2026

    @github-actions
    Contributor

    A PR closing this issue has just been released 🚀

    This issue was referenced by PR #23054, which was included in the 11.6.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions