Skip to content

fix(astro): defer to @sentry/cloudflare/vite on Cloudflare Workers - #25347

Open
isaacs wants to merge 1 commit into
isaacs/auto-instrument-default-export-re-exportedfrom
isaacschlueter/js-3934-sentryastro-use-the-cloudflare-vite-plugin-for-workers
Open

isaacs wants to merge 1 commit into
isaacs/auto-instrument-default-export-re-exportedfrom
isaacschlueter/js-3934-sentryastro-use-the-cloudflare-vite-plugin-for-workers

Conversation

@isaacs

@isaacs isaacs commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

On Cloudflare Workers, an Astro app needed a hand-written sentry.server.config.* that wraps the adapter's handler, set as the wrangler main. The integration's own Cloudflare plugin wraps astrojs-ssr-virtual-entry, which @astrojs/cloudflare v13 and later no longer emit, so on those versions it wraps nothing.

@sentry/cloudflare/vite can now wrap a package main, such as @astrojs/cloudflare/entrypoints/server. When the user adds sentryCloudflareVitePlugin() to the Vite plugins in astro.config, the integration now leaves the Worker to it:

  • It does not add its own Cloudflare wrap plugin.
  • It does not add its orchestrion plugin, because the Cloudflare plugin adds one with the workerd-safe diagnostics_channel module.
  • It does not inject the default server init. That init reads PUBLIC_SENTRY_DSN, which is not set on Workers, so it disabled the transport. The Cloudflare plugin inits the SDK from instrument.server.* beside the wrangler config, or from env.

The integration detects the plugin by name. Importing it would load @sentry/cloudflare and wrangler for every Astro app.

Apps without the plugin keep the integration's own wrap plugin. It now also matches virtual:cloudflare/worker-entry, the entry module of @cloudflare/vite-plugin, which v13 and later build through. That entry ends in export default mod.default ?? {};, so the plugin now wraps any default export expression, not only a dotted name. When the user's main already wraps the handler, the second withSentry call does nothing new, because each handler method is patched only once.

The astro-6-cf-workers e2e app now uses the new setup: main is the adapter's entry, and the options live in instrument.server.js.

Fixes JS-3934
Fixes JS-2893
Fixes #21901
Fixes #25344

@isaacs
isaacs added this pull request to stack #25346 October 14, 2026 03:19
@linear-code

linear-code Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

JS-2893

JS-3934

@isaacs

isaacs commented Oct 14, 2026

Copy link
Copy Markdown
Member Author

Bugbot run

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

Stale Bugbot comment from a previous run.

@isaacs
isaacs requested a review from JPeer264 October 14, 2026 04:02
@isaacs
isaacs marked this pull request as ready for review October 14, 2026 04:02
@isaacs
isaacs requested a review from a team as a code owner October 14, 2026 04:02
@isaacs
isaacs requested review from mydea and s1gr1d and removed request for a team October 14, 2026 04:02
On Cloudflare Workers, an Astro app needed a hand-written
`sentry.server.config.*` that wraps the adapter's handler, set as the
wrangler `main`. The integration's own Cloudflare plugin wraps
`astrojs-ssr-virtual-entry`, which `@astrojs/cloudflare` v13 and later
no longer emit, so on those versions it wraps nothing.

`@sentry/cloudflare/vite` can now wrap a package `main`, such as
`@astrojs/cloudflare/entrypoints/server`. When the user adds
`sentryCloudflareVitePlugin()` to the Vite plugins in `astro.config`,
the integration now leaves the Worker to it:

- It does not add its own Cloudflare wrap plugin.
- It does not add its orchestrion plugin, because the Cloudflare plugin
  adds one with the workerd-safe `diagnostics_channel` module.
- It does not inject the default server init. That init reads
  `PUBLIC_SENTRY_DSN`, which is not set on Workers, so it disabled the
  transport. The Cloudflare plugin inits the SDK from
  `instrument.server.*` beside the wrangler config, or from `env`.

The integration detects the plugin by name. Importing it would load
`@sentry/cloudflare` and `wrangler` for every Astro app.

Apps without the plugin keep the integration's own wrap plugin. It now
also matches `virtual:cloudflare/worker-entry`, the entry module of
`@cloudflare/vite-plugin`, which v13 and later build through. That
entry ends in `export default mod.default ?? {};`, so the plugin now
wraps any default export expression, not only a dotted name. When the
user's `main` already wraps the handler, the second `withSentry` call
does nothing new, because each handler method is patched only once.

The `astro-6-cf-workers` e2e app now uses the new setup: `main` is the
adapter's entry, and the options live in `instrument.server.js`.

Fixes JS-3934
Fixes JS-2893

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@isaacs
isaacs force-pushed the isaacschlueter/js-3934-sentryastro-use-the-cloudflare-vite-plugin-for-workers branch from f2b7725 to 9ee9847 Compare October 14, 2026 04:03

@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 9ee9847. Configure here.

}
}
return false;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Plugin detection misses opted-out wrap

Medium Severity

hasCloudflareAutoInstrumentPlugin treats sentryCloudflareVitePlugin() as present only when it finds sentry-cloudflare-auto-instrument. That sub-plugin is omitted if autoInstrumentation is false, so the integration still adds its Node diagnostics_channel orchestrion and the default PUBLIC_SENTRY_DSN server init. Those are the Workers failures this change is meant to avoid, and the Cloudflare plugin still ships its workerd-safe orchestrion in that configuration.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 9ee9847. Configure here.

@JPeer264 JPeer264 left a comment

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.

huge win

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants