Skip to content

feat(cloudflare): Support tracing for queue producer - #20529

Merged
JPeer264 merged 4 commits into
developfrom
jp/cloudflare-queues
May 5, 2026
Merged

feat(cloudflare): Support tracing for queue producer#20529
JPeer264 merged 4 commits into
developfrom
jp/cloudflare-queues

Conversation

@JPeer264

@JPeer264JPeer264 commented Apr 27, 2026

Copy link
Copy Markdown
Member

closes#14387
closes#14387

We already had support for the consumer, but the producer was never instrumented. Which means we only knew when a queue was consumed, but never when it was produced.

Example trace (producer new): https://sentry-sdks.sentry.io/explore/traces/trace/7ee71fd6dc8b4ce1a22b1bb9f9610b26/
Example trace (consumer): https://sentry-sdks.sentry.io/explore/traces/trace/486eb86cd02146279c4d547efb4cabab/

In wrangler.jsonc a producer needs to be configured via queues.producers:

{
"queues": {
"producers": [
{
"queue": "test-queue",
"binding": "MY_QUEUE",
},
],
},
}

Once this happens the MY_QUEUE is available in the env variable, which we already instrument. With that we only add isQueue inside instrumentEnv.ts and get instrument the producer:

// this is the producerthis.env.MY_QUEUE.send({somePayload: 'ʕっ•ᴥ•ʔっ'})

Additional info

We are using messaging.batch.message_count, which is not yet in our semantic conventions: https://getsentry.github.io/sentry-conventions/attributes/messaging/

But it was already used before in our queue consumer logic. So the only thing is that it needs to be added first: getsentry/sentry-conventions#338 to make it official

@JPeer264JPeer264 self-assigned this Apr 27, 2026
@linear-code

Copy link
Copy Markdown

@JPeer264
JPeer264force-pushed the jp/cloudflare-queues branch from ef6442b to b9b0533CompareApril 27, 2026 14:57
@github-actions

github-actionsBot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser26.3 kB--
@sentry/browser - with treeshaking flags24.78 kB--
@sentry/browser (incl. Tracing)44.17 kB--
@sentry/browser (incl. Tracing + Span Streaming)46.39 kB--
@sentry/browser (incl. Tracing, Profiling)49.14 kB--
@sentry/browser (incl. Tracing, Replay)83.55 kB--
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags73.01 kB--
@sentry/browser (incl. Tracing, Replay with Canvas)88.23 kB--
@sentry/browser (incl. Tracing, Replay, Feedback)100.84 kB--
@sentry/browser (incl. Feedback)43.44 kB--
@sentry/browser (incl. sendFeedback)31.11 kB--
@sentry/browser (incl. FeedbackAsync)36.19 kB--
@sentry/browser (incl. Metrics)27.6 kB--
@sentry/browser (incl. Logs)27.73 kB--
@sentry/browser (incl. Metrics & Logs)28.43 kB--
@sentry/react28.04 kB--
@sentry/react (incl. Tracing)46.4 kB--
@sentry/vue31.18 kB--
@sentry/vue (incl. Tracing)46.02 kB--
@sentry/svelte26.32 kB--
CDN Bundle28.91 kB--
CDN Bundle (incl. Tracing)46.94 kB--
CDN Bundle (incl. Logs, Metrics)30.33 kB--
CDN Bundle (incl. Tracing, Logs, Metrics)48.04 kB--
CDN Bundle (incl. Replay, Logs, Metrics)69.4 kB--
CDN Bundle (incl. Tracing, Replay)84.07 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)85.15 kB--
CDN Bundle (incl. Tracing, Replay, Feedback)89.89 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)90.99 kB--
CDN Bundle - uncompressed84.88 kB--
CDN Bundle (incl. Tracing) - uncompressed140.44 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed89.08 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed143.9 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed212.99 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed258.24 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed261.69 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed271.94 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed275.38 kB--
@sentry/nextjs (client)48.9 kB--
@sentry/sveltekit (client)44.64 kB--
@sentry/node-core59.13 kB+0.03%+13 B 🔺
@sentry/node170.62 kB+0.01%+11 B 🔺
@sentry/node - without tracing97.16 kB+0.01%+7 B 🔺
@sentry/aws-serverless113.98 kB+0.03%+29 B 🔺
@sentry/cloudflare (withSentry) - minified168.38 kB+0.9%+1.49 kB 🔺
@sentry/cloudflare (withSentry)424.9 kB+0.74%+3.1 kB 🔺

View base workflow run

@JPeer264
JPeer264 marked this pull request as ready for review April 27, 2026 15:19

@cursorcursorBot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

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 b9b0533. Configure here.

Comment threadpackages/cloudflare/src/instrumentations/worker/instrumentQueueProducer.ts Outdated
@github-actions

Copy link
Copy Markdown
Contributor

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

@JPeer264
JPeer264 requested a review from a teamMay 5, 2026 12:07
@JPeer264
JPeer264 requested a review from a team as a code ownerMay 5, 2026 12:09
@JPeer264
JPeer264force-pushed the jp/cloudflare-queues branch from d4d646b to 124f4d9CompareMay 5, 2026 12:41
expect(constructorEnv).not.toBe(mockEnv);
});

it('passes original env to the constructor when enableRpcTracePropagation is disabled', () => {

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This test has been removed as before it only checked if the env was not changed to a Proxy. Because we now have another instrumentation we can simply remove it as it will always be a proxy

Comment on lines +63 to +69
/**
* Duck-type check for Queue producer bindings.
* Queue has `send` and `sendBatch` async methods.
*/
export function isQueue(item: unknown): item is Queue {
return item != null && isNotJSRPC(item) && typeof item.send === 'function' && typeof item.sendBatch === 'function';
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a possibility that other APIs provide the same functions? Meaning: is this check safe enough?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

very unlikely that send and sendBatch are on it at the same time. There is a WebSocket, SendEmail and Pipeline that have send, but not sendBatch.

Comment on lines +57 to +59
if (!rpcPropagation) {
return item;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this be moved up to be an early-return? Then we wouldn't need the isQueue check and it's slightly more performant.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

no it can't as the queue will always be instrumented in case there is one, so rpcPropagation is already an early return for what comes next

@JPeer264
JPeer264 merged commit 4cf5c61 into developMay 5, 2026
503 of 505 checks passed
@JPeer264
JPeer264 deleted the jp/cloudflare-queues branch May 5, 2026 18:18
@github-actionsgithub-actionsBot mentioned this pull request May 7, 2026
@arthurfiorette

Copy link
Copy Markdown

Hey @JPeer264@logaretm is this working? Latest docs says to manually instrument and i couldn't get automated instrumentation to work.

https://docs.sentry.io/platforms/javascript/guides/cloudflare/tracing/instrumentation/queues-module/

Sign up for freeto 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.

Cloudflare queues

4 participants

@JPeer264@arthurfiorette@logaretm@s1gr1d