@@ -10,7 +10,9 @@ import {
10
10
11
11
import { getActiveTransaction , hasTracingEnabled } from '../utils' ;
12
12
13
+ // TODO (v8): Remove `tracingOrigins`
13
14
export const DEFAULT_TRACING_ORIGINS = [ 'localhost' , / ^ \/ / ] ;
15
+ export const DEFAULT_TRACE_PROPAGATION_TARGETS = [ 'localhost' , / ^ \/ / ] ;
14
16
15
17
/** Options for Request Instrumentation */
16
18
export interface RequestInstrumentationOptions {
@@ -22,6 +24,14 @@ export interface RequestInstrumentationOptions {
22
24
*/
23
25
tracingOrigins : Array < string | RegExp > ;
24
26
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
+
25
35
/**
26
36
* Flag to disable patching all together for fetch requests.
27
37
*
@@ -99,19 +109,22 @@ export const defaultRequestInstrumentationOptions: RequestInstrumentationOptions
99
109
traceFetch : true ,
100
110
traceXHR : true ,
101
111
tracingOrigins : DEFAULT_TRACING_ORIGINS ,
112
+ tracePropagationTargets : DEFAULT_TRACE_PROPAGATION_TARGETS ,
102
113
} ;
103
114
104
115
/** Registers span creators for xhr and fetch requests */
105
116
export function instrumentOutgoingRequests ( _options ?: Partial < RequestInstrumentationOptions > ) : void {
106
- const { traceFetch, traceXHR, tracingOrigins, shouldCreateSpanForRequest } = {
117
+ const { traceFetch, traceXHR, tracingOrigins, tracePropagationTargets , shouldCreateSpanForRequest } = {
107
118
...defaultRequestInstrumentationOptions ,
108
119
..._options ,
109
120
} ;
110
121
111
122
const shouldCreateSpan =
112
123
typeof shouldCreateSpanForRequest === 'function' ? shouldCreateSpanForRequest : ( _ : string ) => true ;
113
124
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 ) ) ;
115
128
116
129
const spans : Record < string , Span > = { } ;
117
130
0 commit comments