Skip to content

Commit

Permalink
fix(tracing): Don't consider tracing origins when creating spans (#6039)
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish committed Oct 27, 2022
1 parent 6c8d6c3 commit b2948e8
Showing 1 changed file with 3 additions and 25 deletions.
28 changes: 3 additions & 25 deletions packages/tracing/src/browser/request.ts
Expand Up @@ -5,7 +5,6 @@ import {
BAGGAGE_HEADER_NAME,
dynamicSamplingContextToSentryBaggageHeader,
isInstanceOf,
isMatchingPattern,
} from '@sentry/utils';

import { getActiveTransaction, hasTracingEnabled } from '../utils';
Expand Down Expand Up @@ -104,34 +103,13 @@ export const defaultRequestInstrumentationOptions: RequestInstrumentationOptions
/** Registers span creators for xhr and fetch requests */
export function instrumentOutgoingRequests(_options?: Partial<RequestInstrumentationOptions>): void {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { traceFetch, traceXHR, tracingOrigins, shouldCreateSpanForRequest } = {
const { traceFetch, traceXHR, shouldCreateSpanForRequest } = {
...defaultRequestInstrumentationOptions,
..._options,
};

// We should cache url -> decision so that we don't have to compute
// regexp everytime we create a request.
const urlMap: Record<string, boolean> = {};

const defaultShouldCreateSpan = (url: string): boolean => {
if (urlMap[url]) {
return urlMap[url];
}
const origins = tracingOrigins;
urlMap[url] =
origins.some((origin: string | RegExp) => isMatchingPattern(url, origin)) &&
!isMatchingPattern(url, 'sentry_key');
return urlMap[url];
};

// We want that our users don't have to re-implement shouldCreateSpanForRequest themselves
// That's why we filter out already unwanted Spans from tracingOrigins
let shouldCreateSpan = defaultShouldCreateSpan;
if (typeof shouldCreateSpanForRequest === 'function') {
shouldCreateSpan = (url: string) => {
return defaultShouldCreateSpan(url) && shouldCreateSpanForRequest(url);
};
}
const shouldCreateSpan =
typeof shouldCreateSpanForRequest === 'function' ? shouldCreateSpanForRequest : (_: string) => true;

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

Expand Down

0 comments on commit b2948e8

Please sign in to comment.