Skip to content

fix(opentelemetry): Normalize performance timestamps - #25744

Closed
MathurAditya724 wants to merge 2 commits into
developfrom
codex/fix-otel-performance-timestamps
Closed

MathurAditya724 wants to merge 2 commits into
developfrom
codex/fix-otel-performance-timestamps

Conversation

@MathurAditya724

Copy link
Copy Markdown
Member

OpenTelemetry spans started or ended with performance.now() now use Unix-epoch timestamps and preserve millisecond durations. Previously these numbers were interpreted as Sentry timestamps in seconds, causing Next.js client-component loading spans to appear near 1970 and inflating trace durations.

Normalize numeric time inputs for OpenTelemetry-created spans while retaining the direct Sentry API's seconds-based behavior. Idle-span cancellation passes an unambiguous high-resolution timestamp so it works with either kind of descendant span.

Fixes #25743

Preserve OpenTelemetry millisecond timestamps without changing direct Sentry span timing.

Fixes #25743

Co-Authored-By: GPT-6 <codex@openai.com>
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: b359ca2 (PR test merge using develop at 84f5d12)

Against: 84f5d12 (develop) · base run #63636

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 29.98 kB - -
@sentry/browser - with treeshaking flags 28.13 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.03 kB - -
@sentry/browser (incl. Tracing) 52.25 kB +0.15% +77 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 52.26 kB +0.16% +80 B 🔺
@sentry/browser (incl. Tracing, Profiling) 55.17 kB +0.1% +54 B 🔺
@sentry/browser (incl. Tracing, Replay) 92.02 kB +0.06% +53 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 80.92 kB +0.09% +65 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 96.76 kB +0.06% +57 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 109.7 kB +0.06% +63 B 🔺
@sentry/browser (incl. Feedback) 47.51 kB - -
@sentry/browser (incl. sendFeedback) 35.05 kB - -
@sentry/browser (incl. FeedbackAsync) 40.15 kB - -
@sentry/browser (incl. Metrics) 31.01 kB - -
@sentry/browser (incl. Logs) 31.28 kB - -
@sentry/browser (incl. Metrics & Logs) 31.94 kB - -
@sentry/react 31.81 kB - -
@sentry/react (incl. Tracing) 54.57 kB +0.14% +72 B 🔺
@sentry/vue 38.26 kB +0.32% +119 B 🔺
@sentry/vue (incl. Tracing) 55.17 kB +0.12% +61 B 🔺
@sentry/svelte 30.01 kB - -
@sentry/remix (Remix 3 client bundle) 57.29 kB +0.17% +94 B 🔺
CDN Bundle 31.76 kB - -
CDN Bundle (incl. Tracing) 52.77 kB +0.13% +68 B 🔺
CDN Bundle (incl. Logs, Metrics) 33.95 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 54.73 kB +0.15% +79 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 74.93 kB - -
CDN Bundle (incl. Tracing, Replay) 90.48 kB +0.09% +73 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 92.39 kB +0.07% +63 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 96.6 kB +0.06% +57 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 98.56 kB +0.07% +64 B 🔺
CDN Bundle - uncompressed 93.51 kB - -
CDN Bundle (incl. Tracing) - uncompressed 156.55 kB +0.13% +194 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.06 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 162.52 kB +0.12% +194 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 230.28 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 276.89 kB +0.08% +194 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 282.85 kB +0.07% +194 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 290.6 kB +0.07% +194 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 296.54 kB +0.07% +194 B 🔺
@sentry/nextjs (client) 57.45 kB +0.13% +73 B 🔺
@sentry/sveltekit (client) 52.61 kB +0.12% +60 B 🔺
@sentry/core/server 43.76 kB +0.32% +137 B 🔺
@sentry/core/browser 13.95 kB +1.05% +144 B 🔺
@sentry/node 154.11 kB +0.1% +148 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.58 kB - -
@sentry/node - without tracing 95.63 kB +0.16% +150 B 🔺
@sentry/node - without channel injection 134.77 kB +0.11% +144 B 🔺
@sentry/aws-serverless 103.78 kB +0.14% +136 B 🔺
@sentry/cloudflare (withSentry) - minified 197.65 kB +0.2% +389 B 🔺
@sentry/cloudflare (withSentry) 491.17 kB +0.23% +1.09 kB 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 218.24 kB +0.18% +389 B 🔺

View base workflow run

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 4 not successful, 61 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Failing after 1m Details
❌ CI: Optional E2E Tests / E2E node-openai-decisions-send-to-sentry Test (optional) Failing after 4m Details
❌ CI: Optional E2E Tests / E2E node-anthropic-send-to-sentry (latest) Test (optional) Failing after 44s Details
❌ CI: Optional E2E Tests / E2E node-openai-decisions-send-to-sentry (latest) Test (optional) Failing after 4m Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E angular (canary) Test (optional) Successful in 55s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 23s Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 23s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 49s Details
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E react-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 46s Details
✅ CI: Optional E2E Tests / E2E node-anthropic-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (canary, webpack) Test (optional) Successful in 5m Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 25s Details
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 50s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (canary, turbopack) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E vue-3 (canary) Test (optional) Successful in 51s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 42s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 23s Details
✅ CI: Optional E2E Tests / E2E angular (canary) Test (optional) Successful in 53s Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (canary) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 22s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E nextjs-16-standalone (canary, turbopack) Test (optional) Successful in 41s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (deno) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-3 (canary) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 20s Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 41s Details
✅ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Successful in 41s Details
✅ CI: Optional E2E Tests / E2E nuxt-4-static (canary) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 18s Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) Successful in 23s Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 32s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E nuxt-4 (canary) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 18s Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 27s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 23s Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 47s Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 49s Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E node-openai-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 22s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 23s Details
✅ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 42s Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 46s Details
✅ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 18s Details
✅ CI: Optional E2E Tests / E2E node-openai-send-to-sentry (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E vue-3 (no Options API) Test (optional) Successful in 54s Details

@MathurAditya724
MathurAditya724 marked this pull request as ready for review October 26, 2026 04:56
@MathurAditya724
MathurAditya724 requested a review from a team as a code owner October 26, 2026 04:56
@MathurAditya724
MathurAditya724 requested review from isaacs and mydea and removed request for a team October 26, 2026 04:56
@@ -38,6 +38,7 @@ import {
INTERNAL_setSegmentNameSourceIfSegment,
spanIsSegment,
spanTimeInputToSeconds,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

h: instead of all of this, can we not just adjust spanTimeInputToSeconds to handle this case as well? that should already be called for started spans and when calling end, so this single point should be enough to tweak I believe?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The tricky bit is that Sentry accepts numbers in seconds, while OTel uses milliseconds, including performance.now(). Those values can overlap, so guessing in the shared helper could break existing Sentry timestamps. We could consolidate the helpers with an explicit input mode, but would still need to distinguish the two.

@mydea

mydea commented Oct 28, 2026

Copy link
Copy Markdown
Member

I opened a PR with a slightly different (but similar) approach to solve this here: #25790 - thanks for bringing this up 🙏

@mydea mydea closed this Oct 28, 2026
mydea added a commit that referenced this pull request Oct 28, 2026
#25790)

**Why:** OpenTelemetry numeric time inputs are always milliseconds,
either since the epoch or relative to the performance time origin
(`performance.now()`). We passed them straight into
`spanTimeInputToSeconds`, which treats numbers as seconds, so
`performance.now()` start/end times produced 1970-dated spans with
durations inflated 1000×. This can't be fixed by detecting the unit in
`spanTimeInputToSeconds` itself: Sentry seconds (~1.8e9) and relative
milliseconds overlap after ~21 days of process uptime. Within OTel
semantics the split is unambiguous though — epoch milliseconds are >
1e12 for any date after 2001, while `performance.now()` needs ~30 years
of uptime to get there.

So `otelTimeInputToSeconds` applies OTel semantics, used by
`SentryTracer` for `startTime` and by `SentrySpan` for
`end`/`addEvent`/`updateStartTime` on spans marked via
`spanIsTracerProviderSpan`. It's a separate function instead of a flag
on `spanTimeInputToSeconds` so non-tracing bundles stay unchanged (+0 B
on `@sentry/browser`, ~+70–80 B gzipped on tracing bundles).

**How to review:** Start with `otelTimeInputToSeconds` in
`spanUtils.ts`. Idle spans still cancel unfinished children with a
seconds timestamp, which provider spans would read as relative
milliseconds. I left that alone on purpose: idle spans only exist in the
browser, where we don't really support OTel.

**Unsure about:** `addEvent` keeps treating a falsy time as "now"
(`startTime || undefined`), so `addEvent(name, attrs, 0)` on a provider
span doesn't mean `performance.now()` zero. Kept for backwards
compatibility. We don't really care about `addEvent` too much, so I'd
argue it's fine to keep it and not think too much about this.

Based on the work by @MathurAditya724 in #25744 — thank you!

Closes #25743

Co-authored-by: Aditya Mathur
<57684218+MathurAditya724@users.noreply.github.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

OpenTelemetry performance timestamps produce past-dated spans and inflated durations

2 participants