Skip to content

Commit e70a84a

Browse files
committed
fix(tracing): Pass tracePropagationTargets to instrumentOutgoingRequests
1 parent 955a1b2 commit e70a84a

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

packages/tracing/src/browser/browsertracing.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
112112
): void;
113113
}
114114

115-
const DEFAULT_BROWSER_TRACING_OPTIONS = {
115+
const DEFAULT_BROWSER_TRACING_OPTIONS: BrowserTracingOptions = {
116116
idleTimeout: DEFAULT_IDLE_TIMEOUT,
117117
finalTimeout: DEFAULT_FINAL_TIMEOUT,
118118
heartbeatInterval: DEFAULT_HEARTBEAT_INTERVAL,
@@ -153,6 +153,15 @@ export class BrowserTracing implements Integration {
153153
..._options,
154154
};
155155

156+
// TODO (v8): remove this block after tracingOrigins is removed
157+
// Set tracePropagationTargets from tracingOrigins if specified by the user
158+
// In case both are specified, tracePropagationTargets takes precedence
159+
// eslint-disable-next-line deprecation/deprecation
160+
if (_options && !_options.tracePropagationTargets && _options.tracingOrigins) {
161+
// eslint-disable-next-line deprecation/deprecation
162+
this.options.tracePropagationTargets = _options.tracingOrigins;
163+
}
164+
156165
const { _metricOptions } = this.options;
157166
startTrackingWebVitals(_metricOptions && _metricOptions._reportAllChanges);
158167
if (this.options._experiments?.enableLongTask) {
@@ -174,8 +183,7 @@ export class BrowserTracing implements Integration {
174183
markBackgroundTransactions,
175184
traceFetch,
176185
traceXHR,
177-
// eslint-disable-next-line deprecation/deprecation
178-
tracingOrigins,
186+
tracePropagationTargets,
179187
shouldCreateSpanForRequest,
180188
} = this.options;
181189

@@ -189,7 +197,12 @@ export class BrowserTracing implements Integration {
189197
registerBackgroundTabDetection();
190198
}
191199

192-
instrumentOutgoingRequests({ traceFetch, traceXHR, tracingOrigins, shouldCreateSpanForRequest });
200+
instrumentOutgoingRequests({
201+
traceFetch,
202+
traceXHR,
203+
tracePropagationTargets,
204+
shouldCreateSpanForRequest,
205+
});
193206
}
194207

195208
/** Create routing idle transaction. */

packages/tracing/src/browser/request.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const defaultRequestInstrumentationOptions: RequestInstrumentationOptions
113113
/** Registers span creators for xhr and fetch requests */
114114
export function instrumentOutgoingRequests(_options?: Partial<RequestInstrumentationOptions>): void {
115115
// eslint-disable-next-line deprecation/deprecation
116-
const { traceFetch, traceXHR, tracingOrigins, tracePropagationTargets, shouldCreateSpanForRequest } = {
116+
const { traceFetch, traceXHR, tracePropagationTargets, shouldCreateSpanForRequest } = {
117117
traceFetch: defaultRequestInstrumentationOptions.traceFetch,
118118
traceXHR: defaultRequestInstrumentationOptions.traceXHR,
119119
..._options,
@@ -122,8 +122,7 @@ export function instrumentOutgoingRequests(_options?: Partial<RequestInstrumenta
122122
const shouldCreateSpan =
123123
typeof shouldCreateSpanForRequest === 'function' ? shouldCreateSpanForRequest : (_: string) => true;
124124

125-
const shouldAttachHeadersWithTargets = (url: string): boolean =>
126-
shouldAttachHeaders(url, tracingOrigins, tracePropagationTargets);
125+
const shouldAttachHeadersWithTargets = (url: string): boolean => shouldAttachHeaders(url, tracePropagationTargets);
127126

128127
const spans: Record<string, Span> = {};
129128

@@ -147,17 +146,8 @@ export function instrumentOutgoingRequests(_options?: Partial<RequestInstrumenta
147146
*
148147
* TODO (v8): Remove `tracingOrigins` which should drastically simplify this function.
149148
*/
150-
export function shouldAttachHeaders(
151-
url: string,
152-
tracePropagationTargets: (string | RegExp)[] | undefined,
153-
tracingOrigins: (string | RegExp)[] | undefined,
154-
): boolean {
155-
// TODO (v8): Replace the entire code below with this one-liner:
156-
// return stringMatchesSomePattern(url, tracePropagationTargets || DEFAULT_TRACE_PROPAGATION_TARGETS);
157-
if (tracePropagationTargets || tracingOrigins) {
158-
return stringMatchesSomePattern(url, tracePropagationTargets || tracingOrigins);
159-
}
160-
return stringMatchesSomePattern(url, DEFAULT_TRACE_PROPAGATION_TARGETS);
149+
export function shouldAttachHeaders(url: string, tracePropagationTargets: (string | RegExp)[] | undefined): boolean {
150+
return stringMatchesSomePattern(url, tracePropagationTargets || DEFAULT_TRACE_PROPAGATION_TARGETS);
161151
}
162152

163153
/**

0 commit comments

Comments
 (0)