-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(node): Add build-time opt-out for runtime channel injection #23475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dac4c3a
567644a
a39c210
f1c25ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -303,6 +303,21 @@ export interface Options { | |
| */ | ||
| excludeTracing?: boolean; | ||
|
|
||
| /** | ||
| * Exclude the Node SDK's runtime diagnostics-channel injection from the bundle. | ||
| * | ||
| * If set to `true`, the plugin will attempt to tree-shake (remove) code that installs the Node SDK's | ||
| * runtime module hooks (e.g. for Express instrumentation) at load time. Note that the success of this | ||
| * depends on tree-shaking being enabled in your build tooling. | ||
| * | ||
| * Only enable this when the diagnostics channels are injected at build time (via the bundler plugin) or | ||
| * when you otherwise do not rely on the runtime channel injection. This is equivalent to setting | ||
| * `enableRuntimeChannelInjection: false` in the SDK's `init` options. | ||
| * | ||
| * @default false | ||
| */ | ||
| excludeChannelInjection?: boolean; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this also be added to the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, you are right. this is a bit weird and maybe we can combine these together at some point... |
||
|
|
||
| /** | ||
| * If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay Canvas recording functionality. | ||
| * Note that the success of this depends on tree-shaking being enabled in your build tooling. | ||
|
|
@@ -526,6 +541,7 @@ export type IncludeEntry = { | |
| export interface SentrySDKBuildFlags extends Record<string, boolean | undefined> { | ||
| __SENTRY_DEBUG__?: boolean; | ||
| __SENTRY_TRACING__?: boolean; | ||
| __SENTRY_CHANNEL_INJECTION__?: boolean; | ||
| __RRWEB_EXCLUDE_CANVAS__?: boolean; | ||
| __RRWEB_EXCLUDE_IFRAME__?: boolean; | ||
| __RRWEB_EXCLUDE_SHADOW_DOM__?: boolean; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,10 @@ import { defaultStackParser, getSentryRelease } from './api'; | |
| import { NodeClient } from './client'; | ||
| import { initOpenTelemetry } from './initOtel'; | ||
|
|
||
| // Treeshakable guard to remove all code related to runtime diagnostics-channel injection. Set to | ||
| // `false` at build time by the Sentry bundler plugins' `bundleSizeOptimizations.excludeChannelInjection`. | ||
| declare const __SENTRY_CHANNEL_INJECTION__: boolean | undefined; | ||
|
|
||
| /** | ||
| * Get the base default integrations shared by all Node SDK default-integration sets. | ||
| */ | ||
|
|
@@ -155,11 +159,16 @@ function _init( | |
| }; | ||
|
|
||
| // Install the channel-based (orchestrion diagnostics-channel) instrumentation hooks by default, | ||
| // independent of tracing — the channel integrations also capture errors, not just spans. Opt out | ||
| // with `enableRuntimeChannelInjection: false`. Install as early as possible, before the app imports | ||
| // its instrumented modules. | ||
| const useChannelInjection = options.enableRuntimeChannelInjection !== false; | ||
| if (useChannelInjection) { | ||
| // independent of tracing — the channel integrations also capture errors, not just spans. Opt out at | ||
| // runtime with `enableRuntimeChannelInjection: false`, or at build time via the bundler plugins' | ||
| // `bundleSizeOptimizations.excludeChannelInjection` (which tree-shakes this whole block away). | ||
| // Install as early as possible, before the app imports its instrumented modules. | ||
| if ( | ||
| (typeof __SENTRY_CHANNEL_INJECTION__ === 'undefined' || __SENTRY_CHANNEL_INJECTION__) && | ||
| options.enableRuntimeChannelInjection !== false | ||
| ) { | ||
| registerDiagnosticsChannelInjection(); | ||
| } | ||
| registerDiagnosticsChannelInjection(); | ||
| } | ||
|
Comment on lines
172
to
173
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: There is a duplicate, unconditional call to Suggested FixRemove the unconditional call to Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.