8
8
makeSession ,
9
9
updateSession ,
10
10
} from '@sentry/core' ;
11
- import type { Event , ScopeData , Session , StackFrame } from '@sentry/types' ;
11
+ import type { DebugImage , Event , ScopeData , Session , StackFrame } from '@sentry/types' ;
12
12
import {
13
13
callFrameToStackFrame ,
14
14
normalizeUrlToBase ,
@@ -26,6 +26,7 @@ type VoidFunction = () => void;
26
26
const options : WorkerStartData = workerData ;
27
27
let session : Session | undefined ;
28
28
let hasSentAnrEvent = false ;
29
+ let mainDebugImages : Record < string , string > = { } ;
29
30
30
31
function log ( msg : string ) : void {
31
32
if ( options . debug ) {
@@ -87,6 +88,35 @@ function prepareStackFrames(stackFrames: StackFrame[] | undefined): StackFrame[]
87
88
return strippedFrames ;
88
89
}
89
90
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
+
90
120
function applyScopeToEvent ( event : Event , scope : ScopeData ) : void {
91
121
applyScopeDataToEvent ( event , scope ) ;
92
122
@@ -140,6 +170,8 @@ async function sendAnrEvent(frames?: StackFrame[], scope?: ScopeData): Promise<v
140
170
applyScopeToEvent ( event , scope ) ;
141
171
}
142
172
173
+ applyDebugMeta ( event ) ;
174
+
143
175
const envelope = createEventEnvelope ( event , options . dsn , options . sdkMetadata , options . tunnel ) ;
144
176
// Log the envelope to aid in testing
145
177
log ( JSON . stringify ( envelope ) ) ;
@@ -272,10 +304,14 @@ function watchdogTimeout(): void {
272
304
273
305
const { poll } = watchdogTimer ( createHrTimer , options . pollInterval , options . anrThreshold , watchdogTimeout ) ;
274
306
275
- parentPort ?. on ( 'message' , ( msg : { session : Session | undefined } ) => {
307
+ parentPort ?. on ( 'message' , ( msg : { session : Session | undefined ; debugImages ?: Record < string , string > } ) => {
276
308
if ( msg . session ) {
277
309
session = makeSession ( msg . session ) ;
278
310
}
279
311
312
+ if ( msg . debugImages ) {
313
+ mainDebugImages = msg . debugImages ;
314
+ }
315
+
280
316
poll ( ) ;
281
317
} ) ;
0 commit comments