Skip to content

fix(browser): Use drift-corrected time origin for INP, replay and profiling - #23067

Draft
Lms24 wants to merge 1 commit into
lms/fix-core-browser-timestampInSeconds-offset-clockdriftfrom
lms/fix-browser-live-performance-time-origin
Draft

fix(browser): Use drift-corrected time origin for INP, replay and profiling#23067
Lms24 wants to merge 1 commit into
lms/fix-core-browser-timestampInSeconds-offset-clockdriftfrom
lms/fix-browser-live-performance-time-origin

Conversation

@Lms24

@Lms24 Lms24 commented Aug 5, 2026

Copy link
Copy Markdown
Member

No description provided.

…filing

`timestampInSeconds` re-derives its time origin when it detects clock drift,
but `browserPerformanceTimeOrigin` caches the origin resolved at SDK init and
never revisits it. Consumers that convert a `PerformanceEntry`'s monotonic
`startTime` to wall clock time therefore end up on a different timeline than
span and event timestamps once a correction has happened.

Exposes the corrected origin as `correctedPerformanceTimeOrigin` and uses it
for the consumers that outlive a span timeout: INP (reports on pagehide) and
replay (sessions run up to an hour). Profiling already compensated for the SDK
changing its time origin, but computed the adjustment against the stale cached
value.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 25c1b28. Configure here.

// Since JS self profiling time origin is always initialized to performance.timeOrigin, we need to adjust for
// the drift between the SDK selected value and our profile time origin.
const perfOrigin = browserPerformanceTimeOrigin();
const perfOrigin = correctedPerformanceTimeOrigin();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Profile elapsed times shift after drift

High Severity

Switching convertJSSelfProfileToSampledFormat to correctedPerformanceTimeOrigin makes adjustForOriginChange non-zero after runtime clock drift. That delta is added into every elapsed_since_start_ns, so the first sample is no longer 0 and all relative sample times shift by the full drift (often negative after device sleep). Continuous profiling absolute timestamps are fine; this only breaks transaction/sampled profiles.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 25c1b28. Configure here.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.88 kB added added
@sentry/browser - with treeshaking flags 28.07 kB added added
@sentry/browser (incl. Tracing) 47.3 kB added added
@sentry/browser (incl. Tracing + Span Streaming) 47.32 kB added added
@sentry/browser (incl. Tracing, Profiling) 52.06 kB added added
@sentry/browser (incl. Tracing, Replay) 86.66 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 76.07 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 91.35 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 104.03 kB added added
@sentry/browser (incl. Feedback) 47.17 kB added added
@sentry/browser (incl. sendFeedback) 34.71 kB added added
@sentry/browser (incl. FeedbackAsync) 39.82 kB added added
@sentry/browser (incl. Metrics) 30.96 kB added added
@sentry/browser (incl. Logs) 31.17 kB added added
@sentry/browser (incl. Metrics & Logs) 31.86 kB added added
@sentry/react 31.68 kB added added
@sentry/react (incl. Tracing) 49.55 kB added added
@sentry/vue 34.96 kB added added
@sentry/vue (incl. Tracing) 49.28 kB added added
@sentry/svelte 29.9 kB added added
CDN Bundle 31.9 kB added added
CDN Bundle (incl. Tracing) 47.6 kB added added
CDN Bundle (incl. Logs, Metrics) 33.45 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 48.99 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 72.81 kB added added
CDN Bundle (incl. Tracing, Replay) 85.22 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.53 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 91.05 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.37 kB added added
CDN Bundle - uncompressed 94.68 kB added added
CDN Bundle (incl. Tracing) - uncompressed 142.21 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.31 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 146.19 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 224 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 261.49 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 265.45 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 275.19 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 279.15 kB added added
@sentry/nextjs (client) 52.12 kB added added
@sentry/sveltekit (client) 47.75 kB added added
@sentry/core/server 65.66 kB added added
@sentry/core/browser 51.96 kB added added
@sentry/node 120.11 kB added added
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 83.73 kB added added
@sentry/aws-serverless 92.23 kB added added
@sentry/cloudflare (withSentry) - minified 218.72 kB added added
@sentry/cloudflare (withSentry) 539.21 kB added added

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant