1
1
import * as os from 'os' ;
2
- import type { Context , Envelope , Event , StackFrame , StackParser } from '@sentry/types' ;
2
+ import type { Client , Context , Envelope , Event , StackFrame , StackParser } from '@sentry/types' ;
3
3
import { env , versions } from 'process' ;
4
4
import { isMainThread , threadId } from 'worker_threads' ;
5
5
6
- import { getCurrentHub } from '@sentry/node' ;
7
6
import { GLOBAL_OBJ , forEachEnvelopeItem , logger } from '@sentry/utils' ;
8
7
9
8
import { DEBUG_BUILD } from './debug-build' ;
10
- import type { Profile , ProfiledEvent , RawThreadCpuProfile , ThreadCpuProfile } from './types' ;
9
+ import type { Profile , RawThreadCpuProfile , ThreadCpuProfile } from './types' ;
11
10
import type { DebugImage } from './types' ;
12
11
13
12
// We require the file because if we import it, it will be included in the bundle.
@@ -61,59 +60,18 @@ export function enrichWithThreadInformation(profile: ThreadCpuProfile | RawThrea
61
60
} ;
62
61
}
63
62
64
- /**
65
- * Creates a profiling event envelope from a Sentry event. If profile does not pass
66
- * validation, returns null.
67
- * @param {Event }
68
- * @returns {Profile | null }
69
- */
70
- export function createProfilingEventFromTransaction ( event : ProfiledEvent ) : Profile | null {
71
- if ( event . type !== 'transaction' ) {
72
- // createProfilingEventEnvelope should only be called for transactions,
73
- // we type guard this behavior with isProfiledTransactionEvent.
74
- throw new TypeError ( 'Profiling events may only be attached to transactions, this should never occur.' ) ;
75
- }
76
-
77
- const rawProfile = event . sdkProcessingMetadata [ 'profile' ] ;
78
- if ( rawProfile === undefined || rawProfile === null ) {
79
- throw new TypeError (
80
- `Cannot construct profiling event envelope without a valid profile. Got ${ rawProfile } instead.` ,
81
- ) ;
82
- }
83
-
84
- if ( ! rawProfile . profile_id ) {
85
- throw new TypeError (
86
- `Cannot construct profiling event envelope without a valid profile id. Got ${ rawProfile . profile_id } instead.` ,
87
- ) ;
88
- }
89
-
90
- if ( ! isValidProfile ( rawProfile ) ) {
91
- return null ;
92
- }
93
-
94
- return createProfilePayload ( rawProfile , {
95
- release : event . release ?? '' ,
96
- environment : event . environment ?? '' ,
97
- event_id : event . event_id ?? '' ,
98
- transaction : event . transaction ?? '' ,
99
- start_timestamp : event . start_timestamp ? event . start_timestamp * 1000 : Date . now ( ) ,
100
- trace_id : event . contexts ?. [ 'trace' ] ?. [ 'trace_id' ] ?? '' ,
101
- profile_id : rawProfile . profile_id ,
102
- } ) ;
103
- }
104
-
105
63
/**
106
64
* Creates a profiling envelope item, if the profile does not pass validation, returns null.
107
65
* @param {RawThreadCpuProfile }
108
66
* @param {Event }
109
67
* @returns {Profile | null }
110
68
*/
111
- export function createProfilingEvent ( profile : RawThreadCpuProfile , event : Event ) : Profile | null {
69
+ export function createProfilingEvent ( client : Client , profile : RawThreadCpuProfile , event : Event ) : Profile | null {
112
70
if ( ! isValidProfile ( profile ) ) {
113
71
return null ;
114
72
}
115
73
116
- return createProfilePayload ( profile , {
74
+ return createProfilePayload ( client , profile , {
117
75
release : event . release ?? '' ,
118
76
environment : event . environment ?? '' ,
119
77
event_id : event . event_id ?? '' ,
@@ -132,6 +90,7 @@ export function createProfilingEvent(profile: RawThreadCpuProfile, event: Event)
132
90
*/
133
91
134
92
function createProfilePayload (
93
+ client : Client ,
135
94
cpuProfile : RawThreadCpuProfile ,
136
95
{
137
96
release,
@@ -185,7 +144,7 @@ function createProfilePayload(
185
144
is_emulator : false ,
186
145
} ,
187
146
debug_meta : {
188
- images : applyDebugMetadata ( cpuProfile . resources ) ,
147
+ images : applyDebugMetadata ( client , cpuProfile . resources ) ,
189
148
} ,
190
149
profile : enrichedThreadProfile ,
191
150
transaction : {
@@ -310,18 +269,13 @@ const debugIdStackParserCache = new WeakMap<StackParser, Map<string, StackFrame[
310
269
* @param {string[] } resource_paths
311
270
* @returns {DebugImage[] }
312
271
*/
313
- export function applyDebugMetadata ( resource_paths : ReadonlyArray < string > ) : DebugImage [ ] {
272
+ export function applyDebugMetadata ( client : Client , resource_paths : ReadonlyArray < string > ) : DebugImage [ ] {
314
273
const debugIdMap = GLOBAL_OBJ . _sentryDebugIds ;
315
-
316
274
if ( ! debugIdMap ) {
317
275
return [ ] ;
318
276
}
319
277
320
- // eslint-disable-next-line deprecation/deprecation
321
- const hub = getCurrentHub ( ) ;
322
- // eslint-disable-next-line deprecation/deprecation
323
- const client = hub . getClient ( ) ;
324
- const options = client && client . getOptions ( ) ;
278
+ const options = client . getOptions ( ) ;
325
279
326
280
if ( ! options || ! options . stackParser ) {
327
281
return [ ] ;
0 commit comments