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

Copy link
Copy Markdown
Member

closes #22214
closes JS-3018

Description

This continues the trace that Cloudflare starts for each invocation (fetch, scheduled, queue and email handlers). Errors, logs and spans then have the same trace id as the Cloudflare spans in Workers Observability, also with tracesSampleRate: 0. An incoming sentry-trace header still has precedence.

Most of the changed lines are tests.

Sampling decisions

The SDK continues only invocations that Cloudflare traces, but it does not take the Cloudflare sampling decision: tracesSampleRate still decides. The alternative is to pass the Cloudflare decision on as sampled, so that Sentry keeps the same traces as Cloudflare.

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.

Sentry traces

Sentry trace whose root span has the Cloudflare span as parent: https://sentry-sdks.sentry.io/explore/traces/trace/69d9287a44d4faddcda5b6612256e6b6/?project=4510555608449024&statsPeriod=14d

@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: bd006ce (PR test merge using develop at 21a9938)

Against: 21a9938 (develop) · base run #63512

✅ 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.17 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.18 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.12 kB - -
@sentry/browser (incl. Tracing, Replay) 91.97 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 80.86 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 96.7 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 109.64 kB - -
@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.5 kB - -
@sentry/vue 38.14 kB - -
@sentry/vue (incl. Tracing) 55.11 kB - -
@sentry/svelte 30.01 kB - -
@sentry/remix (Remix 3 client bundle) 57.19 kB - -
CDN Bundle 31.76 kB - -
CDN Bundle (incl. Tracing) 52.71 kB - -
CDN Bundle (incl. Logs, Metrics) 33.95 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 54.66 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 74.93 kB - -
CDN Bundle (incl. Tracing, Replay) 90.41 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 92.33 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 96.55 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 98.5 kB - -
CDN Bundle - uncompressed 93.51 kB - -
CDN Bundle (incl. Tracing) - uncompressed 156.36 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.06 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 162.33 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 230.28 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 276.71 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 282.66 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 290.41 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 296.35 kB - -
@sentry/nextjs (client) 57.38 kB - -
@sentry/sveltekit (client) 52.55 kB - -
@sentry/core/server 43.62 kB - -
@sentry/core/browser 13.81 kB - -
@sentry/node 153.77 kB +0.01% +2 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.58 kB +0.01% +1 B 🔺
@sentry/node - without tracing 95.32 kB +0.01% +1 B 🔺
@sentry/node - without channel injection 134.42 kB - -
@sentry/aws-serverless 103.48 kB - -
@sentry/cloudflare (withSentry) - minified 195.93 kB +0.21% +407 B 🔺
@sentry/cloudflare (withSentry) 487.34 kB +0.2% +967 B 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 216.59 kB +0.19% +407 B 🔺

View base workflow run

@JPeer264
JPeer264 force-pushed the jp/cloudflare-native-trace-id-events branch from 117c409 to 0d94f79 Compare October 21, 2026 12:36
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 tests pass on
both wranglers. 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>
@JPeer264
JPeer264 force-pushed the jp/cloudflare-native-trace-id-events branch 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.

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