Skip to content

Commit 0eb81bc

Browse files
authored
fix(node): Add LRU map for tracePropagationTargets calculation (#8130)
1 parent ae9ebe3 commit 0eb81bc

File tree

1 file changed

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

1 file changed

+7
-6
lines changed

packages/node/src/integrations/http.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function _createWrappedRequestMethodFactory(
138138
): WrappedRequestMethodFactory {
139139
// We're caching results so we don't have to recompute regexp every time we create a request.
140140
const createSpanUrlMap = new LRUMap<string, boolean>(100);
141-
const headersUrlMap: Record<string, boolean> = {};
141+
const headersUrlMap = new LRUMap<string, boolean>(100);
142142

143143
const shouldCreateSpan = (url: string): boolean => {
144144
if (tracingOptions?.shouldCreateSpanForRequest === undefined) {
@@ -160,13 +160,14 @@ function _createWrappedRequestMethodFactory(
160160
return true;
161161
}
162162

163-
if (headersUrlMap[url]) {
164-
return headersUrlMap[url];
163+
const cachedDecision = headersUrlMap.get(url);
164+
if (cachedDecision !== undefined) {
165+
return cachedDecision;
165166
}
166167

167-
headersUrlMap[url] = stringMatchesSomePattern(url, tracingOptions.tracePropagationTargets);
168-
169-
return headersUrlMap[url];
168+
const decision = stringMatchesSomePattern(url, tracingOptions.tracePropagationTargets);
169+
headersUrlMap.set(url, decision);
170+
return decision;
170171
};
171172

172173
return function wrappedRequestMethodFactory(originalRequestMethod: OriginalRequestMethod): WrappedRequestMethod {

0 commit comments

Comments
 (0)