@@ -10,6 +10,7 @@ import {
10
10
} from '@sentry/utils' ;
11
11
import type * as http from 'http' ;
12
12
import type * as https from 'https' ;
13
+ import { LRUMap } from 'lru_map' ;
13
14
14
15
import type { NodeClient } from '../client' ;
15
16
import type { RequestMethod , RequestMethodArgs } from './utils/http' ;
@@ -138,21 +139,22 @@ function _createWrappedRequestMethodFactory(
138
139
tracingOptions : TracingOptions | undefined ,
139
140
) : WrappedRequestMethodFactory {
140
141
// 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 ) ;
142
143
const headersUrlMap : Record < string , boolean > = { } ;
143
144
144
145
const shouldCreateSpan = ( url : string ) : boolean => {
145
146
if ( tracingOptions ?. shouldCreateSpanForRequest === undefined ) {
146
147
return true ;
147
148
}
148
149
149
- if ( createSpanUrlMap [ url ] ) {
150
- return createSpanUrlMap [ url ] ;
150
+ const cachedDecision = createSpanUrlMap . get ( url ) ;
151
+ if ( cachedDecision !== undefined ) {
152
+ return cachedDecision ;
151
153
}
152
154
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 ;
156
158
} ;
157
159
158
160
const shouldAttachTraceData = ( url : string ) : boolean => {
0 commit comments