Skip to content

feat(nitro): Add a Cloudflare Workers plugin - #23246

Open
adipascu wants to merge 1 commit into
getsentry:developfrom
adipascu:feat/nitro-cloudflare-plugin
Open

feat(nitro): Add a Cloudflare Workers plugin#23246
adipascu wants to merge 1 commit into
getsentry:developfrom
adipascu:feat/nitro-cloudflare-plugin

Conversation

@adipascu

@adipascu adipascu commented Aug 11, 2026

Copy link
Copy Markdown

Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).
  • Link an issue if there is one related to your pull request. If no issue is linked, one will be auto-generated and linked.

What

Adds a Cloudflare Workers build to @sentry/nitro, so Nitro apps on a Workers preset get server-side capture through @sentry/cloudflare.

  • sentryCloudflareNitroPlugin(optionsOrFn) mirrors the existing @sentry/nuxt plugin API, and resolves its options on each request so a DSN from a request-scoped binding is picked up.
  • Reachable as @sentry/nitro/cloudflare and through the workerd and worker conditions, with the entry at src/cloudflare/index.ts. Nitro's Cloudflare presets resolve workerd, and worker covers bundlers that use the broader condition, following @sentry/nextjs and @sentry/tanstackstart-react.
  • Reads the Worker ExecutionContext from request.runtime.cloudflare.context, where Nitro v3 puts it, and warns once instead of staying silent when a request carries none (nitro dev, non-Workers presets).
  • Gives each request its own isolation scope, flushes through waitUntil, and reuses the existing captureErrorHook for Nitro's error hook.
  • Adds @sentry/cloudflare to dependencies, matching @sentry/nuxt and @sentry/sveltekit.

The change is additive: the Node entry keeps its exports and behaviour.

Root types points at the Node build, and each workerd/worker branch carries the Cloudflare declarations, so a TS setup with a matching custom condition resolves types that agree with the runtime module. The other packages use a combined index.types.d.ts, but generating one here would drop most of the @sentry/node surface through export * collisions, so the Cloudflare entry keeps its own types instead. Happy to add the combined entry if you would prefer it.

Related: #23029, #20038.

Why

@sentry/nitro resolves to @sentry/node under every condition today, so a cloudflare-module preset has no supported path to server-side capture from this SDK. Nuxt already ships a Workers plugin, and Nitro is the layer both sit on, so the capability belongs here.

Testing

Unit tests cover the plugin, including that the options are re-read per request. One test walks the @sentry/nitro/cloudflare module graph and asserts it stays clear of @sentry/node, since #22519 hit that class of bug through a barrel re-export and it is invisible at build time.

A new nitro-3-cloudflare e2e app builds the cloudflare-module preset and serves it under wrangler dev. It asserts that a thrown route error arrives from the Workers runtime as an HTTP 500 with the Error linked to its h3 HTTPError wrapper and handled: false, that a handled request produces an http.server transaction with origin auto.http.cloudflare, and that 404s are not reported.


Aside: I am currently available for JavaScript/TypeScript contracting or full-time work. Contact: adrian@pascu.be.

@adipascu
adipascu force-pushed the feat/nitro-cloudflare-plugin branch 3 times, most recently from 34b9f59 to 0b5bae1 Compare August 11, 2026 10:58
@adipascu
adipascu marked this pull request as ready for review August 11, 2026 11:00
@adipascu
adipascu requested a review from a team as a code owner August 11, 2026 11:00
@adipascu
adipascu requested review from chargome and s1gr1d and removed request for a team August 11, 2026 11:00
@adipascu
adipascu marked this pull request as draft August 11, 2026 11:01
Comment thread packages/nitro/src/runtime/plugins/cloudflare.ts Outdated
Comment thread packages/nitro/test/runtime/plugins/cloudflare.test.ts
@adipascu
adipascu force-pushed the feat/nitro-cloudflare-plugin branch 2 times, most recently from 7c4df55 to e490372 Compare August 11, 2026 11:26
@adipascu
adipascu marked this pull request as ready for review August 11, 2026 12:05
@adipascu
adipascu force-pushed the feat/nitro-cloudflare-plugin branch 2 times, most recently from a2df7b1 to 2dca239 Compare August 11, 2026 14:26
Comment thread packages/nitro/src/runtime/plugins/cloudflare.ts

@cursor cursor Bot 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 2dca239. Configure here.

@adipascu
adipascu force-pushed the feat/nitro-cloudflare-plugin branch from 2dca239 to 35d55b8 Compare August 11, 2026 14:38
Comment thread packages/nitro/src/runtime/plugins/cloudflare.ts
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.

1 participant