@@ -119,25 +119,30 @@ function getTraceId(event: Event): string {
119119 * Creates a profiling event envelope from a Sentry event.
120120 */
121121export function createProfilePayload (
122- event : ProfiledEvent ,
123- processedProfile : JSSelfProfile ,
124122 profile_id : string ,
123+ start_timestamp : number | undefined ,
124+ processed_profile : JSSelfProfile ,
125+ event : ProfiledEvent ,
125126) : Profile {
126127 if ( event . type !== 'transaction' ) {
127128 // createProfilingEventEnvelope should only be called for transactions,
128129 // we type guard this behavior with isProfiledTransactionEvent.
129130 throw new TypeError ( 'Profiling events may only be attached to transactions, this should never occur.' ) ;
130131 }
131132
132- if ( processedProfile === undefined || processedProfile === null ) {
133+ if ( processed_profile === undefined || processed_profile === null ) {
133134 throw new TypeError (
134- `Cannot construct profiling event envelope without a valid profile. Got ${ processedProfile } instead.` ,
135+ `Cannot construct profiling event envelope without a valid profile. Got ${ processed_profile } instead.` ,
135136 ) ;
136137 }
137138
138139 const traceId = getTraceId ( event ) ;
139- const enrichedThreadProfile = enrichWithThreadInformation ( processedProfile ) ;
140- const transactionStartMs = typeof event . start_timestamp === 'number' ? event . start_timestamp * 1000 : Date . now ( ) ;
140+ const enrichedThreadProfile = enrichWithThreadInformation ( processed_profile ) ;
141+ const transactionStartMs = start_timestamp
142+ ? start_timestamp
143+ : typeof event . start_timestamp === 'number'
144+ ? event . start_timestamp * 1000
145+ : Date . now ( ) ;
141146 const transactionEndMs = typeof event . timestamp === 'number' ? event . timestamp * 1000 : Date . now ( ) ;
142147
143148 const profile : Profile = {
@@ -164,7 +169,7 @@ export function createProfilePayload(
164169 is_emulator : false ,
165170 } ,
166171 debug_meta : {
167- images : applyDebugMetadata ( processedProfile . resources ) ,
172+ images : applyDebugMetadata ( processed_profile . resources ) ,
168173 } ,
169174 profile : enrichedThreadProfile ,
170175 transactions : [
@@ -575,12 +580,17 @@ export function shouldProfileTransaction(transaction: Transaction): boolean {
575580 * @param event
576581 * @returns {Profile | null }
577582 */
578- export function createProfilingEvent ( profile_id : string , profile : JSSelfProfile , event : ProfiledEvent ) : Profile | null {
583+ export function createProfilingEvent (
584+ profile_id : string ,
585+ start_timestamp : number | undefined ,
586+ profile : JSSelfProfile ,
587+ event : ProfiledEvent ,
588+ ) : Profile | null {
579589 if ( ! isValidProfile ( profile ) ) {
580590 return null ;
581591 }
582592
583- return createProfilePayload ( event , profile , profile_id ) ;
593+ return createProfilePayload ( profile_id , start_timestamp , profile , event ) ;
584594}
585595
586596const PROFILE_MAP : Map < string , JSSelfProfile > = new Map ( ) ;
0 commit comments