11import type { StackFrame , StackLineParser , StackLineParserFn , StackParser } from '@sentry/types' ;
22
3+ import { GLOBAL_OBJ } from './worldwide' ;
4+
35const STACKTRACE_LIMIT = 50 ;
46
7+ type DebugIdFilename = string ;
8+ type DebugId = string ;
9+
10+ const debugIdParserCache = new Map < StackLineParserFn , Map < DebugIdFilename , DebugId > > ( ) ;
11+
512/**
613 * Creates a stack parser with the supplied line parsers
714 *
@@ -15,6 +22,28 @@ export function createStackParser(...parsers: StackLineParser[]): StackParser {
1522 return ( stack : string , skipFirst : number = 0 ) : StackFrame [ ] => {
1623 const frames : StackFrame [ ] = [ ] ;
1724
25+ for ( const parser of sortedParsers ) {
26+ let debugIdCache = debugIdParserCache . get ( parser ) ;
27+ if ( ! debugIdCache ) {
28+ debugIdCache = new Map ( ) ;
29+ debugIdParserCache . set ( parser , debugIdCache ) ;
30+ }
31+
32+ const debugIdMap = GLOBAL_OBJ . _sentryDebugIds ;
33+
34+ if ( debugIdMap ) {
35+ Object . keys ( debugIdMap ) . forEach ( debugIdStackTrace => {
36+ debugIdStackTrace . split ( '\n' ) . forEach ( line => {
37+ const frame = parser ( line ) ;
38+ if ( frame && frame . filename ) {
39+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
40+ debugIdCache ! . set ( frame . filename , debugIdMap [ debugIdStackTrace ] ) ;
41+ }
42+ } ) ;
43+ } ) ;
44+ }
45+ }
46+
1847 for ( const line of stack . split ( '\n' ) . slice ( skipFirst ) ) {
1948 // Ignore lines over 1kb as they are unlikely to be stack frames.
2049 // Many of the regular expressions use backtracking which results in run time that increases exponentially with
@@ -32,6 +61,14 @@ export function createStackParser(...parsers: StackLineParser[]): StackParser {
3261 const frame = parser ( cleanedLine ) ;
3362
3463 if ( frame ) {
64+ const debugIdCache = debugIdParserCache . get ( parser ) ;
65+ if ( debugIdCache && frame . filename ) {
66+ const cachedDebugId = debugIdCache . get ( frame . filename ) ;
67+ if ( cachedDebugId ) {
68+ frame . debug_id = cachedDebugId ;
69+ }
70+ }
71+
3572 frames . push ( frame ) ;
3673 break ;
3774 }
0 commit comments