Skip to content

fix(core): Account for clock drift in initial timestampInSeconds() call#22488

Draft
Lms24 wants to merge 2 commits into
developfrom
lms/fix-timeStampInSeconds-partially
Draft

fix(core): Account for clock drift in initial timestampInSeconds() call#22488
Lms24 wants to merge 2 commits into
developfrom
lms/fix-timeStampInSeconds-partially

Conversation

@Lms24

@Lms24 Lms24 commented Jul 22, 2026

Copy link
Copy Markdown
Member

#22375 reports a valid bug which is that timestampInSeconds() may return an inaccurate time stamp, since we don't detect clock drift between the performance.timeOrigin + performance.now() timestamp and Date.now().

This PR intentionally only partially fixes this problem by adding a clock drift check only to the initial timestampInSeconds call. This should account for cases where the monotonic performance.now() clock is already off at SDK init time but won't catch clock drift later on.

From here we have two options:

  1. Also add the drift validity check to subsequent calls. This means we'll bypass caching (what we do now) until we detect clock drift, adding performance overhead by running the validity check on every timestampInSeconds call until then.
  2. Drop using the performance time APIs entirely and only return Date.now(). This should give us more accurate timing overall but:
    • we loose nanoseconds precision
    • we'd arguably now report accurate and inaccurate times in one trace because some spans are created from PerformanceEntry entries, which include relative timestamps that might have also suffered from clock drift.

I also still need to look at the sent_at header which should prompt Relay to perform clock-drift normalization but I'm not yet sure to which extent.

Keeping this draft as a possible mitigation open for now

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.8 kB +0.17% +47 B 🔺
@sentry/browser - with treeshaking flags 26.24 kB +0.18% +46 B 🔺
@sentry/browser (incl. Tracing) 46.6 kB +0.04% +14 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 48.41 kB +0.04% +17 B 🔺
@sentry/browser (incl. Tracing, Profiling) 51.42 kB +0.07% +31 B 🔺
@sentry/browser (incl. Tracing, Replay) 85.88 kB +0.06% +45 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.51 kB +0.06% +38 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 90.61 kB +0.07% +55 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 103.23 kB +0.02% +18 B 🔺
@sentry/browser (incl. Feedback) 44.99 kB +0.11% +46 B 🔺
@sentry/browser (incl. sendFeedback) 32.59 kB +0.12% +39 B 🔺
@sentry/browser (incl. FeedbackAsync) 37.72 kB +0.1% +34 B 🔺
@sentry/browser (incl. Metrics) 28.89 kB +0.19% +52 B 🔺
@sentry/browser (incl. Logs) 29.12 kB +0.22% +62 B 🔺
@sentry/browser (incl. Metrics & Logs) 29.82 kB +0.18% +52 B 🔺
@sentry/react 29.6 kB +0.16% +46 B 🔺
@sentry/react (incl. Tracing) 48.9 kB +0.07% +31 B 🔺
@sentry/vue 33.23 kB +0.16% +52 B 🔺
@sentry/vue (incl. Tracing) 48.6 kB +0.08% +38 B 🔺
@sentry/svelte 27.82 kB +0.17% +47 B 🔺
CDN Bundle 30.2 kB +0.15% +44 B 🔺
CDN Bundle (incl. Tracing) 48.58 kB +0.04% +18 B 🔺
CDN Bundle (incl. Logs, Metrics) 31.78 kB +0.13% +41 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 49.9 kB +0.09% +42 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 71.04 kB +0.06% +36 B 🔺
CDN Bundle (incl. Tracing, Replay) 86.09 kB +0.05% +37 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.41 kB +0.05% +35 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 91.9 kB +0.04% +35 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 93.18 kB +0.06% +51 B 🔺
CDN Bundle - uncompressed 90 kB +0.13% +109 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 146.85 kB +0.06% +81 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.68 kB +0.09% +81 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 150.83 kB +0.06% +81 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 219.44 kB +0.04% +81 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.09 kB +0.04% +81 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 270.05 kB +0.04% +81 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.79 kB +0.03% +81 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 283.74 kB +0.03% +81 B 🔺
@sentry/nextjs (client) 51.42 kB +0.09% +42 B 🔺
@sentry/sveltekit (client) 47.04 kB +0.08% +34 B 🔺
@sentry/core/server 80.33 kB +0.04% +25 B 🔺
@sentry/core/browser 66.75 kB +0.07% +42 B 🔺
@sentry/node-core 63.26 kB +0.07% +43 B 🔺
@sentry/node 124.35 kB +0.05% +53 B 🔺
@sentry/node (incl. diagnostics channel injection) 149.79 kB +0.02% +19 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 70.03 kB - -
@sentry/node/light 51.38 kB +0.09% +46 B 🔺
@sentry/node - without tracing 74.96 kB +0.07% +47 B 🔺
@sentry/aws-serverless 84.2 kB +0.05% +34 B 🔺
@sentry/cloudflare (withSentry) - minified 196.74 kB +0.08% +156 B 🔺
@sentry/cloudflare (withSentry) 484.48 kB +0.14% +645 B 🔺

View base workflow run

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