GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(cloudflare): propagate tracing context through Queue messages by arthurfiorette · Pull Request #22303 · getsentry/sentry-javascript

Conversation

@arthurfiorette

@arthurfiorette arthurfiorette commented Jul 15, 2026 •
edited by andreiborza
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Adds opt-in distributed tracing across Cloudflare Queue producers and consumers.

When enableQueueTracePropagation is enabled on both sides:

  • Record-like message bodies carry sentry-trace and baggage under __sentry_queue_meta__.
  • Arrays, binary payloads, and non-object payloads remain unchanged.
  • Consumers remove the transport metadata before invoking the application handler.
  • queue.process remains a root batch span and links to every producer represented in the batch.

Span links are used instead of continuing a producer trace because a Queue batch can contain messages from unrelated traces. Selecting one producer as the parent would create false causal relationships for the other messages.

The option is disabled by default because Cloudflare Queues does not expose a message-header API. Producers must modify record-like message bodies, so consumers without matching instrumentation may observe the additional metadata field.

Closes #22298

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sentry[bot] reacted with hooray emoji
All reactions
  • 🎉 1 reaction
@arthurfiorette
code
0b05f24
@arthurfiorette
arthurfiorette requested a review from a team as a code owner July 15, 2026 18:26
@arthurfiorette
arthurfiorette requested review from andreiborza, isaacs and mydea and removed request for a team July 15, 2026 18:26
cursor[bot]
cursor Bot reviewed Jul 15, 2026
View reviewed changes
Comment thread packages/cloudflare/src/instrumentations/worker/instrumentQueue.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/cloudflare/src/utils/queueTraceMeta.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/cloudflare/src/instrumentations/worker/instrumentQueue.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@arthurfiorette
fix review comments
0bd582c
cursor[bot]
cursor Bot reviewed Jul 15, 2026
View reviewed changes

@cursor cursor Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

There are 4 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/cloudflare/src/instrumentations/worker/instrumentQueueProducer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/cloudflare/src/utils/queueTraceMeta.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/cloudflare/src/instrumentations/worker/instrumentEnv.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

arthurfiorette and others added 2 commits July 15, 2026 16:17
@arthurfiorette
fix reviews
fe0b730
@arthurfiorette
Merge branch 'develop' into arthurfiorette/queue-links
14ec356
@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

👋 @isaacs, @mydea, @andreiborza — Please review this PR when you get a chance!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

isaacs
isaacs requested changes Jul 21, 2026
View reviewed changes

@isaacs isaacs left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit, one minor improvement, and one potentially substantial design choice. Looks good overall, though, and does indeed fix the bug!

Also, since this is a user-facing change (albeit small), we probably want to add a CHANGELOG.md entry like:

- feat(cloudflare): Add `enableQueueTracePropagation` to link Queue producer and consumer traces ([#22303](https://github.com/getsentry/sentry-javascript/pull/22303))

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/cloudflare/src/instrumentations/worker/instrumentQueue.ts
traceFlags: producerContext.sampled ? TraceFlags.SAMPLED : TraceFlags.NONE,
isRemote: true,
},
attributes: { [SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE]: 'previous_trace' },

@isaacs isaacs Jul 20, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it might be a weird fit. A previous_trace value here indicates that the link is part of a sequential chain of traces, for example a series of browser interactions that a user might perform. In the UI, it's going to be presented with that kind of sequential semantics.

However, this is more of a "fan out" relationship, not previous/next relationship, so I don't think previous_trace makes the most sense here. It might be better to just leave the type off, and let it be a plain old link.

@andreiborza @mydea Do you think I'm misreading this? What is your opinion on the semantics here?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/cloudflare/src/utils/queueTraceMeta.ts
const sentryTrace = body[SENTRY_QUEUE_TRACE_KEY];

// Once propagation is enabled this key is reserved transport metadata, even if its value was corrupted in transit.
delete body.__sentry_queue_trace__;

@isaacs isaacs Jul 20, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the same const as the rest of the file. Also, delete can throw in strict mode if the object is frozen, so best to try/catch it.

Suggested change
delete body.__sentry_queue_trace__;
try {
delete body[SENTRY_QUEUE_TRACE_KEY];
} catch {
// best effort
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/cloudflare/src/instrumentations/worker/instrumentQueueProducer.ts
Comment on lines +89 to +97
return startPublishSpan({ bindingName, bodySize: getBodySize(message) }, span => {
// Read trace data here so the carrier points to queue.publish, not its parent span.
const tracedMessage = enableTracePropagation
? addQueueTraceContext(message, getTraceData()['sentry-trace'])
: message;

if (enableTracePropagation) {
span.setAttribute('messaging.message.body.size', getBodySize(tracedMessage));
}

@isaacs isaacs Jul 21, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, when trace propagation is enabled, we're calling getBodySize twice, and discarding the original value. It's not a huge cost, but it does incur a JSON.stringify, which can be excessive on large messages.

Consider something like this:

Suggested change
return startPublishSpan({ bindingName, bodySize: getBodySize(message) }, span => {
// Read trace data here so the carrier points to queue.publish, not its parent span.
const tracedMessage = enableTracePropagation
? addQueueTraceContext(message, getTraceData()['sentry-trace'])
: message;
if (enableTracePropagation) {
span.setAttribute('messaging.message.body.size', getBodySize(tracedMessage));
}
return startPublishSpan({ bindingName, bodySize: undefined }, span => {
// Read trace data here so the carrier points to queue.publish, not its parent span.
const tracedMessage = enableTracePropagation
? addQueueTraceContext(message, getTraceData()['sentry-trace'])
: message;
span.setAttribute('messaging.message.body.size', getBodySize(tracedMessage));

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/cloudflare/src/utils/queueTraceMeta.ts
// Cloudflare Queues has no message-header API. Only record-like bodies can carry a named field; binary data and
// other structured-clone values must pass through untouched.
const prototype = Object.getPrototypeOf(body);
return prototype === Object.prototype || prototype === null;

@isaacs isaacs Jul 21, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Excludes all "fancy" objects. 👍

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you apply the label PR: no-auto-close I will leave it alone ... forever!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the PR: stale label Aug 11, 2026
@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Closing due to inactivity after stale warning. Comment or reopen when ready to continue, and use PR: no-auto-close to opt out of automatic closure.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Aug 19, 2026
@arthurfiorette arthurfiorette mentioned this pull request Oct 13, 2026
feat(cloudflare): propagate tracing context through Queue messages #25306
Merged
JPeer264 pushed a commit that referenced this pull request Nov 9, 2026
@arthurfiorette @claude
feat(cloudflare): propagate tracing context through Queue messages (#…
7259f5d
…25306)

This extends #22303, which was auto-closed for inactivity after its
review comments slipped through my GitHub inbox. It is now synced with
`develop` and addresses that review.

---

Adds opt-in trace propagation from Cloudflare Queue producers to
consumers.

* When a producer binding matches `queueTracePropagationBindings`,
plain-object message bodies carry the producer's `sentry-trace` under
`__sentry_queue_trace__`.
* Arrays, binary payloads and other non-plain values are sent unchanged.
* Consumers remove that field before invoking the application handler.
* `queue.process` remains 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: boolean` became
`queueTracePropagationBindings`, mirroring `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__`.
* Links no longer set `sentry.link.type: previous_trace`. A batch fans
in producers rather than forming a previous/next chain.

Fixes #22309

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cursor cursor[bot] cursor[bot] left review comments
@isaacs isaacs isaacs requested changes
@mydea mydea Awaiting requested review from mydea mydea was automatically assigned from getsentry/team-javascript-sdks-server
@andreiborza andreiborza Awaiting requested review from andreiborza andreiborza was automatically assigned from getsentry/team-javascript-sdks-server

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

PR: stale

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Cloudflare Instrumentation for Queues seems broken

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@arthurfiorette @isaacs
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.