Skip to content

Commit fba1580

Browse files
committed
fix: respect SUPPRESS_TRACING flag
1 parent 5379392 commit fba1580

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

packages/core/src/integrations/http/client-subscriptions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
SPAN_STATUS_ERROR,
2121
SPAN_STATUS_UNSET,
2222
startInactiveSpan,
23+
SUPPRESS_TRACING_KEY,
2324
withActiveSpan,
2425
} from '../../tracing';
2526
import { debug } from '../../utils/debug-logger';
@@ -31,7 +32,7 @@ import type { HttpInstrumentationOptions, HttpClientRequest } from './types';
3132
import { DEBUG_BUILD } from '../../debug-build';
3233
import { LOG_PREFIX, HTTP_ON_CLIENT_REQUEST } from './constants';
3334
import type { ClientSubscriptionName } from './constants';
34-
import { getClient } from '../../currentScopes';
35+
import { getClient, getCurrentScope } from '../../currentScopes';
3536
import { hasSpansEnabled } from '../../utils/hasSpansEnabled';
3637

3738
type ChannelListener = (message: unknown, name: string | symbol) => void;
@@ -53,6 +54,11 @@ export function getHttpClientSubscriptions(options: HttpInstrumentationOptions):
5354
const onHttpClientRequestCreated: ChannelListener = (data: unknown): void => {
5455
const { request } = data as { request: HttpClientRequest };
5556

57+
// Skip if tracing is suppressed (e.g., inside Sentry.suppressTracing())
58+
if (getCurrentScope().getScopeData().sdkProcessingMetadata[SUPPRESS_TRACING_KEY] === true) {
59+
return;
60+
}
61+
5662
// check if request is ignored anyway
5763
if (options.ignoreOutgoingRequests?.(getRequestUrl(request), request)) {
5864
return;

packages/core/src/tracing/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export {
1313
withActiveSpan,
1414
suppressTracing,
1515
startNewTrace,
16+
SUPPRESS_TRACING_KEY,
1617
} from './trace';
1718
export {
1819
getDynamicSamplingContextFromClient,

packages/core/src/tracing/trace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { SPAN_STATUS_ERROR } from './spanstatus';
3636
import { setCapturedScopesOnSpan } from './utils';
3737
import type { Client } from '../client';
3838

39-
const SUPPRESS_TRACING_KEY = '__SENTRY_SUPPRESS_TRACING__';
39+
export const SUPPRESS_TRACING_KEY = '__SENTRY_SUPPRESS_TRACING__';
4040

4141
/**
4242
* Wraps a function with a transaction/span and finishes the span after the function is done.

packages/node-core/src/integrations/http/SentryHttpInstrumentation.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,13 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
214214
return moduleExports;
215215
};
216216

217-
// On Node < 22.12, trace propagation via diagnostics channel is not available,
218-
// so we fall back to monkey-patching without injecting trace headers.
219-
const legacyPatchOptions = { ...patchOptions, propagateTrace: false };
220-
221217
const wrapHttp = FULLY_SUPPORTS_HTTP_DIAGNOSTICS_CHANNEL
222218
? sub
223-
: (moduleExports: HttpModuleExport) => patchHttpModuleClient(moduleExports, legacyPatchOptions);
219+
: (moduleExports: HttpModuleExport) => patchHttpModuleClient(moduleExports, patchOptions);
224220

225221
const wrapHttps = FULLY_SUPPORTS_HTTP_DIAGNOSTICS_CHANNEL
226222
? sub
227-
: (moduleExports: HttpModuleExport) => patchHttpsModuleClient(moduleExports, legacyPatchOptions);
223+
: (moduleExports: HttpModuleExport) => patchHttpsModuleClient(moduleExports, patchOptions);
228224

229225
/**
230226
* You may be wondering why we register these diagnostics-channel listeners

packages/node-core/src/light/asyncLocalStorageStrategy.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { AsyncLocalStorage } from 'node:async_hooks';
22
import type { Scope } from '@sentry/core';
3-
import { getDefaultCurrentScope, getDefaultIsolationScope, setAsyncContextStrategy } from '@sentry/core';
3+
import {
4+
getDefaultCurrentScope,
5+
getDefaultIsolationScope,
6+
setAsyncContextStrategy,
7+
SUPPRESS_TRACING_KEY,
8+
} from '@sentry/core';
49

510
/**
611
* Sets the async context strategy to use AsyncLocalStorage.
@@ -62,7 +67,7 @@ export function setAsyncLocalStorageAsyncContextStrategy(): void {
6267
// In contrast to the browser, we can rely on async context isolation here
6368
function suppressTracing<T>(callback: () => T): T {
6469
return withScope(scope => {
65-
scope.setSDKProcessingMetadata({ __SENTRY_SUPPRESS_TRACING__: true });
70+
scope.setSDKProcessingMetadata({ [SUPPRESS_TRACING_KEY]: true });
6671
return callback();
6772
});
6873
}

0 commit comments

Comments
 (0)