Repository navigation
Conversation
Member
Author
|
Bugbot run |
isaacs
force-pushed
the
isaacschlueter/js-3725-sentrycloudflarevite-auto-instrumentation-skips-the-worker
branch
from
October 14, 2026 02:49
90a6ab1 to
86fcec8
Compare
isaacs
added this pull request to stack #25346
October 14, 2026 03:02
isaacs
marked this pull request as ready for review
October 14, 2026 04:03
isaacs
requested review from
andreiborza and
mydea
and removed request for
a team
October 14, 2026 04:03
JPeer264
approved these changes
Oct 14, 2026
JPeer264
left a comment
Member
There was a problem hiding this comment.
Thanks for taking this. That's quite an important one
isaacs
force-pushed
the
isaacschlueter/js-3725-sentrycloudflarevite-auto-instrumentation-skips-the-worker
branch
from
October 14, 2026 16:17
b07bdc6 to
771e865
Compare
Contributor
size-limit report 📦
|
When wrangler `main` is a package export, such as
`"main": "vinext/server/fetch-handler"` or
`"main": "@astrojs/cloudflare/entrypoints/server"`, the Vite plugin did
not wrap the Worker. The build passed, but the bundle had no Sentry
code, and the plugin gave no warning.
`unstable_readConfig()` resolved every `main` as a path relative to the
wrangler config, so no module matched the entry. The plugin now reads
`main` the way `@cloudflare/vite-plugin` does. A value with a JS or TS
extension is a file path. Any other value is resolved with Vite, once
per environment, from the wrangler config. If it does not resolve, the
plugin warns that auto-instrumentation is off. For a package entry,
`instrument.server.*` is read from beside the wrangler config.
The resolve uses `createIdResolver` from `vite`, so `vite` is now an
optional peer dependency. `this.resolve()` in `transform` does not
work: Rollup's commonjs resolver loads each module it resolves, so a
resolve of the entry from the entry's own transform never finishes.
A `resolveId` hook does not work either, because `vite:resolve`
resolves bare specifiers before user plugins see them.
`createIdResolver` uses each environment's own conditions (for example
`workerd`), so it picks the same file that the Cloudflare plugin
bundles.
Bundled package entries often end in `export { handler as default }`.
The transform only wrapped `export default <expr>`, so it now also
wraps a default export in that form.
The new `cloudflare-autoinstrument-package-entry` e2e app installs a
local package as the Worker entry. `@sentry/astro` still needs changes
before `astro-6-cf-workers` can use a package `main`, so that app stays
as it is, and will be fixed in a subsequent PR.
Fixes #24522
Fixes JS-3725
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
For `export { handler as default }`, the transform declared
`const __SENTRY_DEFAULT_EXPORT__ = withSentry(...)` at the end of the
module. Until that line ran, the default export was in the temporal dead
zone. A circular import that read it during module evaluation threw a
`ReferenceError` and stopped the Worker from starting, where the
original `var` binding was already set.
The wrapper is now declared right after the statement that declares the
binding. It is a `var`, so an earlier read gets `undefined`, as it would
from the bundler's own `var`, and never throws.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…odule
For `export { handler as default }`, the wrapper ran right after
`handler` was declared. A handler assigned later (`let handler; ...
handler = { fetch }`) was exported as `undefined`, and a method added
later (`handler.fetch = ...`) was not instrumented, because `withSentry`
only patches the methods that exist when it runs.
The default export is now set in two steps. Right after `handler` is
declared, it is bound to `handler` as-is, so a circular import that
reads it during module evaluation still gets the handler. At the end of
the module, it is rebound to `withSentry(..., handler)`, which sees the
handler as it ends up.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
isaacs
force-pushed
the
isaacschlueter/js-3725-sentrycloudflarevite-auto-instrumentation-skips-the-worker
branch
from
October 14, 2026 18:18
0941e83 to
1698a1d
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1698a1d. Configure here.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

When wrangler
mainis a package export, such as"main": "vinext/server/fetch-handler"or"main": "@astrojs/cloudflare/entrypoints/server", the Vite plugin did not wrap the Worker. The build passed, but the bundle had no Sentry code, and the plugin gave no warning.unstable_readConfig()resolved everymainas a path relative to the wrangler config, so no module matched the entry. The plugin now readsmainthe way@cloudflare/vite-plugindoes. A value with a JS or TS extension is a file path. Any other value is resolved with Vite, once per environment, from the wrangler config. If it does not resolve, the plugin warns that auto-instrumentation is off. For a package entry,instrument.server.*is read from beside the wrangler config.The resolve uses
createIdResolverfromvite, soviteis now an optional peer dependency.this.resolve()intransformdoes not work: Rollup's commonjs resolver loads each module it resolves, so a resolve of the entry from the entry's own transform never finishes. AresolveIdhook does not work either, becausevite:resolveresolves bare specifiers before user plugins see them.createIdResolveruses each environment's own conditions (for exampleworkerd), so it picks the same file that the Cloudflare plugin bundles.Bundled package entries often end in
export { handler as default }. The transform only wrappedexport default <expr>, so it now also wraps a default export in that form.The new
cloudflare-autoinstrument-package-entrye2e app installs a local package as the Worker entry.@sentry/astrostill needs changes beforeastro-6-cf-workerscan use a packagemain, so that app stays as it is, and will be fixed in a subsequent PR.Fixes #24522
Fixes JS-3725