Skip to content

fix(opentelemetry): Convert OpenTelemetry performance.now() timestamps - #25790

Merged
mydea merged 5 commits into
developfrom
fix/otel-performance-timestamps
Oct 28, 2026
Merged

mydea merged 5 commits into
developfrom
fix/otel-performance-timestamps

Conversation

@mydea

@mydea mydea commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

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

mydea and others added 3 commits October 28, 2026 10:03
OpenTelemetry numeric time inputs are always milliseconds, either since the
epoch or since the performance time origin. Interpret them as such for spans
created by the SentryTracerProvider, instead of applying the Sentry API's
seconds-or-milliseconds heuristic.

Fixes #25743

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 1660b32 (PR test merge using develop at 408951e)

Against: 408951e (develop) · base run #63898

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

Path Size % Change Change
@sentry/browser 30.33 kB - -
@sentry/browser - with treeshaking flags 28.45 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.34 kB - -
@sentry/browser (incl. Tracing) 52.6 kB +0.11% +56 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 52.61 kB +0.13% +65 B 🔺
@sentry/browser (incl. Tracing, Profiling) 55.54 kB +0.09% +45 B 🔺
@sentry/browser (incl. Tracing, Replay) 92.8 kB +0.06% +50 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.42 kB +0.07% +52 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 97.53 kB +0.05% +41 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 110.51 kB +0.04% +36 B 🔺
@sentry/browser (incl. Feedback) 47.89 kB - -
@sentry/browser (incl. sendFeedback) 35.4 kB - -
@sentry/browser (incl. FeedbackAsync) 40.51 kB - -
@sentry/browser (incl. Metrics) 31.34 kB - -
@sentry/browser (incl. Logs) 31.62 kB - -
@sentry/browser (incl. Metrics & Logs) 32.3 kB - -
@sentry/react 32.14 kB - -
@sentry/react (incl. Tracing) 54.89 kB +0.13% +71 B 🔺
@sentry/vue 38.6 kB +0.36% +136 B 🔺
@sentry/vue (incl. Tracing) 55.49 kB +0.09% +47 B 🔺
@sentry/svelte 30.36 kB - -
@sentry/remix (Remix 3 client bundle) 57.64 kB +0.08% +46 B 🔺
CDN Bundle 32.06 kB - -
CDN Bundle (incl. Tracing) 53.09 kB +0.14% +69 B 🔺
CDN Bundle (incl. Logs, Metrics) 34.26 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.04 kB +0.1% +53 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 75.68 kB - -
CDN Bundle (incl. Tracing, Replay) 91.22 kB +0.04% +36 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.16 kB +0.04% +32 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 97.36 kB +0.06% +56 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.33 kB +0.07% +64 B 🔺
CDN Bundle - uncompressed 94.29 kB - -
CDN Bundle (incl. Tracing) - uncompressed 157.29 kB +0.1% +152 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.84 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.26 kB +0.1% +152 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.34 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 278.92 kB +0.06% +152 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 284.87 kB +0.06% +152 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 292.62 kB +0.06% +152 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 298.56 kB +0.06% +152 B 🔺
@sentry/nextjs (client) 57.74 kB +0.09% +51 B 🔺
@sentry/sveltekit (client) 53.05 kB +0.1% +50 B 🔺
@sentry/core/server 43.84 kB +0.33% +144 B 🔺
@sentry/core/browser 13.95 kB +1% +137 B 🔺
@sentry/node 154.57 kB +0.11% +161 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.62 kB - -
@sentry/node - without tracing 95.69 kB +0.18% +165 B 🔺
@sentry/node - without channel injection 135.21 kB +0.11% +136 B 🔺
@sentry/aws-serverless 103.86 kB +0.15% +155 B 🔺
@sentry/cloudflare (withSentry) - minified 197.77 kB +0.25% +491 B 🔺
@sentry/cloudflare (withSentry) 491.5 kB +0.3% +1.43 kB 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 218.35 kB +0.23% +491 B 🔺

View base workflow run

Comment thread packages/core/src/tracing/idleSpan.ts Outdated
if (childSpan.isRecording()) {
childSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'cancelled' });
childSpan.end(endTimestamp);
// `endTimestamp` is in seconds, but provider spans read numbers as OpenTelemetry milliseconds

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.

it is super unlikely, I guess, that this is actually the case, because we don't really support otel in browser, and idle spans are only really used in browser.

so we could also decide to ignore this case here 🤔

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.

Yea seems reasonable to me to ignore it here.

@github-actions

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

@mydea
mydea marked this pull request as ready for review October 28, 2026 09:57
@mydea
mydea requested review from a team as code owners October 28, 2026 09:57
@mydea
mydea requested review from andreiborza, chargome, isaacs, logaretm, msonnb and nicohrubec and removed request for a team October 28, 2026 09:57

@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 7a5b50f. Configure here.

childSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'cancelled' });
// NOTE: This deliberately does not work for OTEL-provider spans (which use ms timestamps)
// We do not really support OTEL in the browser, which is the only place that uses idle spans
childSpan.end(endTimestamp);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale provider span cancel test

Medium Severity

This test still expects a tracer-provider child to share the idle span end time, but the cancel path now passes the seconds endTimestamp through unchanged. Provider spans interpret that number as relative milliseconds, so the assertion no longer matches the intended behavior. Testing conventions require tests to cover the newly added behavior.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 7a5b50f. Configure here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mydea
mydea merged commit aaef171 into develop Oct 28, 2026
402 of 406 checks passed
@mydea
mydea deleted the fix/otel-performance-timestamps branch October 28, 2026 11:35
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