Skip to content

Commit b571e79

Browse files
committed
add tracePropagationTargets option
1 parent b4ebafe commit b571e79

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/tracing/src/browser/request.ts

+14-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,13 @@ export interface RequestInstrumentationOptions {
2224
*/
2325
tracingOrigins: Array<string | RegExp>;
2426

27+
/**
28+
* List of strings / regex used to define which outgoing requests the `sentry-trace` header will be attached to.
29+
*
30+
* Default: ['localhost', /^\//] {@see DEFAULT_TRACE_PROPAGATION_TARGETS}
31+
*/
32+
tracePropagationTargets: Array<string | RegExp>;
33+
2534
/**
2635
* Flag to disable patching all together for fetch requests.
2736
*
@@ -99,19 +108,22 @@ export const defaultRequestInstrumentationOptions: RequestInstrumentationOptions
99108
traceFetch: true,
100109
traceXHR: true,
101110
tracingOrigins: DEFAULT_TRACING_ORIGINS,
111+
tracePropagationTargets: DEFAULT_TRACE_PROPAGATION_TARGETS,
102112
};
103113

104114
/** Registers span creators for xhr and fetch requests */
105115
export function instrumentOutgoingRequests(_options?: Partial<RequestInstrumentationOptions>): void {
106-
const { traceFetch, traceXHR, tracingOrigins, shouldCreateSpanForRequest } = {
116+
const { traceFetch, traceXHR, tracingOrigins, tracePropagationTargets, shouldCreateSpanForRequest } = {
107117
...defaultRequestInstrumentationOptions,
108118
..._options,
109119
};
110120

111121
const shouldCreateSpan =
112122
typeof shouldCreateSpanForRequest === 'function' ? shouldCreateSpanForRequest : (_: string) => true;
113123

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

116128
const spans: Record<string, Span> = {};
117129

0 commit comments

Comments
 (0)