11/* eslint-disable max-lines */
22
33import { 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' ;
155import {
16- GLOBAL_OBJ ,
176 browserPerformanceTimeOrigin ,
187 forEachEnvelopeItem ,
8+ getDebugImagesForResources ,
199 logger ,
2010 timestampInSeconds ,
2111 uuid4 ,
@@ -352,17 +342,10 @@ export function findProfiledTransactionsFromEnvelope(envelope: Envelope): Event[
352342 return events ;
353343}
354344
355- const debugIdStackParserCache = new WeakMap < StackParser , Map < string , StackFrame [ ] > > ( ) ;
356345/**
357346 * Applies debug meta data to an event from a list of paths to resources (sourcemaps)
358347 */
359348export function applyDebugMetadata ( resource_paths : ReadonlyArray < string > ) : DebugImage [ ] {
360- const debugIdMap = GLOBAL_OBJ . _sentryDebugIds ;
361-
362- if ( ! debugIdMap ) {
363- return [ ] ;
364- }
365-
366349 const client = getClient ( ) ;
367350 const options = client && client . getOptions ( ) ;
368351 const stackParser = options && options . stackParser ;
@@ -371,51 +354,7 @@ export function applyDebugMetadata(resource_paths: ReadonlyArray<string>): Debug
371354 return [ ] ;
372355 }
373356
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 ) ;
419358}
420359
421360/**
0 commit comments