11import * 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' ;
33import { env , versions } from 'process' ;
44import { isMainThread , threadId } from 'worker_threads' ;
55
6- import { getCurrentHub } from '@sentry/node' ;
76import { GLOBAL_OBJ , forEachEnvelopeItem , logger } from '@sentry/utils' ;
87
98import { DEBUG_BUILD } from './debug-build' ;
10- import type { Profile , ProfiledEvent , RawThreadCpuProfile , ThreadCpuProfile } from './types' ;
9+ import type { Profile , RawThreadCpuProfile , ThreadCpuProfile } from './types' ;
1110import type { DebugImage } from './types' ;
1211
1312// 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
6160 } ;
6261}
6362
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-
10563/**
10664 * Creates a profiling envelope item, if the profile does not pass validation, returns null.
10765 * @param {RawThreadCpuProfile }
10866 * @param {Event }
10967 * @returns {Profile | null }
11068 */
111- export function createProfilingEvent ( profile : RawThreadCpuProfile , event : Event ) : Profile | null {
69+ export function createProfilingEvent ( client : Client , profile : RawThreadCpuProfile , event : Event ) : Profile | null {
11270 if ( ! isValidProfile ( profile ) ) {
11371 return null ;
11472 }
11573
116- return createProfilePayload ( profile , {
74+ return createProfilePayload ( client , profile , {
11775 release : event . release ?? '' ,
11876 environment : event . environment ?? '' ,
11977 event_id : event . event_id ?? '' ,
@@ -132,6 +90,7 @@ export function createProfilingEvent(profile: RawThreadCpuProfile, event: Event)
13290 */
13391
13492function createProfilePayload (
93+ client : Client ,
13594 cpuProfile : RawThreadCpuProfile ,
13695 {
13796 release,
@@ -185,7 +144,7 @@ function createProfilePayload(
185144 is_emulator : false ,
186145 } ,
187146 debug_meta : {
188- images : applyDebugMetadata ( cpuProfile . resources ) ,
147+ images : applyDebugMetadata ( client , cpuProfile . resources ) ,
189148 } ,
190149 profile : enrichedThreadProfile ,
191150 transaction : {
@@ -310,18 +269,13 @@ const debugIdStackParserCache = new WeakMap<StackParser, Map<string, StackFrame[
310269 * @param {string[] } resource_paths
311270 * @returns {DebugImage[] }
312271 */
313- export function applyDebugMetadata ( resource_paths : ReadonlyArray < string > ) : DebugImage [ ] {
272+ export function applyDebugMetadata ( client : Client , resource_paths : ReadonlyArray < string > ) : DebugImage [ ] {
314273 const debugIdMap = GLOBAL_OBJ . _sentryDebugIds ;
315-
316274 if ( ! debugIdMap ) {
317275 return [ ] ;
318276 }
319277
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 ( ) ;
325279
326280 if ( ! options || ! options . stackParser ) {
327281 return [ ] ;
0 commit comments