Skip to content

Commit 59c8016

Browse files
committed
add tracePropagationTargets option
1 parent 24e2a27 commit 59c8016

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

packages/tracing/src/browser/request.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import {
1010

1111
import { getActiveTransaction, hasTracingEnabled } from '../utils';
1212

13+
// TODO (v8): Remove `tracingOrigins`
1314
export const DEFAULT_TRACING_ORIGINS = ['localhost', /^\//];
15+
export const DEFAULT_TRACE_PROPAGATION_TARGETS = ['localhost', /^\//];
1416

1517
/** Options for Request Instrumentation */
1618
export interface RequestInstrumentationOptions {
@@ -22,6 +24,14 @@ export interface RequestInstrumentationOptions {
2224
*/
2325
tracingOrigins: Array<string | RegExp>;
2426

27+
/**
28+
* List of strings and/or regexes used to determine which outgoing requests will have `sentry-trace` and `baggage`
29+
* headers attached.
30+
*
31+
* Default: ['localhost', /^\//] {@see DEFAULT_TRACE_PROPAGATION_TARGETS}
32+
*/
33+
tracePropagationTargets: Array<string | RegExp>;
34+
2535
/**
2636
* Flag to disable patching all together for fetch requests.
2737
*
@@ -99,19 +109,22 @@ export const defaultRequestInstrumentationOptions: RequestInstrumentationOptions
99109
traceFetch: true,
100110
traceXHR: true,
101111
tracingOrigins: DEFAULT_TRACING_ORIGINS,
112+
tracePropagationTargets: DEFAULT_TRACE_PROPAGATION_TARGETS,
102113
};
103114

104115
/** Registers span creators for xhr and fetch requests */
105116
export function instrumentOutgoingRequests(_options?: Partial<RequestInstrumentationOptions>): void {
106-
const { traceFetch, traceXHR, tracingOrigins, shouldCreateSpanForRequest } = {
117+
const { traceFetch, traceXHR, tracingOrigins, tracePropagationTargets, shouldCreateSpanForRequest } = {
107118
...defaultRequestInstrumentationOptions,
108119
..._options,
109120
};
110121

111122
const shouldCreateSpan =
112123
typeof shouldCreateSpanForRequest === 'function' ? shouldCreateSpanForRequest : (_: string) => true;
113124

114-
const shouldAttachHeaders = (url: string): boolean => tracingOrigins.some(origin => isMatchingPattern(url, origin));
125+
const shouldAttachHeaders = (url: string): boolean =>
126+
tracingOrigins.some(origin => isMatchingPattern(url, origin)) ||
127+
tracePropagationTargets.some(origin => isMatchingPattern(url, origin));
115128

116129
const spans: Record<string, Span> = {};
117130

0 commit comments

Comments
 (0)