From 22dee474ccb220954f4278fb9bab4767f7e4ff3a Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 10 Feb 2026 16:29:32 +0100 Subject: [PATCH 1/2] ref(core): Move `shouldPropagateTraceForUrl` from opentelemetry to core This function is needed by light mode integrations that don't use OpenTelemetry. Move it to @sentry/core and re-export from @sentry/opentelemetry for backwards compatibility. --- packages/core/src/index.ts | 1 + .../core/src/utils/tracePropagationTargets.ts | 34 ++++++++++++++++++ packages/opentelemetry/src/propagator.ts | 35 +++---------------- 3 files changed, 39 insertions(+), 31 deletions(-) create mode 100644 packages/core/src/utils/tracePropagationTargets.ts diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 30ace1803b1a..7f262e4762b3 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -92,6 +92,7 @@ export { _setSpanForScope as _INTERNAL_setSpanForScope } from './utils/spanOnSco export { parseSampleRate } from './utils/parseSampleRate'; export { applySdkMetadata } from './utils/sdkMetadata'; export { getTraceData } from './utils/traceData'; +export { shouldPropagateTraceForUrl } from './utils/tracePropagationTargets'; export { getTraceMetaTags } from './utils/meta'; export { debounce } from './utils/debounce'; export { diff --git a/packages/core/src/utils/tracePropagationTargets.ts b/packages/core/src/utils/tracePropagationTargets.ts new file mode 100644 index 000000000000..6c4f9c88c62e --- /dev/null +++ b/packages/core/src/utils/tracePropagationTargets.ts @@ -0,0 +1,34 @@ +import type { CoreOptions as Options } from '../types-hoist/options'; +import { debug } from './debug-logger'; +import type { LRUMap } from './lru'; +import { stringMatchesSomePattern } from './string'; + +const NOT_PROPAGATED_MESSAGE = + '[Tracing] Not injecting trace data for url because it does not match tracePropagationTargets:'; + +/** + * Check if a given URL should be propagated to or not. + * If no url is defined, or no trace propagation targets are defined, this will always return `true`. + * You can also optionally provide a decision map, to cache decisions and avoid repeated regex lookups. + */ +export function shouldPropagateTraceForUrl( + url: string | undefined, + tracePropagationTargets: Options['tracePropagationTargets'], + decisionMap?: LRUMap, +): boolean { + if (typeof url !== 'string' || !tracePropagationTargets) { + return true; + } + + const cachedDecision = decisionMap?.get(url); + if (cachedDecision !== undefined) { + !cachedDecision && debug.log(NOT_PROPAGATED_MESSAGE, url); + return cachedDecision; + } + + const decision = stringMatchesSomePattern(url, tracePropagationTargets); + decisionMap?.set(url, decision); + + !decision && debug.log(NOT_PROPAGATED_MESSAGE, url); + return decision; +} diff --git a/packages/opentelemetry/src/propagator.ts b/packages/opentelemetry/src/propagator.ts index 458fc7f2ac94..2b5873658706 100644 --- a/packages/opentelemetry/src/propagator.ts +++ b/packages/opentelemetry/src/propagator.ts @@ -2,7 +2,7 @@ import type { Baggage, Context, Span, SpanContext, TextMapGetter, TextMapSetter import { context, INVALID_TRACEID, propagation, trace, TraceFlags } from '@opentelemetry/api'; import { isTracingSuppressed, W3CBaggagePropagator } from '@opentelemetry/core'; import { ATTR_URL_FULL, SEMATTRS_HTTP_URL } from '@opentelemetry/semantic-conventions'; -import type { Client, continueTrace, DynamicSamplingContext, Options, Scope } from '@sentry/core'; +import type { Client, continueTrace, DynamicSamplingContext, Scope } from '@sentry/core'; import { baggageHeaderToDynamicSamplingContext, debug, @@ -18,8 +18,8 @@ import { propagationContextFromHeaders, SENTRY_BAGGAGE_KEY_PREFIX, shouldContinueTrace, + shouldPropagateTraceForUrl, spanToJSON, - stringMatchesSomePattern, } from '@sentry/core'; import { SENTRY_BAGGAGE_HEADER, SENTRY_TRACE_HEADER, SENTRY_TRACE_STATE_URL } from './constants'; import { DEBUG_BUILD } from './debug-build'; @@ -124,35 +124,8 @@ export class SentryPropagator extends W3CBaggagePropagator { } } -const NOT_PROPAGATED_MESSAGE = - '[Tracing] Not injecting trace data for url because it does not match tracePropagationTargets:'; - -/** - * Check if a given URL should be propagated to or not. - * If no url is defined, or no trace propagation targets are defined, this will always return `true`. - * You can also optionally provide a decision map, to cache decisions and avoid repeated regex lookups. - */ -export function shouldPropagateTraceForUrl( - url: string | undefined, - tracePropagationTargets: Options['tracePropagationTargets'], - decisionMap?: LRUMap, -): boolean { - if (typeof url !== 'string' || !tracePropagationTargets) { - return true; - } - - const cachedDecision = decisionMap?.get(url); - if (cachedDecision !== undefined) { - DEBUG_BUILD && !cachedDecision && debug.log(NOT_PROPAGATED_MESSAGE, url); - return cachedDecision; - } - - const decision = stringMatchesSomePattern(url, tracePropagationTargets); - decisionMap?.set(url, decision); - - DEBUG_BUILD && !decision && debug.log(NOT_PROPAGATED_MESSAGE, url); - return decision; -} +// Re-exported from @sentry/core for backwards compatibility +export { shouldPropagateTraceForUrl } from '@sentry/core'; /** * Get propagation injection data for the given context. From 970a0755ad89acb44d8fe49bd87706af0e1ff328 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 10 Feb 2026 16:46:27 +0100 Subject: [PATCH 2/2] Add DEBUG_BUILD guard to shouldPropagateTraceForUrl debug logs Restore the DEBUG_BUILD && prefix that was present in the original opentelemetry version, enabling bundlers to tree-shake the debug log calls and string constant in production builds. --- packages/core/src/utils/tracePropagationTargets.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/core/src/utils/tracePropagationTargets.ts b/packages/core/src/utils/tracePropagationTargets.ts index 6c4f9c88c62e..be3b6ce9aed8 100644 --- a/packages/core/src/utils/tracePropagationTargets.ts +++ b/packages/core/src/utils/tracePropagationTargets.ts @@ -1,3 +1,4 @@ +import { DEBUG_BUILD } from '../debug-build'; import type { CoreOptions as Options } from '../types-hoist/options'; import { debug } from './debug-logger'; import type { LRUMap } from './lru'; @@ -22,13 +23,13 @@ export function shouldPropagateTraceForUrl( const cachedDecision = decisionMap?.get(url); if (cachedDecision !== undefined) { - !cachedDecision && debug.log(NOT_PROPAGATED_MESSAGE, url); + DEBUG_BUILD && !cachedDecision && debug.log(NOT_PROPAGATED_MESSAGE, url); return cachedDecision; } const decision = stringMatchesSomePattern(url, tracePropagationTargets); decisionMap?.set(url, decision); - !decision && debug.log(NOT_PROPAGATED_MESSAGE, url); + DEBUG_BUILD && !decision && debug.log(NOT_PROPAGATED_MESSAGE, url); return decision; }