Skip to content

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

Draft
JPeer264 wants to merge 1 commit into
developfrom
jp/cloudflare-native-trace-id-events
Draft

JPeer264 wants to merge 1 commit 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: dbfd19c (PR test merge using develop at 00ee6b7)

Against: 00ee6b7 (develop) · base run #62916

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

Path Size % Change Change
@sentry/browser 29.91 kB - -
@sentry/browser - with treeshaking flags 28.05 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.95 kB - -
@sentry/browser (incl. Tracing) 52.1 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.1 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.05 kB - -
@sentry/browser (incl. Tracing, Replay) 91.85 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 80.72 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 96.58 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 109.52 kB - -
@sentry/browser (incl. Feedback) 47.42 kB - -
@sentry/browser (incl. sendFeedback) 34.97 kB - -
@sentry/browser (incl. FeedbackAsync) 40.07 kB - -
@sentry/browser (incl. Metrics) 30.93 kB - -
@sentry/browser (incl. Logs) 31.21 kB - -
@sentry/browser (incl. Metrics & Logs) 31.84 kB - -
@sentry/react 31.73 kB - -
@sentry/react (incl. Tracing) 54.41 kB - -
@sentry/vue 38.07 kB - -
@sentry/vue (incl. Tracing) 55.03 kB - -
@sentry/svelte 29.93 kB - -
@sentry/remix (Remix 3 client bundle) 57.11 kB - -
CDN Bundle 31.67 kB - -
CDN Bundle (incl. Tracing) 52.61 kB - -
CDN Bundle (incl. Logs, Metrics) 33.87 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 54.55 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 74.79 kB - -
CDN Bundle (incl. Tracing, Replay) 90.28 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 92.21 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 96.42 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 98.37 kB - -
CDN Bundle - uncompressed 93.29 kB - -
CDN Bundle (incl. Tracing) - uncompressed 156.14 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.84 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 162.11 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 229.88 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 276.31 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 282.26 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 290.01 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 295.96 kB - -
@sentry/nextjs (client) 57.31 kB - -
@sentry/sveltekit (client) 52.48 kB - -
@sentry/core/server 41.8 kB - -
@sentry/core/browser 13.81 kB - -
@sentry/node 155.41 kB - -
@sentry/node/import (ESM hook with diagnostics-channel injection) 84.17 kB - -
@sentry/node - without tracing 97.04 kB -0.01% -1 B 🔽
@sentry/node - without channel injection 133.3 kB - -
@sentry/aws-serverless 105.22 kB - -
@sentry/cloudflare (withSentry) - minified 211.5 kB +0.19% +393 B 🔺
@sentry/cloudflare (withSentry) 524.78 kB +0.19% +951 B 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 231.13 kB +0.18% +393 B 🔺

View base workflow run

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 117c409 to 0d94f79 Compare October 21, 2026 12:36

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