1- import type { Envelope , Event , Profile } from '@sentry/types' ;
2- import { forEachEnvelopeItem , logger } from '@sentry/utils' ;
1+ import type { DebugImage , Envelope , Event , Profile } from '@sentry/types' ;
2+ import { forEachEnvelopeItem , GLOBAL_OBJ , logger } from '@sentry/utils' ;
33
4+ import { DEFAULT_BUNDLE_NAME } from './hermes' ;
45import type { RawThreadCpuProfile } from './types' ;
56
67/**
@@ -136,7 +137,7 @@ function createProfilePayload(
136137 const profile : Profile = {
137138 event_id : profile_id ,
138139 timestamp : new Date ( start_timestamp ) . toISOString ( ) ,
139- platform : 'node ' ,
140+ platform : 'javascript ' ,
140141 version : '1' ,
141142 release : release ,
142143 environment : environment ,
@@ -163,11 +164,47 @@ function createProfilePayload(
163164 trace_id : trace_id || '' ,
164165 active_thread_id : cpuProfile . active_thread_id ,
165166 } ,
167+ debug_meta : {
168+ images : getDebugMetadata ( ) ,
169+ } ,
166170 } ;
167171
168172 return profile ;
169173}
170174
175+ /**
176+ * Returns debug meta images of the loaded bundle.
177+ */
178+ export function getDebugMetadata ( ) : DebugImage [ ] {
179+ if ( ! DEFAULT_BUNDLE_NAME ) {
180+ return [ ] ;
181+ }
182+
183+ const debugIdMap = GLOBAL_OBJ . _sentryDebugIds ;
184+ if ( ! debugIdMap ) {
185+ return [ ] ;
186+ }
187+
188+ const debugIdsKeys = Object . keys ( debugIdMap ) ;
189+ if ( ! debugIdsKeys . length ) {
190+ return [ ] ;
191+ }
192+
193+ if ( debugIdsKeys . length > 1 ) {
194+ logger . warn (
195+ '[Profiling] Multiple debug images found, but only one one bundle is supported. Using the first one...' ,
196+ ) ;
197+ }
198+
199+ return [
200+ {
201+ code_file : DEFAULT_BUNDLE_NAME ,
202+ debug_id : debugIdMap [ debugIdsKeys [ 0 ] ] ,
203+ type : 'sourcemap' ,
204+ } ,
205+ ] ;
206+ }
207+
171208/**
172209 * Adds items to envelope if they are not already present - mutates the envelope.
173210 * @param envelope
0 commit comments