@@ -3,7 +3,8 @@ import { diag } from '@opentelemetry/api';
33import type { HttpInstrumentationConfig } from '@opentelemetry/instrumentation-http' ;
44import { HttpInstrumentation } from '@opentelemetry/instrumentation-http' ;
55import type { Span } from '@sentry/core' ;
6- import { defineIntegration , getClient } from '@sentry/core' ;
6+ import { defineIntegration , getClient , hasSpansEnabled } from '@sentry/core' ;
7+ import { NODE_VERSION } from '../../nodeVersion' ;
78import { generateInstrumentOnce } from '../../otel/instrument' ;
89import type { NodeClient } from '../../sdk/client' ;
910import type { HTTPModuleRequestIncomingMessage } from '../../transports/http-module' ;
@@ -85,8 +86,8 @@ interface HttpOptions {
8586 * Do not capture the request body for incoming HTTP requests to URLs where the given callback returns `true`.
8687 * This can be useful for long running requests where the body is not needed and we want to avoid capturing it.
8788 *
88- * @param url Contains the entire URL, including query string (if any), protocol, host, etc. of the outgoing request.
89- * @param request Contains the {@type RequestOptions} object used to make the outgoing request.
89+ * @param url Contains the entire URL, including query string (if any), protocol, host, etc. of the incoming request.
90+ * @param request Contains the {@type RequestOptions} object used to make the incoming request.
9091 */
9192 ignoreIncomingRequestBody ?: ( url : string , request : RequestOptions ) => boolean ;
9293
@@ -159,8 +160,22 @@ export const instrumentOtelHttp = generateInstrumentOnce<HttpInstrumentationConf
159160/** Exported only for tests. */
160161export function _shouldInstrumentSpans ( options : HttpOptions , clientOptions : Partial < NodeClientOptions > = { } ) : boolean {
161162 // If `spans` is passed in, it takes precedence
162- // Else, we by default emit spans, unless `skipOpenTelemetrySetup` is set to `true`
163- return typeof options . spans === 'boolean' ? options . spans : ! clientOptions . skipOpenTelemetrySetup ;
163+ // Else, we by default emit spans, unless `skipOpenTelemetrySetup` is set to `true` or spans are not enabled
164+ if ( typeof options . spans === 'boolean' ) {
165+ return options . spans ;
166+ }
167+
168+ if ( clientOptions . skipOpenTelemetrySetup ) {
169+ return false ;
170+ }
171+
172+ // IMPORTANT: We only disable span instrumentation when spans are not enabled _and_ we are on Node 22+,
173+ // as otherwise the necessary diagnostics channel is not available yet
174+ if ( ! hasSpansEnabled ( clientOptions ) && NODE_VERSION . major >= 22 ) {
175+ return false ;
176+ }
177+
178+ return true ;
164179}
165180
166181/**
0 commit comments