feat(node): Add build-time opt-out for runtime channel injection - #23475
feat(node): Add build-time opt-out for runtime channel injection#23475mydea wants to merge 1 commit into
Conversation
size-limit report 📦
|
68993db to
c6d9d7f
Compare
c6d9d7f to
1d27eb4
Compare
1d27eb4 to
e670b7c
Compare
e670b7c to
40ae0c4
Compare
40ae0c4 to
8ff1633
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes 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 8ff1633. Configure here.
8ff1633 to
5a399f9
Compare
Introduce a `__SENTRY_CHANNEL_INJECTION__` treeshaking flag (mirroring `__SENTRY_TRACING__`) that removes the runtime diagnostics-channel injection when text-replaced with `false`, and expose it through the bundler plugins' `bundleSizeOptimizations.excludeChannelInjection`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
5a399f9 to
dac4c3a
Compare
isaacs
left a comment
There was a problem hiding this comment.
Two small fixes that I think are worth doing before landing, but this looks good otherwise.
| * | ||
| * @default false | ||
| */ | ||
| excludeChannelInjection?: boolean; |
There was a problem hiding this comment.
Should this also be added to the BundleSizeOptimizationsOptions in packages/core/src/build-time-plugins/buildTimeOptionsBase.ts, so that it can be picked up on the bundleSizeOptimizations field of BuildTimeOptionsBase? Eg, that's what packages/nuxt/src/common/types.ts pulls its options from.
| const useChannelInjection = | ||
| (typeof __SENTRY_CHANNEL_INJECTION__ === 'undefined' || __SENTRY_CHANNEL_INJECTION__) && | ||
| options.enableRuntimeChannelInjection !== false; | ||
| if (useChannelInjection) { |
There was a problem hiding this comment.
Making this a const seems to thwart tree shaking on webpack 5 and esbuild, maybe because the options.enableRuntimeChannelInjection is a property access, so could theoretically be a getter?
But doing it this way drops the webpack and esbuild builds by about 20kb. (Rollup seems to be smart enough to know the const is unused outside of these two lines.)
| const useChannelInjection = | |
| (typeof __SENTRY_CHANNEL_INJECTION__ === 'undefined' || __SENTRY_CHANNEL_INJECTION__) && | |
| options.enableRuntimeChannelInjection !== false; | |
| if (useChannelInjection) { | |
| if ( | |
| (typeof __SENTRY_CHANNEL_INJECTION__ === 'undefined' || __SENTRY_CHANNEL_INJECTION__) && | |
| options.enableRuntimeChannelInjection !== false | |
| ) { | |
| registerDiagnosticsChannelInjection(); | |
| } |
There was a problem hiding this comment.
Found by adding a size-limt entry for this, could be a good addition to this PR, or a follow-up:
diff --git a/.size-limit.js b/.size-limit.js
index 288258df7c..66e82cbdc5 100644
--- a/.size-limit.js
+++ b/.size-limit.js
@@ -447,6 +447,30 @@ module.exports = [
return config;
},
},
+ {
+ // verify the ~20kb the `bundleSizeOptimizations.excludeChannelInjection`
+ // option removes from the default @sentry/node build.
+ name: '@sentry/node - without channel injection',
+ path: 'packages/node/build/esm/index.js',
+ import: createImport('init'),
+ gzip: true,
+ limit: '104 KB',
+ disablePlugins: ['@size-limit/esbuild'],
+ ignore: [...builtinModules, ...nodePrefixedBuiltinModules],
+ modifyWebpackConfig: function (config) {
+ const webpack = require('webpack');
+
+ config.plugins.push(
+ new webpack.DefinePlugin({
+ __SENTRY_CHANNEL_INJECTION__: false,
+ }),
+ );
+
+ config.optimization.minimize = true;
+
+ return config;
+ },
+ },
// AWS SDK (ESM)
{
name: '@sentry/aws-serverless',

Stacked on #23473.
Adds a build-time opt-out for the Node SDK's runtime diagnostics-channel injection, complementing the runtime
enableRuntimeChannelInjectionoption from the base PR.__SENTRY_CHANNEL_INJECTION__treeshaking flag, mirroring__SENTRY_TRACING__: when a bundler text-replaces it withfalse, theregisterDiagnosticsChannelInjection()/detectOrchestrionSetup()block ininitis dropped, and its transitive orchestrion-register code tree-shakes away.bundleSizeOptimizations.excludeChannelInjection, which maps to__SENTRY_CHANNEL_INJECTION__ = falsevia the same mechanism asexcludeTracing.(typeof __SENTRY_CHANNEL_INJECTION__ === 'undefined' || __SENTRY_CHANNEL_INJECTION__) && options.enableRuntimeChannelInjection !== false.🤖 Generated with Claude Code