From bf803e8de48a23c9a722da2b66d75d18376b7512 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 16 May 2023 10:54:21 +0200 Subject: [PATCH] fix(node): Add LRU map for tracePropagationTargets calculation --- packages/node/src/integrations/http.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/node/src/integrations/http.ts b/packages/node/src/integrations/http.ts index 41fe2a68c058..5e2ce9e253a2 100644 --- a/packages/node/src/integrations/http.ts +++ b/packages/node/src/integrations/http.ts @@ -138,7 +138,7 @@ function _createWrappedRequestMethodFactory( ): WrappedRequestMethodFactory { // We're caching results so we don't have to recompute regexp every time we create a request. const createSpanUrlMap = new LRUMap(100); - const headersUrlMap: Record = {}; + const headersUrlMap = new LRUMap(100); const shouldCreateSpan = (url: string): boolean => { if (tracingOptions?.shouldCreateSpanForRequest === undefined) { @@ -160,13 +160,14 @@ function _createWrappedRequestMethodFactory( return true; } - if (headersUrlMap[url]) { - return headersUrlMap[url]; + const cachedDecision = headersUrlMap.get(url); + if (cachedDecision !== undefined) { + return cachedDecision; } - headersUrlMap[url] = stringMatchesSomePattern(url, tracingOptions.tracePropagationTargets); - - return headersUrlMap[url]; + const decision = stringMatchesSomePattern(url, tracingOptions.tracePropagationTargets); + headersUrlMap.set(url, decision); + return decision; }; return function wrappedRequestMethodFactory(originalRequestMethod: OriginalRequestMethod): WrappedRequestMethod {