Skip to content

Commit 8470cec

Browse files
committed
feat(node): Do not add HTTP & fetch span instrumentation if tracing is disabled
1 parent d0300e6 commit 8470cec

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

packages/node/src/integrations/http/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ClientRequest, IncomingMessage, RequestOptions, ServerResponse } f
22
import { diag } from '@opentelemetry/api';
33
import type { HttpInstrumentationConfig } from '@opentelemetry/instrumentation-http';
44
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
5-
import type { Span } from '@sentry/core';
5+
import { Span, hasSpansEnabled } from '@sentry/core';
66
import { defineIntegration, getClient } from '@sentry/core';
77
import { generateInstrumentOnce } from '../../otel/instrument';
88
import type { NodeClient } from '../../sdk/client';
@@ -136,8 +136,8 @@ export const instrumentOtelHttp = generateInstrumentOnce<HttpInstrumentationConf
136136
/** Exported only for tests. */
137137
export function _shouldInstrumentSpans(options: HttpOptions, clientOptions: Partial<NodeClientOptions> = {}): boolean {
138138
// If `spans` is passed in, it takes precedence
139-
// Else, we by default emit spans, unless `skipOpenTelemetrySetup` is set to `true`
140-
return typeof options.spans === 'boolean' ? options.spans : !clientOptions.skipOpenTelemetrySetup;
139+
// Else, we by default emit spans, unless `skipOpenTelemetrySetup` is set to `true` or spans are not enabled
140+
return typeof options.spans === 'boolean' ? options.spans : !clientOptions.skipOpenTelemetrySetup && hasSpansEnabled(clientOptions);
141141
}
142142

143143
/**

packages/node/src/integrations/node-fetch/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { UndiciInstrumentationConfig } from '@opentelemetry/instrumentation-undici';
22
import { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici';
3-
import type { IntegrationFn } from '@sentry/core';
3+
import { IntegrationFn, hasSpansEnabled } from '@sentry/core';
44
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, defineIntegration, getClient } from '@sentry/core';
55
import { generateInstrumentOnce } from '../../otel/instrument';
66
import type { NodeClient } from '../../sdk/client';
@@ -83,8 +83,10 @@ function getAbsoluteUrl(origin: string, path: string = '/'): string {
8383

8484
function _shouldInstrumentSpans(options: NodeFetchOptions, clientOptions: Partial<NodeClientOptions> = {}): boolean {
8585
// If `spans` is passed in, it takes precedence
86-
// Else, we by default emit spans, unless `skipOpenTelemetrySetup` is set to `true`
87-
return typeof options.spans === 'boolean' ? options.spans : !clientOptions.skipOpenTelemetrySetup;
86+
// Else, we by default emit spans, unless `skipOpenTelemetrySetup` is set to `true` or spans are not enabled
87+
return typeof options.spans === 'boolean'
88+
? options.spans
89+
: !clientOptions.skipOpenTelemetrySetup && hasSpansEnabled(clientOptions);
8890
}
8991

9092
function getConfigWithDefaults(options: Partial<NodeFetchOptions> = {}): UndiciInstrumentationConfig {

0 commit comments

Comments
 (0)