Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node): Add LRU map for tracePropagationTargets calculation #8130

Merged
merged 1 commit into from
May 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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