Skip to content

Commit 42d4d4b

Browse files
authored
fix(node): Add lru cache to http integration span map (#7064)
1 parent 17db8e2 commit 42d4d4b

File tree

1 file changed

+8
-6
lines changed
  • packages/node/src/integrations

1 file changed

+8
-6
lines changed

packages/node/src/integrations/http.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from '@sentry/utils';
1111
import type * as http from 'http';
1212
import type * as https from 'https';
13+
import { LRUMap } from 'lru_map';
1314

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

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

149-
if (createSpanUrlMap[url]) {
150-
return createSpanUrlMap[url];
150+
const cachedDecision = createSpanUrlMap.get(url);
151+
if (cachedDecision !== undefined) {
152+
return cachedDecision;
151153
}
152154

153-
createSpanUrlMap[url] = tracingOptions.shouldCreateSpanForRequest(url);
154-
155-
return createSpanUrlMap[url];
155+
const decision = tracingOptions.shouldCreateSpanForRequest(url);
156+
createSpanUrlMap.set(url, decision);
157+
return decision;
156158
};
157159

158160
const shouldAttachTraceData = (url: string): boolean => {

0 commit comments

Comments
 (0)