Repository navigation
feat(cloudflare): Continue the Cloudflare trace of the invocation - #25613
Conversation
size-limit report 📦Compared: 4fc3f29 (PR test merge using develop at 14e0d56) Against: 14e0d56 (develop) · base run #66054 ✅ Baseline matches: this diff contains only this PR's changes.
|
0d94f79 to
0ac234a
Compare
|
bugbot run |
There was a problem hiding this comment.
✅ 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.
a831f0a to
7c966d8
Compare
Optional E2E testsSome optional checks were not successful. They do not block the merge. 4 not successful, 54 successful. See the run.
Successful checks
|
8f1b2b0 to
66599aa
Compare
isaacs
left a comment
There was a problem hiding this comment.
Looks good to me.
Should we put something in the changelog, since cf users might see events with a parent_span_id that never makes it to Sentry? Idk how much anyone will actually care, tbh, since this can happen already in some cases anyway.
|
Good point. Adding something into the changelog already makes sense - I'll add something. |
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>
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>
c4d3236 to
5e001ad
Compare
…acing (#25643) This adds the e2e app `cloudflare-workers-without-tracing-send-to-sentry`. It deploys a real Worker without Sentry tracing (no `tracesSampleRate`) and with Cloudflare traces on, and checks that an error in Sentry has the Cloudflare trace id and the Cloudflare request span as its parent. More tests without tracing can go into this app. ## Why The integration tests of #25613 run on a local workerd. This test checks the fix on Cloudflare, against the span that Workers Observability stores for the request. ## Sentry traces With #25613, the error is in the Cloudflare trace: https://sentry-sdks.sentry.io/explore/traces/trace/666e09b1979b18724b8fd77faed99e1b/?project=4510555608449024&statsPeriod=14d (captured with `tracesSampleRate: 0`, before #25613 limited the behavior to setups without tracing) Without #25613, the error has its own trace: https://sentry-sdks.sentry.io/explore/traces/trace/bc56b593dcf941c7b21af6216f215dff/?project=4510555608449024&statsPeriod=14d <!-- junior-request-attribution:start --> via **Jan Peer Stöcklmair**. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0CA6TD3QRK%3A1794409643.554379 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CA6TD3QRK%3A1794409643.554379) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CA6TD3QRK%3A1794409643.554379/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
closes #22214
closes JS-3018
Description
When Sentry tracing is not set up (no
tracesSampleRateortracesSampler), this continues the trace that Cloudflare starts for each invocation (fetch, scheduled, queue and email handlers, andWorkerEntrypointRPC methods). Errors and logs then have the same trace id as the Cloudflare spans in Workers Observability. An incoming Sentry trace (sentry-traceheader 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: 0counts as tracing set up (same check ashasSpansEnabled).Known issues
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.DurableObjectStatehas notracing. A follow-up can readtracingfromcloudflare:workersinstead.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: 0before 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]