Skip to content

feat(cloudflare): Continue the Cloudflare trace of the invocation - #25613

Draft
JPeer264 wants to merge 4 commits into
developfrom
jp/cloudflare-native-trace-id-events
Draft

JPeer264 wants to merge 4 commits into
developfrom
jp/cloudflare-native-trace-id-events

Conversation

@JPeer264

@JPeer264 JPeer264 commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

closes #22214
closes JS-3018

Description

When Sentry tracing is not set up (no tracesSampleRate or tracesSampler), this continues the trace that Cloudflare starts for each invocation (fetch, scheduled, queue and email handlers, and WorkerEntrypoint RPC methods). Errors and logs then have the same trace id as the Cloudflare spans in Workers Observability. An incoming Sentry trace (sentry-trace header or RPC trace data) still has precedence.

When tracing is set up, the SDK keeps starting its own traces as before. This keeps a single tracing source per trace, so Cloudflare and SDK spans never mix in one trace and Sentry does not get the same request spans twice. We can still add an opt-in to continue the Cloudflare trace with tracing enabled later if there is demand.

tracesSampleRate: 0 counts as tracing set up (same check as hasSpansEnabled).

Known issues

  • The SDK reads Span.spanContext(), which ships in workerd 1.20261009.1. Older runtimes keep the current behavior, so only the optional CI job with the latest wrangler runs the new code path.
  • Durable Object handlers do not continue the Cloudflare trace, because DurableObjectState has no tracing. A follow-up can read tracing from cloudflare:workers instead.
  • Without a Cloudflare traces destination, the parent of the Sentry error is not in Sentry.

Sentry traces

Error without tracing, in the Cloudflare trace: https://sentry-sdks.sentry.io/explore/traces/trace/666e09b1979b18724b8fd77faed99e1b/?project=4510555608449024&statsPeriod=14d (captured with tracesSampleRate: 0 before tracing gated the behavior)

Same error without this PR, in its own trace: https://sentry-sdks.sentry.io/explore/traces/trace/bc56b593dcf941c7b21af6216f215dff/?project=4510555608449024&statsPeriod=14d

via Jan Peer Stöcklmair.

--

View Session [Sentry]

@linear-code

linear-code Bot commented Oct 21, 2026

Copy link
Copy Markdown

JS-3018

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: a5edced (PR test merge using develop at 2b878f1)

Against: 2b878f1 (develop) · base run #65743

✅ 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.02 kB - -
@sentry/browser (incl. Tracing) 52.36 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.36 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.33 kB - -
@sentry/browser (incl. Tracing, Replay) 92.76 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.41 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.49 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 110.48 kB - -
@sentry/browser (incl. Feedback) 47.57 kB - -
@sentry/browser (incl. sendFeedback) 35.07 kB - -
@sentry/browser (incl. FeedbackAsync) 40.18 kB - -
@sentry/browser (incl. Metrics) 31.54 kB - -
@sentry/browser (incl. Logs) 31.83 kB - -
@sentry/browser (incl. Metrics & Logs) 32.52 kB - -
@sentry/react 31.84 kB - -
@sentry/react (incl. Tracing) 54.8 kB - -
@sentry/vue 38.39 kB - -
@sentry/vue (incl. Tracing) 55.38 kB - -
@sentry/svelte 30 kB - -
@sentry/remix (Remix 3 client bundle) 57.97 kB - -
CDN Bundle 31.77 kB - -
CDN Bundle (incl. Tracing) 52.94 kB - -
CDN Bundle (incl. Logs, Metrics) 34.58 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.45 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 76.05 kB - -
CDN Bundle (incl. Tracing, Replay) 91.22 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.77 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.34 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.93 kB - -
CDN Bundle - uncompressed 92.89 kB - -
CDN Bundle (incl. Tracing) - uncompressed 156.15 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.42 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.92 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 233.31 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 278.17 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.93 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 291.87 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 299.63 kB - -
@sentry/nextjs (client) 57.74 kB - -
@sentry/sveltekit (client) 52.92 kB - -
@sentry/core/server 44.51 kB - -
@sentry/core/browser 14.02 kB - -
@sentry/node 157.81 kB +0.01% +14 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.31 kB - -
@sentry/node - without tracing 97.25 kB +0.02% +18 B 🔺
@sentry/node - without channel injection 138.12 kB +0.02% +18 B 🔺
@sentry/aws-serverless 106.06 kB +0.02% +21 B 🔺
@sentry/cloudflare (withSentry) - minified 204.95 kB +0.25% +493 B 🔺
@sentry/cloudflare (withSentry) 509.3 kB +0.24% +1.2 kB 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 229.96 kB +0.22% +494 B 🔺

View base workflow run

@JPeer264
JPeer264 force-pushed the jp/cloudflare-native-trace-id-events branch 2 times, most recently from 0d94f79 to 0ac234a Compare October 22, 2026 09:57
@JPeer264
JPeer264 added this pull request to stack #25674 October 23, 2026 06:16
@JPeer264

Copy link
Copy Markdown
Member Author

bugbot run

@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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 0ac234a. Configure here.

@JPeer264
JPeer264 force-pushed the jp/cloudflare-native-trace-id-events branch 2 times, most recently from a831f0a to 7c966d8 Compare October 27, 2026 15:52
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

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

Check Status
❌ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Failing after 2m Details
❌ CI: Optional E2E Tests / E2E nextjs-16-cacheComponents (cloudflare) Test (optional) Failing after 10m Details
❌ CI: Optional E2E Tests / E2E node-eve Test (optional) Failing after 2m Details
❌ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Failing after 58s Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Successful in 51s Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (latest) Test (optional) Successful in 49s Details
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 31s Details
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 57s Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 36s Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 59s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Successful in 52s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (deno) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 52s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 44s Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 43s Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) Successful in 33s Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 28s Details
✅ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) Successful in 40s Details
✅ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 37s Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 40s Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (tunnel-dev) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 40s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 28s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-cloudflare Test (optional) Successful in 29s Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 38s Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 51s Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 34s Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 42s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 34s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Successful in 1m Details

@JPeer264 JPeer264 self-assigned this Nov 9, 2026
@JPeer264
JPeer264 marked this pull request as ready for review November 9, 2026 10:14
@JPeer264
JPeer264 requested review from a team as code owners November 9, 2026 10:14
@JPeer264
JPeer264 requested review from andreiborza, chargome, msonnb and mydea and removed request for a team November 9, 2026 10:14
JPeer264 and others added 3 commits November 11, 2026 14:02
The SDK now reads `ctx.tracing.getActiveSpan().spanContext()` and sets
the propagation context to the Cloudflare trace id and span id. Errors,
logs and spans then use the same trace id as the spans that Cloudflare
exports, also when `tracesSampleRate` is 0. An incoming `sentry-trace`
header keeps precedence. Runtimes without `spanContext()` and invocations
that Cloudflare does not trace keep the current behavior.

`spanContext()` ships in workerd 1.20261009.1, so only the optional CI
job with the latest wrangler runs the new code path. The integration
tests select the expected values of each runtime with
`supports({ minWorkerd })`. The latest wrangler traces every local
invocation, so a root span can have the Cloudflare span as parent, and
the tests find the child segment by its parent instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Jan Peer Stöcklmair <jan.peer@sentry.io>
Co-Authored-By: Jan Peer Stöcklmair <jan.peer@sentry.io>
Co-Authored-By: Jan Peer Stöcklmair <jan.peer@sentry.io>
@sentry-junior
sentry-junior Bot force-pushed the jp/cloudflare-native-trace-id-events branch from 8f1b2b0 to 66599aa Compare November 11, 2026 14:05
@sentry-junior
sentry-junior Bot requested a review from a team November 11, 2026 14:05
@JPeer264
JPeer264 marked this pull request as draft November 11, 2026 15:07
@JPeer264
JPeer264 removed the request for review from mydea November 11, 2026 15:07
Only continue the Cloudflare trace when Sentry tracing is not set up
(no tracesSampleRate or tracesSampler), so a trace has a single source
and Cloudflare and SDK spans never mix.

Co-Authored-By: Jan Peer Stöcklmair <jan.peer@sentry.io>

This branch has not been deployed

No deployments
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.

Add trace id in Sentry Event when tracesSampleRate is set to 0 in Cloudflare

1 participant