Skip to content

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

Open
JPeer264 wants to merge 1 commit intodevelopfrom
jp/cloudflare-queues
Open

feat(cloudflare): Support tracing for queue producer#20529
JPeer264 wants to merge 1 commit intodevelopfrom
jp/cloudflare-queues

Conversation

@JPeer264
Copy link
Copy Markdown
Member

closes #14387
closes JS-1813

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 producer
this.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

@JPeer264 JPeer264 self-assigned this Apr 27, 2026
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Apr 27, 2026

@JPeer264 JPeer264 force-pushed the jp/cloudflare-queues branch from ef6442b to b9b0533 Compare April 27, 2026 14:57
@github-actions
Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 26.13 kB - -
@sentry/browser - with treeshaking flags 24.6 kB - -
@sentry/browser (incl. Tracing) 44.07 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 46.06 kB - -
@sentry/browser (incl. Tracing, Profiling) 49.02 kB - -
@sentry/browser (incl. Tracing, Replay) 83.27 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 72.77 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 87.94 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 100.61 kB - -
@sentry/browser (incl. Feedback) 43.37 kB - -
@sentry/browser (incl. sendFeedback) 30.93 kB - -
@sentry/browser (incl. FeedbackAsync) 36.11 kB - -
@sentry/browser (incl. Metrics) 27.41 kB - -
@sentry/browser (incl. Logs) 27.56 kB - -
@sentry/browser (incl. Metrics & Logs) 28.24 kB - -
@sentry/react 27.86 kB - -
@sentry/react (incl. Tracing) 46.31 kB - -
@sentry/vue 31 kB - -
@sentry/vue (incl. Tracing) 45.91 kB - -
@sentry/svelte 26.15 kB - -
CDN Bundle 28.8 kB - -
CDN Bundle (incl. Tracing) 46.61 kB - -
CDN Bundle (incl. Logs, Metrics) 30.19 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 47.67 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 69.16 kB - -
CDN Bundle (incl. Tracing, Replay) 83.67 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 84.71 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 89.5 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 90.57 kB - -
CDN Bundle - uncompressed 84.45 kB - -
CDN Bundle (incl. Tracing) - uncompressed 139.45 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 88.59 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 142.86 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 212.17 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 256.89 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 260.29 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 270.59 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 273.98 kB - -
@sentry/nextjs (client) 48.8 kB - -
@sentry/sveltekit (client) 44.52 kB - -
@sentry/node-core 58.73 kB +0.02% +6 B 🔺
@sentry/node 169.84 kB +0.01% +8 B 🔺
@sentry/node - without tracing 97.57 kB +0.01% +4 B 🔺
@sentry/aws-serverless 114.32 kB +0.01% +7 B 🔺
@sentry/cloudflare (withSentry) - minified 164.69 kB +0.91% +1.47 kB 🔺
@sentry/cloudflare (withSentry) 415.59 kB +0.74% +3.04 kB 🔺

View base workflow run

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

@cursor cursor Bot left a 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 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.

const totalBodySize = messageArray.reduce<number>((acc, m) => {
const size = getBodySize(m.body);
return size === undefined ? acc : acc + size;
}, 0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

sendBatch reports body size 0 instead of undefined

Low Severity

The sendBatch body size calculation uses reduce with an initial value of 0, so totalBodySize is always a number (minimum 0). When all messages have unsizable bodies (e.g., null or circular references), totalBodySize will be 0 and messaging.message.body.size gets set to 0. This is inconsistent with send, which correctly passes undefined from getBodySize when the body can't be sized, causing the attribute to be omitted. The sendBatch path emits a misleading 0 instead.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b9b0533. Configure here.

@github-actions
Copy link
Copy Markdown
Contributor

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

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.

Cloudflare queues

1 participant