@@ -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,13 @@ export interface RequestInstrumentationOptions {
22
24
*/
23
25
tracingOrigins : Array < string | RegExp > ;
24
26
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
+
25
34
/**
26
35
* Flag to disable patching all together for fetch requests.
27
36
*
@@ -99,19 +108,22 @@ export const defaultRequestInstrumentationOptions: RequestInstrumentationOptions
99
108
traceFetch : true ,
100
109
traceXHR : true ,
101
110
tracingOrigins : DEFAULT_TRACING_ORIGINS ,
111
+ tracePropagationTargets : DEFAULT_TRACE_PROPAGATION_TARGETS ,
102
112
} ;
103
113
104
114
/** Registers span creators for xhr and fetch requests */
105
115
export function instrumentOutgoingRequests ( _options ?: Partial < RequestInstrumentationOptions > ) : void {
106
- const { traceFetch, traceXHR, tracingOrigins, shouldCreateSpanForRequest } = {
116
+ const { traceFetch, traceXHR, tracingOrigins, tracePropagationTargets , shouldCreateSpanForRequest } = {
107
117
...defaultRequestInstrumentationOptions ,
108
118
..._options ,
109
119
} ;
110
120
111
121
const shouldCreateSpan =
112
122
typeof shouldCreateSpanForRequest === 'function' ? shouldCreateSpanForRequest : ( _ : string ) => true ;
113
123
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 ) ) ;
115
127
116
128
const spans : Record < string , Span > = { } ;
117
129
0 commit comments