Repository navigation
feat(cloudflare): propagate tracing context through Queue messages - #25306
Conversation
- Replace `enableQueueTracePropagation` with `queueTracePropagationBindings`, matching `rpcTracePropagationBindings`: producers opt in per binding, consumers always strip and link. - Drop the `previous_trace` link type, a batch fans in producers rather than chaining traces. - Strip the carrier with `Reflect.deleteProperty` on the shared key so frozen bodies cannot throw. - Compute the publish body size once when propagation is enabled. - Move the queue integration assertions to span streaming. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
HI @arthurfiorette thanks for opening another PR for this! I'll leave the review up to @JPeer264 who has more context on the cloudflare specific details. Good idea to use span links. I think we should still set the |
…ueue-links # Conflicts: # CHANGELOG.md
|
I'll wait on reviewing that PR until #21777 is finished. In that PR is an open point on how we deal with span links for queues. This might be then also relevant for this PR. I think by mid next week I can start reviewing this. Hope the timeline is ok for you. |
JPeer264
left a comment
There was a problem hiding this comment.
Sorry that it took a while, but I was finally able to finish of the remaining work of the other PR, that blocked this PR.
It is good that we add a new queueTracePropagationBindings option, since the current one is only focusing on rpc (I originally thought of having a one size fits all option, but I don't think that would have been a good idea).
I added some comments, so please take a look at them. The rest of the code looks good, great work - thank you.
| * ); | ||
| * ``` | ||
| */ | ||
| queueTracePropagationBindings?: TracePropagationTargets; |
There was a problem hiding this comment.
note to myself. We might need to extend this in our Vite plugin to automatically add these in case they're in the same deployment
| @@ -1,18 +1,14 @@ | |||
| import { matchesTracePropagationTargets } from '@sentry/core'; | |||
| import { matchesTracePropagationTargets, type TracePropagationTargets } from '@sentry/core'; | |||
There was a problem hiding this comment.
Super low priority. Technically this file is doing more now than just rpcPropagation , so we could rename it to something more generic, but not a must. You can decide as you see fit.
…ueue-links # Conflicts: # CHANGELOG.md # packages/cloudflare/src/instrumentations/worker/instrumentEnv.ts # packages/cloudflare/test/instrumentations/instrumentEnv.test.ts
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 27dd16c. Configure here.
|
Review comments fixed @JPeer264! |
|
Amazing. Thanks a lot for your work |
This PR adds the external contributor to the CHANGELOG.md file, so that they are credited for their contribution. See #25306 Co-authored-by: JPeer264 <10677263+JPeer264@users.noreply.github.com>
## DESCRIBE YOUR PR This PR documents the new `queueTracePropagationBindings` option in `@sentry/cloudflare` 11.12.0 ([getsentry/sentry-javascript#25306](getsentry/sentry-javascript#25306), closes [getsentry/sentry-javascript#22309](getsentry/sentry-javascript#22309)). The option connects Cloudflare Queue consumers to the producers that sent their messages. - **Distributed tracing (Cloudflare):** Adds a new "Queue Trace Propagation" section. It covers how to opt in per producer binding, that only plain-object bodies carry the `__sentry_queue_trace__` field, that consumers remove the field automatically, and why `queue.process` links to each producer instead of continuing one producer's trace. It also includes a warning about consumers that don't run Sentry and about the roughly 80 extra bytes per message against the 128 KB limit. - **Options:** Adds a `queueTracePropagationBindings` `SdkOption` next to `rpcTracePropagationBindings`, available since 11.12.0. - **Bindings:** Adds a pointer from the Queues binding to the new section. All wording is based on the option's JSDoc and the implementation in that PR. It does not say the Vite plugin derives queue bindings, because the PR doesn't add that. ## IS YOUR CHANGE URGENT? - [ ] Urgent deadline (GA date, etc.): YYYY-MM-DD - [ ] Other deadline: YYYY-MM-DD - [x] No deadline: Not urgent, can wait up to 1 week+ ## PRE-MERGE CHECKLIST - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) <!-- junior-request-attribution:start --> via **Jan Peer Stöcklmair**. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0CA6TD3QRK%3A1794327747.615899 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CA6TD3QRK%3A1794327747.615899) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CA6TD3QRK%3A1794327747.615899/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Jan Peer Stöcklmair <jan.peer@sentry.io>

This extends #22303, which was auto-closed for inactivity after its review comments slipped through my GitHub inbox. It is now synced with
developand addresses that review.Adds opt-in trace propagation from Cloudflare Queue producers to consumers.
queueTracePropagationBindings, plain-object message bodies carry the producer'ssentry-traceunder__sentry_queue_trace__.queue.processremains a root span and links to every distinct producer in the batch.Span links are used instead of continuing a producer trace because a Queue batch can contain messages from unrelated traces. Picking one producer as the parent would create false causal relationships for the other messages.
Propagation is opt-in per binding because Cloudflare Queues has no message-header API. The SDK has to modify the message body, so consumers without Sentry would see the extra field.
Changes since #22303:
enableQueueTracePropagation: booleanbecamequeueTracePropagationBindings, mirroringrpcTracePropagationBindings(feat(cloudflare)!: Replace enableRpcTracePropagation with rpcTracePropagationBindings #23486). Only the producer opts in, since it is the side that changes the payload. Consumers always strip and link, the same way RPC receivers handle__sentry_rpc_meta__.sentry.link.type: previous_trace. A batch fans in producers rather than forming a previous/next chain.Fixes #22309