@@ -16,6 +16,19 @@ import {
1616} from './diagnosticsChannelInjection' ;
1717import { initOpenTelemetry } from './initOtel' ;
1818
19+ /**
20+ * Whether span recording is enabled, including the `SENTRY_TRACES_SAMPLE_RATE` env var that node-core
21+ * resolves later. `hasSpansEnabled` only inspects the options object, so on init paths that enable
22+ * tracing purely through the env var (e.g. the `@sentry/aws-serverless` Lambda auto-init) it would
23+ * otherwise report `false` and skip the diagnostics-channel injection swap and hook registration.
24+ */
25+ function hasSpansEnabledIncludingEnv ( options : Options ) : boolean {
26+ return (
27+ hasSpansEnabled ( options ) ||
28+ ( options . tracesSampleRate == null && ! options . tracesSampler && ! ! process . env . SENTRY_TRACES_SAMPLE_RATE )
29+ ) ;
30+ }
31+
1932/**
2033 * Get default integrations, excluding performance.
2134 */
@@ -61,7 +74,7 @@ export function applyDiagnosticsChannelInjectionIntegrations(
6174 integrations : Integration [ ] ,
6275 options : Options ,
6376) : Integration [ ] {
64- if ( isDiagnosticsChannelInjectionEnabled ( ) && hasSpansEnabled ( options ) ) {
77+ if ( isDiagnosticsChannelInjectionEnabled ( ) && hasSpansEnabledIncludingEnv ( options ) ) {
6578 const diagnosticsChannelInjection = resolveDiagnosticsChannelInjection ( ) ;
6679 if ( diagnosticsChannelInjection ) {
6780 const replaced = new Set ( diagnosticsChannelInjection . replacedOtelIntegrationNames ) ;
@@ -90,9 +103,12 @@ function _init(
90103 // EXPERIMENTAL: diagnostics-channel injection, opted into via
91104 // `experimentalUseDiagnosticsChannelInjection()`. Gated on span recording to
92105 // match the OTel integrations it replaces. With tracing off there are no
93- // channel subscribers, so injecting is pointless work.
106+ // channel subscribers, so injecting is pointless work. The env var is included
107+ // because node-core resolves `SENTRY_TRACES_SAMPLE_RATE` later, and without it
108+ // the auto-init path (pre-built `integrations`) would skip `register()` and
109+ // never install the module hooks, silently emitting no spans.
94110 const diagnosticsChannelInjection =
95- isDiagnosticsChannelInjectionEnabled ( ) && hasSpansEnabled ( options )
111+ isDiagnosticsChannelInjectionEnabled ( ) && hasSpansEnabledIncludingEnv ( options )
96112 ? resolveDiagnosticsChannelInjection ( )
97113 : undefined ;
98114
0 commit comments