88 makeSession ,
99 updateSession ,
1010} from '@sentry/core' ;
11- import type { Event , ScopeData , Session , StackFrame } from '@sentry/types' ;
11+ import type { DebugImage , Event , ScopeData , Session , StackFrame } from '@sentry/types' ;
1212import {
1313 callFrameToStackFrame ,
1414 normalizeUrlToBase ,
@@ -26,6 +26,7 @@ type VoidFunction = () => void;
2626const options : WorkerStartData = workerData ;
2727let session : Session | undefined ;
2828let hasSentAnrEvent = false ;
29+ let mainDebugImages : Record < string , string > = { } ;
2930
3031function log ( msg : string ) : void {
3132 if ( options . debug ) {
@@ -87,6 +88,35 @@ function prepareStackFrames(stackFrames: StackFrame[] | undefined): StackFrame[]
8788 return strippedFrames ;
8889}
8990
91+ function applyDebugMeta ( event : Event ) : void {
92+ if ( Object . keys ( mainDebugImages ) . length === 0 ) {
93+ return ;
94+ }
95+
96+ const filenameToDebugId = new Map < string , string > ( ) ;
97+
98+ for ( const exception of event . exception ?. values || [ ] ) {
99+ for ( const frame of exception . stacktrace ?. frames || [ ] ) {
100+ const filename = frame . abs_path || frame . filename ;
101+ if ( filename && mainDebugImages [ filename ] ) {
102+ filenameToDebugId . set ( filename , mainDebugImages [ filename ] as string ) ;
103+ }
104+ }
105+ }
106+
107+ if ( filenameToDebugId . size > 0 ) {
108+ const images : DebugImage [ ] = [ ] ;
109+ for ( const [ filename , debugId ] of filenameToDebugId . entries ( ) ) {
110+ images . push ( {
111+ type : 'sourcemap' ,
112+ code_file : filename ,
113+ debug_id : debugId ,
114+ } ) ;
115+ }
116+ event . debug_meta = { images } ;
117+ }
118+ }
119+
90120function applyScopeToEvent ( event : Event , scope : ScopeData ) : void {
91121 applyScopeDataToEvent ( event , scope ) ;
92122
@@ -140,6 +170,8 @@ async function sendAnrEvent(frames?: StackFrame[], scope?: ScopeData): Promise<v
140170 applyScopeToEvent ( event , scope ) ;
141171 }
142172
173+ applyDebugMeta ( event ) ;
174+
143175 const envelope = createEventEnvelope ( event , options . dsn , options . sdkMetadata , options . tunnel ) ;
144176 // Log the envelope to aid in testing
145177 log ( JSON . stringify ( envelope ) ) ;
@@ -272,10 +304,14 @@ function watchdogTimeout(): void {
272304
273305const { poll } = watchdogTimer ( createHrTimer , options . pollInterval , options . anrThreshold , watchdogTimeout ) ;
274306
275- parentPort ?. on ( 'message' , ( msg : { session : Session | undefined } ) => {
307+ parentPort ?. on ( 'message' , ( msg : { session : Session | undefined ; debugImages ?: Record < string , string > } ) => {
276308 if ( msg . session ) {
277309 session = makeSession ( msg . session ) ;
278310 }
279311
312+ if ( msg . debugImages ) {
313+ mainDebugImages = msg . debugImages ;
314+ }
315+
280316 poll ( ) ;
281317} ) ;
0 commit comments