Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/node/src/integrations/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@sentry/utils';
import type * as http from 'http';
import type * as https from 'https';
import { LRUMap } from 'lru_map';

import type { NodeClient } from '../client';
import type { RequestMethod, RequestMethodArgs } from './utils/http';
Expand Down Expand Up @@ -138,21 +139,22 @@ function _createWrappedRequestMethodFactory(
tracingOptions: TracingOptions | undefined,
): WrappedRequestMethodFactory {
// We're caching results so we don't have to recompute regexp every time we create a request.
const createSpanUrlMap: Record<string, boolean> = {};
const createSpanUrlMap = new LRUMap<string, boolean>(100);
const headersUrlMap: Record<string, boolean> = {};

const shouldCreateSpan = (url: string): boolean => {
if (tracingOptions?.shouldCreateSpanForRequest === undefined) {
return true;
}

if (createSpanUrlMap[url]) {
return createSpanUrlMap[url];
const cachedDecision = createSpanUrlMap.get(url);
if (cachedDecision !== undefined) {
return cachedDecision;
}

createSpanUrlMap[url] = tracingOptions.shouldCreateSpanForRequest(url);

return createSpanUrlMap[url];
const decision = tracingOptions.shouldCreateSpanForRequest(url);
createSpanUrlMap.set(url, decision);
return decision;
};

const shouldAttachTraceData = (url: string): boolean => {
Expand Down