From b571e79db8feef36372520b94f09324e53402251 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Thu, 27 Oct 2022 19:51:37 -0700 Subject: [PATCH] add `tracePropagationTargets` option --- packages/tracing/src/browser/request.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/tracing/src/browser/request.ts b/packages/tracing/src/browser/request.ts index d463a1353acc..de330b0b5de2 100644 --- a/packages/tracing/src/browser/request.ts +++ b/packages/tracing/src/browser/request.ts @@ -10,7 +10,9 @@ import { import { getActiveTransaction, hasTracingEnabled } from '../utils'; +// TODO (v8): Remove `tracingOrigins` export const DEFAULT_TRACING_ORIGINS = ['localhost', /^\//]; +export const DEFAULT_TRACE_PROPAGATION_TARGETS = ['localhost', /^\//]; /** Options for Request Instrumentation */ export interface RequestInstrumentationOptions { @@ -22,6 +24,13 @@ export interface RequestInstrumentationOptions { */ tracingOrigins: Array; + /** + * List of strings / regex used to define which outgoing requests the `sentry-trace` header will be attached to. + * + * Default: ['localhost', /^\//] {@see DEFAULT_TRACE_PROPAGATION_TARGETS} + */ + tracePropagationTargets: Array; + /** * Flag to disable patching all together for fetch requests. * @@ -99,11 +108,12 @@ export const defaultRequestInstrumentationOptions: RequestInstrumentationOptions traceFetch: true, traceXHR: true, tracingOrigins: DEFAULT_TRACING_ORIGINS, + tracePropagationTargets: DEFAULT_TRACE_PROPAGATION_TARGETS, }; /** Registers span creators for xhr and fetch requests */ export function instrumentOutgoingRequests(_options?: Partial): void { - const { traceFetch, traceXHR, tracingOrigins, shouldCreateSpanForRequest } = { + const { traceFetch, traceXHR, tracingOrigins, tracePropagationTargets, shouldCreateSpanForRequest } = { ...defaultRequestInstrumentationOptions, ..._options, }; @@ -111,7 +121,9 @@ export function instrumentOutgoingRequests(_options?: Partial true; - const shouldAttachHeaders = (url: string): boolean => tracingOrigins.some(origin => isMatchingPattern(url, origin)); + const shouldAttachHeaders = (url: string): boolean => + tracingOrigins.some(origin => isMatchingPattern(url, origin)) || + tracePropagationTargets.some(origin => isMatchingPattern(url, origin)); const spans: Record = {};