feat(node): Auto-exclude runtime channel injection when build-time instrumentation is on - #23479
Conversation
size-limit report 📦
|
…tation is enabled The `@sentry/node` bundler plugins inject the orchestrion diagnostics channels at build time. When that is on (the default), the SDK's runtime channel injection is redundant, so default `bundleSizeOptimizations.excludeChannelInjection` to `true` to tree-shake the runtime hooks out. Users can still override it explicitly, and the default is skipped when `buildTimeInstrumentation: false`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
54b29f6 to
f119671
Compare
| // A user-provided value takes precedence over the default above. | ||
| ...options?.bundleSizeOptimizations, | ||
| }, | ||
| }; |
There was a problem hiding this comment.
Externalized packages lose injection
Medium Severity
Defaulting excludeChannelInjection whenever buildTimeInstrumentation is not false assumes build-time transforms fully replace runtime hooks. Orchestrion does not transform packages marked external, and its warning still points users at runtime injection as the fallback. With this default, those packages get neither path unless excludeChannelInjection is set back to false.
Reviewed by Cursor Bugbot for commit f119671. Configure here.
… plugin excludes runtime injection Build the entry twice: plain webpack (runtime channel injection bundled by default) and with `sentryWebpackPlugin` (build-time instrumentation), which defaults `excludeChannelInjection` to true and tree-shakes the runtime injection out. assert.mjs verifies the marker is present in the plain build and absent in the plugin build. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ng runs The dead `if (useChannelInjection)` branch is only pruned by the minifier, so `minimize: false` left the runtime injection in the bundle. Verified: with `minimize: true`, the real `sentryWebpackPlugin` excludes the runtime injection while a plain build keeps it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…tests Mirror node-webpack for Vite and Rollup: build the entry plain and with the respective Sentry plugin, and assert the runtime channel-injection marker is present in the plain build but tree-shaken out with the plugin (build-time instrumentation defaults `excludeChannelInjection` to true). Verified locally that both bundlers tree-shake the runtime injection. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c00ea78. Configure here.
Build the entry plain and with `sentryEsbuildPlugin`. esbuild's single-pass tree-shaking keeps the (now dead) runtime injection in the bundle unlike webpack/vite/rollup, so this app only asserts the plain build bundles the runtime injection and the plugin build succeeds; the runtime-behavior side is covered separately. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Vite defaults to a browser target that rejects the entry's top-level await; set a node target. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>


Stacked on #23475.
The
@sentry/nodebundler plugins (sentryRollupPlugin,sentryWebpackPlugin,sentryEsbuildPlugin,sentryVitePlugin) inject the orchestrion diagnostics channels at build time. When that is enabled — which is the default (buildTimeInstrumentation !== false) — the SDK's runtime channel injection is redundant.So the wrappers now default
bundleSizeOptimizations.excludeChannelInjectiontotrue, which sets__SENTRY_CHANNEL_INJECTION__ = false(from #23475) and tree-shakes the runtime hooks out of the build.excludeChannelInjectionalways wins, so it can be turned back on if needed.buildTimeInstrumentation: false, the default is skipped — runtime injection is then the only thing wiring up the channels.Shared via a small
withChannelInjectionExclusionDefaulthelper (bundler-plugin/common.ts) used by all four wrappers, with unit tests.🤖 Generated with Claude Code