@@ -119,25 +119,30 @@ function getTraceId(event: Event): string {
119
119
* Creates a profiling event envelope from a Sentry event.
120
120
*/
121
121
export function createProfilePayload (
122
- event : ProfiledEvent ,
123
- processedProfile : JSSelfProfile ,
124
122
profile_id : string ,
123
+ start_timestamp : number | undefined ,
124
+ processed_profile : JSSelfProfile ,
125
+ event : ProfiledEvent ,
125
126
) : Profile {
126
127
if ( event . type !== 'transaction' ) {
127
128
// createProfilingEventEnvelope should only be called for transactions,
128
129
// we type guard this behavior with isProfiledTransactionEvent.
129
130
throw new TypeError ( 'Profiling events may only be attached to transactions, this should never occur.' ) ;
130
131
}
131
132
132
- if ( processedProfile === undefined || processedProfile === null ) {
133
+ if ( processed_profile === undefined || processed_profile === null ) {
133
134
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.` ,
135
136
) ;
136
137
}
137
138
138
139
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 ( ) ;
141
146
const transactionEndMs = typeof event . timestamp === 'number' ? event . timestamp * 1000 : Date . now ( ) ;
142
147
143
148
const profile : Profile = {
@@ -164,7 +169,7 @@ export function createProfilePayload(
164
169
is_emulator : false ,
165
170
} ,
166
171
debug_meta : {
167
- images : applyDebugMetadata ( processedProfile . resources ) ,
172
+ images : applyDebugMetadata ( processed_profile . resources ) ,
168
173
} ,
169
174
profile : enrichedThreadProfile ,
170
175
transactions : [
@@ -575,12 +580,17 @@ export function shouldProfileTransaction(transaction: Transaction): boolean {
575
580
* @param event
576
581
* @returns {Profile | null }
577
582
*/
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 {
579
589
if ( ! isValidProfile ( profile ) ) {
580
590
return null ;
581
591
}
582
592
583
- return createProfilePayload ( event , profile , profile_id ) ;
593
+ return createProfilePayload ( profile_id , start_timestamp , profile , event ) ;
584
594
}
585
595
586
596
const PROFILE_MAP : Map < string , JSSelfProfile > = new Map ( ) ;
0 commit comments