Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tracing): Don't consider tracingOrigins when creating spans #6039

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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