9
9
addProfilesToEnvelope ,
10
10
createProfilingEvent ,
11
11
findProfiledTransactionsFromEnvelope ,
12
- PROFILE_QUEUE ,
12
+ PROFILE_MAP ,
13
13
} from './utils' ;
14
14
15
15
/**
@@ -39,8 +39,7 @@ export class BrowserProfilingIntegration implements Integration {
39
39
40
40
client . on ( 'beforeEnvelope' , ( envelope ) : void => {
41
41
// if not profiles are in queue, there is nothing to add to the envelope.
42
-
43
- if ( ! PROFILE_QUEUE . length ) {
42
+ if ( ! PROFILE_MAP . size ) {
44
43
return ;
45
44
}
46
45
@@ -56,7 +55,7 @@ export class BrowserProfilingIntegration implements Integration {
56
55
profiledTransaction &&
57
56
profiledTransaction . contexts &&
58
57
profiledTransaction . contexts [ 'profile' ] &&
59
- profiledTransaction . contexts [ 'profile' ] [ 'profile_id' ] ;
58
+ profiledTransaction . contexts [ 'profile' ] [ 'profile_id' ] as string
60
59
61
60
if ( ! profile_id ) {
62
61
throw new TypeError ( '[Profiling] cannot find profile for a transaction without a profile context' ) ;
@@ -67,23 +66,15 @@ export class BrowserProfilingIntegration implements Integration {
67
66
delete profiledTransaction . contexts . profile ;
68
67
}
69
68
70
- // We need to find both a profile and a transaction event for the same profile_id.
71
- const profileIndex = PROFILE_QUEUE . findIndex ( p => p . profile_id === profile_id ) ;
72
- if ( profileIndex === - 1 ) {
73
- __DEBUG_BUILD__ && logger . log ( `[Profiling] Could not retrieve profile for transaction: ${ profile_id } ` ) ;
74
- continue ;
75
- }
76
-
77
- const cpuProfile = PROFILE_QUEUE [ profileIndex ] ;
78
- if ( ! cpuProfile ) {
69
+ const profile = PROFILE_MAP . get ( profile_id ) ;
70
+ if ( ! profile ) {
79
71
__DEBUG_BUILD__ && logger . log ( `[Profiling] Could not retrieve profile for transaction: ${ profile_id } ` ) ;
80
72
continue ;
81
73
}
82
74
83
- // Remove the profile from the queue.
84
- PROFILE_QUEUE . splice ( profileIndex , 1 ) ;
85
- const profileEvent = createProfilingEvent ( cpuProfile , profiledTransaction as ProfiledEvent ) ;
86
-
75
+ PROFILE_MAP . delete ( profile_id ) ;
76
+ const profileEvent = createProfilingEvent ( profile , profiledTransaction as ProfiledEvent ) ;
77
+
87
78
if ( profileEvent ) {
88
79
profilesToAddToEnvelope . push ( profileEvent ) ;
89
80
}
0 commit comments