1
1
/* eslint-disable max-lines */
2
2
3
3
import { DEFAULT_ENVIRONMENT , getClient , spanToJSON } from '@sentry/core' ;
4
- import type {
5
- DebugImage ,
6
- Envelope ,
7
- Event ,
8
- EventEnvelope ,
9
- Profile ,
10
- Span ,
11
- StackFrame ,
12
- StackParser ,
13
- ThreadCpuProfile ,
14
- } from '@sentry/types' ;
4
+ import type { DebugImage , Envelope , Event , EventEnvelope , Profile , Span , ThreadCpuProfile } from '@sentry/types' ;
15
5
import {
16
- GLOBAL_OBJ ,
17
6
browserPerformanceTimeOrigin ,
18
7
forEachEnvelopeItem ,
8
+ getDebugImagesForResources ,
19
9
logger ,
20
10
timestampInSeconds ,
21
11
uuid4 ,
@@ -352,17 +342,10 @@ export function findProfiledTransactionsFromEnvelope(envelope: Envelope): Event[
352
342
return events ;
353
343
}
354
344
355
- const debugIdStackParserCache = new WeakMap < StackParser , Map < string , StackFrame [ ] > > ( ) ;
356
345
/**
357
346
* Applies debug meta data to an event from a list of paths to resources (sourcemaps)
358
347
*/
359
348
export function applyDebugMetadata ( resource_paths : ReadonlyArray < string > ) : DebugImage [ ] {
360
- const debugIdMap = GLOBAL_OBJ . _sentryDebugIds ;
361
-
362
- if ( ! debugIdMap ) {
363
- return [ ] ;
364
- }
365
-
366
349
const client = getClient ( ) ;
367
350
const options = client && client . getOptions ( ) ;
368
351
const stackParser = options && options . stackParser ;
@@ -371,51 +354,7 @@ export function applyDebugMetadata(resource_paths: ReadonlyArray<string>): Debug
371
354
return [ ] ;
372
355
}
373
356
374
- let debugIdStackFramesCache : Map < string , StackFrame [ ] > ;
375
- const cachedDebugIdStackFrameCache = debugIdStackParserCache . get ( stackParser ) ;
376
- if ( cachedDebugIdStackFrameCache ) {
377
- debugIdStackFramesCache = cachedDebugIdStackFrameCache ;
378
- } else {
379
- debugIdStackFramesCache = new Map < string , StackFrame [ ] > ( ) ;
380
- debugIdStackParserCache . set ( stackParser , debugIdStackFramesCache ) ;
381
- }
382
-
383
- // Build a map of filename -> debug_id
384
- const filenameDebugIdMap = Object . keys ( debugIdMap ) . reduce < Record < string , string > > ( ( acc , debugIdStackTrace ) => {
385
- let parsedStack : StackFrame [ ] ;
386
-
387
- const cachedParsedStack = debugIdStackFramesCache . get ( debugIdStackTrace ) ;
388
- if ( cachedParsedStack ) {
389
- parsedStack = cachedParsedStack ;
390
- } else {
391
- parsedStack = stackParser ( debugIdStackTrace ) ;
392
- debugIdStackFramesCache . set ( debugIdStackTrace , parsedStack ) ;
393
- }
394
-
395
- for ( let i = parsedStack . length - 1 ; i >= 0 ; i -- ) {
396
- const stackFrame = parsedStack [ i ] ;
397
- const file = stackFrame && stackFrame . filename ;
398
-
399
- if ( stackFrame && file ) {
400
- acc [ file ] = debugIdMap [ debugIdStackTrace ] as string ;
401
- break ;
402
- }
403
- }
404
- return acc ;
405
- } , { } ) ;
406
-
407
- const images : DebugImage [ ] = [ ] ;
408
- for ( const path of resource_paths ) {
409
- if ( path && filenameDebugIdMap [ path ] ) {
410
- images . push ( {
411
- type : 'sourcemap' ,
412
- code_file : path ,
413
- debug_id : filenameDebugIdMap [ path ] as string ,
414
- } ) ;
415
- }
416
- }
417
-
418
- return images ;
357
+ return getDebugImagesForResources ( stackParser , resource_paths ) ;
419
358
}
420
359
421
360
/**
0 commit comments