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

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 30.3 kB - -
@sentry/browser - with treeshaking flags 28.47 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 26.81 kB - -
@sentry/browser (incl. Tracing) 48.58 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.59 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.46 kB - -
@sentry/browser (incl. Tracing, Replay) 87.98 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.36 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 92.7 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 105.39 kB - -
@sentry/browser (incl. Feedback) 47.65 kB - -
@sentry/browser (incl. sendFeedback) 35.13 kB - -
@sentry/browser (incl. FeedbackAsync) 40.28 kB - -
@sentry/browser (incl. Metrics) 31.24 kB - -
@sentry/browser (incl. Logs) 31.52 kB - -
@sentry/browser (incl. Metrics & Logs) 32.15 kB - -
@sentry/react 32.09 kB - -
@sentry/react (incl. Tracing) 50.77 kB - -
@sentry/vue 35.34 kB - -
@sentry/vue (incl. Tracing) 50.54 kB - -
@sentry/svelte 30.33 kB - -
CDN Bundle 31.61 kB - -
CDN Bundle (incl. Tracing) 48.9 kB - -
CDN Bundle (incl. Logs, Metrics) 33.8 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 50.82 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 74.31 kB - -
CDN Bundle (incl. Tracing, Replay) 86.48 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.31 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 92.19 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.12 kB - -
CDN Bundle - uncompressed 93.84 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.75 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.14 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.44 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 229.08 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.01 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 271.68 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.71 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 285.37 kB - -
@sentry/nextjs (client) 53.29 kB - -
@sentry/sveltekit (client) 49 kB - -
@sentry/core/server 65.38 kB - -
@sentry/core/browser 51.72 kB - -
@sentry/node 117.44 kB -0.01% -7 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.18 kB - -
@sentry/node - without tracing 87.43 kB +6.66% +5.46 kB 🔺
@sentry/aws-serverless 95.71 kB +4.79% +4.37 kB 🔺
@sentry/cloudflare (withSentry) - minified 194.46 kB - -
@sentry/cloudflare (withSentry) 480.88 kB - -

View base workflow run

@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
Comment thread packages/node/src/bundler-plugin/common.ts

@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
mydea force-pushed the fn/bundler-auto-exclude-channel-injection branch from 8a9b5ff to 2e080ad Compare August 24, 2026 07:51
mydea and others added 7 commits August 24, 2026 11:04
…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>
… 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>
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>
@mydea
mydea force-pushed the fn/bundler-auto-exclude-channel-injection branch from 2e080ad to 9c7fdd7 Compare August 24, 2026 09:04
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