Skip to content

Commit

Permalink
fix(node): Add LRU map for tracePropagationTargets calculation (#8130)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad committed May 16, 2023
1 parent ae9ebe3 commit 0eb81bc
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/node/src/integrations/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, boolean>(100);
const headersUrlMap: Record<string, boolean> = {};
const headersUrlMap = new LRUMap<string, boolean>(100);

const shouldCreateSpan = (url: string): boolean => {
if (tracingOptions?.shouldCreateSpanForRequest === undefined) {
Expand All @@ -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 {
Expand Down

0 comments on commit 0eb81bc

Please sign in to comment.