From 59c801670d6e07fe17f58e589ba37447a6150f95 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 | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/tracing/src/browser/request.ts b/packages/tracing/src/browser/request.ts index d463a1353acc..973161c595d3 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,14 @@ export interface RequestInstrumentationOptions { */ tracingOrigins: Array; + /** + * List of strings and/or regexes used to determine which outgoing requests will have `sentry-trace` and `baggage` + * headers attached. + * + * Default: ['localhost', /^\//] {@see DEFAULT_TRACE_PROPAGATION_TARGETS} + */ + tracePropagationTargets: Array; + /** * Flag to disable patching all together for fetch requests. * @@ -99,11 +109,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 +122,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 = {};