Skip to content

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

Merged
isaacs merged 3 commits into
developfrom
isaacschlueter/js-3934-sentryastro-use-the-cloudflare-vite-plugin-for-workers
Oct 15, 2026
Merged

isaacs merged 3 commits into
developfrom
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. This replaces the cloudflare-autoinstrument-package-entry e2e app, as its coverage largely overlaps with it.

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

Comment thread packages/astro/src/integration/index.ts

@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

@isaacs
isaacs force-pushed the isaacschlueter/js-3934-sentryastro-use-the-cloudflare-vite-plugin-for-workers branch 5 times, most recently from 5edda85 to 9e3de29 Compare October 14, 2026 23:36
@JPeer264
JPeer264 force-pushed the isaacschlueter/js-3934-sentryastro-use-the-cloudflare-vite-plugin-for-workers branch from 9e3de29 to 966e0af Compare October 15, 2026 08:45
@isaacs
isaacs force-pushed the isaacschlueter/js-3934-sentryastro-use-the-cloudflare-vite-plugin-for-workers branch from 966e0af to 5715055 Compare October 15, 2026 14:06
Base automatically changed from isaacs/auto-instrument-default-export-re-exported to develop October 15, 2026 14:27
@isaacs
isaacs requested a review from a team as a code owner October 15, 2026 14:27
@isaacs
isaacs requested review from andreiborza and removed request for a team October 15, 2026 14:27
@isaacs
isaacs force-pushed the isaacschlueter/js-3934-sentryastro-use-the-cloudflare-vite-plugin-for-workers branch from 5715055 to 8eb70d7 Compare October 15, 2026 14:27
isaacs and others added 3 commits October 15, 2026 09:43
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>
This PR adds an e2e test that makes the prior one unnecessary. Remove it.
@isaacs
isaacs force-pushed the isaacschlueter/js-3934-sentryastro-use-the-cloudflare-vite-plugin-for-workers branch from 8eb70d7 to 55fd5d1 Compare October 15, 2026 16:43
@isaacs
isaacs merged commit 0778826 into develop Oct 15, 2026
732 of 738 checks passed
@isaacs
isaacs deleted the isaacschlueter/js-3934-sentryastro-use-the-cloudflare-vite-plugin-for-workers branch October 15, 2026 19:03
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