You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@sentry/cloudflare/vite: Auto-instrumentation skips the Worker when wrangler main is a package specifier #24522
sentryCloudflareVitePlugin() does not wrap the Worker when main in the Wrangler config is a package specifier and not a file path. The build succeeds, but the bundle contains no Sentry code, and the plugin logs no warning.
@cloudflare/vite-plugin supports this config, and vinext generates it by default with vinext init --platform=cloudflare:
Tested with @sentry/cloudflare@11.0.0-rc.0, @cloudflare/vite-plugin@1.56.0, wrangler@4.135.0, vinext@1.0.0-beta.10 and Vite 8.3.
Cause
resolveWranglerConfig() calls unstable_readConfig() without preserveOriginalMain (wranglerConfig.ts#L70). Wrangler then resolves every main as a path relative to the config file:
main: "vinext/server/fetch-handler"
-> <project>/vinext/server/fetch-handler (file does not exist)
autoInstrument.ts compares this path with the module IDs in transform (L75), so no module matches. resolveInstrumentFile() also looks for instrument.server.* in the directory of this path (instrumentFile.ts#L23), and a package entry has no such file.
@cloudflare/vite-plugin handles the same value differently:
It reads the config with unstable_readConfig(..., { preserveOriginalMain: true }).
maybeResolveMain() makes main absolute only when it ends with a JS or TS extension.
It resolves the entry with Vite: await this.resolve(workerConfig.main).
Workaround
Add a local entry that re-exports the package entry, and set main to it. Put instrument.server.ts in the same directory:
I reproduced this with a freshly packed SDK from bd3ce5f, using the repo's pinned Vite 7.3.5, Cloudflare plugin 1.34.0 and Wrangler 4.86.0.
The same handler captures errors as a file entry or through a local file adapter. As a package export, it builds and serves requests, but the output has no Sentry wrapper and the build gives no Sentry warning. I also checked a Wrangler config below the Vite root.
Is anyone working on this? I'd like to take the package-entry resolution and a regression test, preserving file-entry behavior. For package entries, should instrument.server.* be read beside the Wrangler config?
Best case scenario is that this file goes away and we only have a instrument.server.* file that uses defineCloudflareOptions (and the wrangler config has "main": "@astrojs/cloudflare/entrypoints/server"). Rest is then automagically done by the Vite plugin.
For package entries, should instrument.server.* be read beside the Wrangler config?
Yes, that'd be nice. In the future I think it's good if this can be changed via an option, but no need for now to add this.
@ihsraham I'm able to take this on, if you haven't gotten around to it yet. But I thought I'd check in, in case you have a PR that you're hoping to send, don't want to scoop your efforts 😅
If I don't hear from you, I'll get a PR open for it soon.
Activity
linear-code commentedon Sep 19, 2026
JS-3725
ihsraham commentedon Sep 27, 2026
I reproduced this with a freshly packed SDK from bd3ce5f, using the repo's pinned Vite 7.3.5, Cloudflare plugin 1.34.0 and Wrangler 4.86.0.
The same handler captures errors as a file entry or through a local file adapter. As a package export, it builds and serves requests, but the output has no Sentry wrapper and the build gives no Sentry warning. I also checked a Wrangler config below the Vite root.
Is anyone working on this? I'd like to take the package-entry resolution and a regression test, preserving file-entry behavior. For package entries, should
instrument.server.*be read beside the Wrangler config?JPeer264 commentedon Sep 28, 2026
Feel free to work on it
You could also update the following E2E test. The ticket states Vinext, as I tried it there, but it also valid for Astro: https://github.com/getsentry/sentry-javascript/blob/954e9694a2bd983c14e0de3b665568c46c60785f/dev-packages/e2e-tests/test-applications/astro-6-cf-workers/sentry.server.config.js
Best case scenario is that this file goes away and we only have a
instrument.server.*file that usesdefineCloudflareOptions(and the wrangler config has"main": "@astrojs/cloudflare/entrypoints/server"). Rest is then automagically done by the Vite plugin.isaacs commentedon Oct 14, 2026
@ihsraham I'm able to take this on, if you haven't gotten around to it yet. But I thought I'd check in, in case you have a PR that you're hoping to send, don't want to scoop your efforts 😅
If I don't hear from you, I'll get a PR open for it soon.
ihsraham commentedon Oct 14, 2026
@isaacs Thanks for checking in. I haven't been able to finish this, so please go ahead and take it on. I appreciate you offering to help.
fix(cloudflare): auto-instrument when wrangler `main` is a package
fix(cloudflare): auto-instrument when wrangler `main` is a package (#…
github-actions commentedon Oct 15, 2026
A PR closing this issue has just been released 🚀
This issue was referenced by PR #25343, which was included in the 11.8.0 release.