Repository navigation
feat(bundler-plugins): Inject installed module versions into server bundles - #26645
sentry-junior[bot] wants to merge 4 commits into
Conversation
size-limit report 📦Compared: 5f4919a (PR test merge using develop at 5b76329) Against: 2e525b2 (develop) · base run #67972
|
|
One or more gzipped bundles increased by more than 500 bytes. If this increase is intentional, add the Accept Bundlesize Increase label to this PR to rerun and accept the check. |
Optional E2E testsSome optional checks were not successful. They do not block the merge. 1 not successful, 76 successful. See the run.
Successful checks
|
can we avoid this somehow?
seems fine to not have this in dev, as long as the fallback generally works there.
would it be hard to change that? seems like this should not be tied to sourcemaps, ideally.
makes sense. |
Yes. Fixed in 88696af: entries that share a chunk now share one copy.
Not hard, but it's a wiring change in 4 frameworks, so I want to agree on the shape first. Today SvelteKit (
Should I go with 1 and add it to this PR, or do it in a follow-up? The dev build and Vite < 6 fallbacks stay as they are; I moved them under "Notes" in the PR body. |
1985c72 to
7acb301
Compare
08bb207 to
b4bcaf1
Compare
7acb301 to
b006c9f
Compare
b006c9f to
d0b5bf9
Compare
e9f9ee8 to
dc440a7
Compare
1e067b7 to
489e0aa
Compare
abb9e9d to
df50522
Compare
1d82887 to
ada67ed
Compare
9972bcc to
19de852
Compare
|
why does this increase bundle size of node sdk so much? shouldn't be the case IMHO |
|
@mydea Almost all of it comes from #26637, not this PR. Size Check compares each PR against
Where #26637's ~500 B goes, measured minified + gzipped per file with esbuild:
So the resolver that #26637 adds (find the app root, read If you want this PR at +0, I can check whether Turbopack accepts the parsed object, by passing the object itself so Next.js's |
…undles In server builds, the Sentry bundler plugins replace the `__SENTRY_SERVER_MODULES__` placeholder that `modulesIntegration` reads with the app's installed module versions, so the integration reports exact versions when `node_modules` is missing or trimmed at runtime. A new `injectModuleVersions` option forces this or opts out. Next.js webpack builds drop their own DefinePlugin and Turbopack reuses the shared resolver through `compiler.defineServer`. SvelteKit, Nuxt, SolidStart and Astro add the plugin in production builds even when source maps are off, with every other plugin feature disabled. Co-Authored-By: Francesco Gringl-Novy <2411343+mydea@users.noreply.github.com>
19de852 to
785802e
Compare
| console.log('Packing @sentry/core...'); | ||
| execSync('pnpm run build:tarball', { cwd: coreDir, stdio: 'inherit' }); | ||
|
|
||
| const serverUtilsDir = join(repoRoot, 'packages', 'server-utils'); |
There was a problem hiding this comment.
can we collapse the build steps into a single pnpm run build:dev:filter call?
There was a problem hiding this comment.
Done in d239e5710c: one pnpm run build:dev:filter @sentry/core @sentry/server-utils @sentry/bundler-plugins call, then a loop packs the three packages.
| describe('replaceBooleanFlagsInCode with server modules', () => { | ||
| const modules = { installed: '1.2.3' }; | ||
|
|
||
| it('replaces the `__SENTRY_SERVER_MODULES__` placeholder', () => { |
There was a problem hiding this comment.
it feels kind of weird that this is part of repalceBooleanFlagsInCode, this is not a boolean flag?
There was a problem hiding this comment.
Agreed. Fixed in d239e5710c: replaceBooleanFlagsInCode is back to only replacing flags. The replacement itself moved to a generic replaceInCode(code, replacements). getBooleanFlagReplacements and getServerModulesReplacement build the entries, and the Rollup transform passes both to it.
| function getServerModules(): Record<string, string> { | ||
| // webpack: the token is replaced with a literal at build time. | ||
| if (typeof __SENTRY_SERVER_MODULES__ !== 'undefined') { | ||
| if (typeof __SENTRY_SERVER_MODULES__ === 'undefined') { |
There was a problem hiding this comment.
hmm wait would that inline the whole object twice here? that seems non-ideal. can we do this in a way that the SENTRY_SERVER_MODULES only exists once and is replaced in a single place somehow, that would be cleaner imho.
There was a problem hiding this comment.
Yes, it inlined the object two to three times: in the typeof check, the return, and the JSON branch. Fixed in d239e5710c: getServerModules now reads the placeholder once (serverModules = __SENTRY_SERVER_MODULES__) inside a try/catch. The catch covers builds that didn't replace it. Bundlers now inline the versions in exactly one place, and the built modules.js contains the placeholder once.
…ction - The Node SDK references `__SENTRY_SERVER_MODULES__` once, so bundlers inline the versions in one place instead of two or three. - `replaceBooleanFlagsInCode` only replaces boolean flags again. The Rollup plugin replaces the flags and the placeholder with a generic `replaceInCode`. - The bundler plugin integration test setup builds the three packed packages with one `build:dev:filter` call. Co-Authored-By: Francesco Gringl-Novy <2411343+mydea@users.noreply.github.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d239e57. Configure here.
|
|
| }; | ||
|
|
||
| function isNodeTarget(target: string | string[] | false | undefined): boolean { | ||
| return (Array.isArray(target) ? target : [target]).some(t => typeof t === 'string' && /^(async-)?node/.test(t)); |
There was a problem hiding this comment.
This also matches node-webkit and misses electron-main
There was a problem hiding this comment.
Fixed in 64de48d. isNodeTarget now matches whole target names: node[X[.Y]], async-node[X[.Y]] and electron[X[.Y]]-main. node-webkit/nwjs, electron-preload and electron-renderer no longer count as server builds. I didn't use externalsPresets.node, because webpack sets it for the Electron renderer and NW.js as well. The webpack test now covers each of these targets.
|
This registers |
…ection
- Move `collectInstalledModules` to `@sentry/core/server`, so
`@sentry/bundler-plugins` no longer depends on `@sentry/server-utils` and
its dependencies.
- Replace the placeholder in a separate `sentry-{vite,rollup}-module-versions`
plugin with a `transform` filter on the placeholder and, in Vite,
`applyToEnvironment` for server environments. The main plugin registers
`transform` only for flags and component annotations again.
- Count webpack `node[X[.Y]]`, `async-node[X[.Y]]` and
`electron[X[.Y]]-main` targets as server builds, and no longer match
`node-webkit`.
Co-Authored-By: Francesco Gringl-Novy <2411343+mydea@users.noreply.github.com>
Fixed in 64de48d. |
Done in 64de48d, as suggested. The replacement now lives in its own
The SvelteKit and SolidStart plugin-list tests now include the new plugin name. |
…ection `compiler.defineServer` inlines `__SENTRY_SERVER_MODULES__`, so it uses `stringifyForCodeInjection` like the other bundlers. The output is still JSON, which `modulesIntegration` parses. Co-Authored-By: Francesco Gringl-Novy <2411343+mydea@users.noreply.github.com>

What
In server builds, the Sentry bundler plugins now replace the
__SENTRY_SERVER_MODULES__placeholder thatmodulesIntegrationreads with the app's installed module versions. That way the integration can report exact versions whennode_modulesis missing or trimmed at runtime. A newinjectModuleVersionsoption forces this withtrueor opts out withfalse.DefinePlugin.define.serverconsumer, and SSR builds.node/async-nodetargets.platform: 'node'.bun/nodetargets.injectModuleVersions: true. Nuxt sets that for its Nitro build.DefinePluginand rely on the plugin. Turbopack builds replace the placeholder throughcompiler.defineServerwith the same resolver, instead of setting a global frominstrumentation.ts. Next.js only accepts strings there, so Turbopack passes JSON, whichmodulesIntegrationparses. The Node SDK no longer reads the global.getDisabledSourcemapsOptions(), which turns off everything else: no source map upload or deletion, no debug IDs, no release creation or injection, and no telemetry.Why
This computes the versions once, in one place, for every bundler instead of per framework.
Replacing the placeholder, instead of injecting a global, keeps the list in one spot: the bundled copy of the SDK's
modules.js. That avoids putting a copy into every entry and needs no chunk placement logic. When the SDK stays external, which is the default for Vite SSR, SvelteKit and Astro on Node, nothing is replaced and the SDK resolves versions fromnode_modulesat runtime as in #26637.node_modulesis present in that setup anyway. Browser bundles never get the list unless someone forces it.Notes:
modulesIntegration#26637,modulesIntegrationuses a non-empty__SENTRY_SERVER_MODULES__as is and skips runtime resolution. Bundled apps therefore report the app's declared dependencies at their installed versions, without transitive packages fromrequire.cache.node_modulesis present. Turbopack dev builds still get the versions throughcompiler.defineServer.build.ssrflag there.via @mydea.
--
View Session [Sentry]