Skip to content

feat(node): Auto-exclude runtime channel injection when build-time instrumentation is on - #23479

Draft
mydea wants to merge 7 commits into
fn/channel-injection-build-flagfrom
fn/bundler-auto-exclude-channel-injection
Draft

feat(node): Auto-exclude runtime channel injection when build-time instrumentation is on#23479
mydea wants to merge 7 commits into
fn/channel-injection-build-flagfrom
fn/bundler-auto-exclude-channel-injection

Conversation

@mydea

@mydea mydea commented Aug 21, 2026

Copy link
Copy Markdown
Member

Stacked on #23475.

The @sentry/node bundler 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.excludeChannelInjection to true, which sets __SENTRY_CHANNEL_INJECTION__ = false (from #23475) and tree-shakes the runtime hooks out of the build.

  • The default is applied only to the options passed to the Sentry bundler plugin; the orchestrion plugin still receives the original options.
  • A user-provided excludeChannelInjection always wins, so it can be turned back on if needed.
  • When buildTimeInstrumentation: false, the default is skipped — runtime injection is then the only thing wiring up the channels.

Shared via a small withChannelInjectionExclusionDefault helper (bundler-plugin/common.ts) used by all four wrappers, with unit tests.

🤖 Generated with Claude Code

Comment thread packages/node/src/bundler-plugin/common.ts
@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 30.3 kB added added
@sentry/browser - with treeshaking flags 28.47 kB added added
@sentry/browser - with treeshaking flags tracing without tracing 26.81 kB added added
@sentry/browser (incl. Tracing) 48.58 kB added added
@sentry/browser (incl. Tracing + Span Streaming) 48.59 kB added added
@sentry/browser (incl. Tracing, Profiling) 51.46 kB added added
@sentry/browser (incl. Tracing, Replay) 87.98 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.36 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 92.7 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 105.39 kB added added
@sentry/browser (incl. Feedback) 47.65 kB added added
@sentry/browser (incl. sendFeedback) 35.13 kB added added
@sentry/browser (incl. FeedbackAsync) 40.28 kB added added
@sentry/browser (incl. Metrics) 31.24 kB added added
@sentry/browser (incl. Logs) 31.52 kB added added
@sentry/browser (incl. Metrics & Logs) 32.15 kB added added
@sentry/react 32.09 kB added added
@sentry/react (incl. Tracing) 50.77 kB added added
@sentry/vue 35.34 kB added added
@sentry/vue (incl. Tracing) 50.54 kB added added
@sentry/svelte 30.33 kB added added
CDN Bundle 31.61 kB added added
CDN Bundle (incl. Tracing) 48.9 kB added added
CDN Bundle (incl. Logs, Metrics) 33.8 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 50.82 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 74.31 kB added added
CDN Bundle (incl. Tracing, Replay) 86.48 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.31 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 92.19 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.12 kB added added
CDN Bundle - uncompressed 93.84 kB added added
CDN Bundle (incl. Tracing) - uncompressed 146.75 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.14 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.44 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 229.08 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.01 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 271.68 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.71 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 285.37 kB added added
@sentry/nextjs (client) 53.29 kB added added
@sentry/sveltekit (client) 49 kB added added
@sentry/core/server 65.38 kB added added
@sentry/core/browser 51.72 kB added added
@sentry/node 117.35 kB added added
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.08 kB added added
⛔️ @sentry/node - without tracing (max: 87 kB) 87.35 kB added added
@sentry/aws-serverless 95.62 kB added added
@sentry/cloudflare (withSentry) - minified 213.98 kB added added
@sentry/cloudflare (withSentry) 528.93 kB added added

…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>
@mydea
mydea force-pushed the fn/bundler-auto-exclude-channel-injection branch from 54b29f6 to f119671 Compare August 21, 2026 11:02
Comment thread packages/node/test/bundler-plugin/common.test.ts
// A user-provided value takes precedence over the default above.
...options?.bundleSizeOptimizations,
},
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f119671. Configure here.

mydea and others added 3 commits August 21, 2026 13:10
… 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>

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

There are 2 total unresolved issues (including 1 from previous review).

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 c00ea78. Configure here.

Comment thread dev-packages/e2e-tests/test-applications/node-webpack/build.mjs
mydea and others added 3 commits August 21, 2026 13:30
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant