1- import * as Sentry from '@sentry/node-experimental ' ;
1+ import { NodeClient , defaultStackParser , flush , makeNodeTransport , setCurrentClient , startInactiveSpan } from '@sentry/node' ;
22
3- import { getMainCarrier } from '@sentry/core' ;
3+ import { getMainCarrier , } from '@sentry/core' ;
44import type { Transport } from '@sentry/types' ;
55import { GLOBAL_OBJ , createEnvelope , logger } from '@sentry/utils' ;
66import { CpuProfilerBindings } from '../src/cpu_profiler' ;
77import { _nodeProfilingIntegration } from '../src/integration' ;
88
9- function makeClientWithHooks ( ) : [ Sentry . NodeClient , Transport ] {
9+ function makeClientWithHooks ( ) : [ NodeClient , Transport ] {
1010 const integration = _nodeProfilingIntegration ( ) ;
11- const client = new Sentry . NodeClient ( {
12- stackParser : Sentry . defaultStackParser ,
11+ const client = new NodeClient ( {
12+ stackParser : defaultStackParser ,
1313 tracesSampleRate : 1 ,
1414 profilesSampleRate : 1 ,
1515 debug : true ,
1616 environment : 'test-environment' ,
1717 dsn : 'https://7fa19397baaf433f919fbe02228d5470@o1137848.ingest.sentry.io/6625302' ,
1818 integrations : [ integration ] ,
1919 transport : _opts =>
20- Sentry . makeNodeTransport ( {
20+ makeNodeTransport ( {
2121 url : 'https://7fa19397baaf433f919fbe02228d5470@o1137848.ingest.sentry.io/6625302' ,
2222 recordDroppedEvent : ( ) => {
2323 return undefined ;
@@ -45,24 +45,24 @@ describe('spanProfileUtils', () => {
4545
4646 it ( 'pulls environment from sdk init' , async ( ) => {
4747 const [ client , transport ] = makeClientWithHooks ( ) ;
48- Sentry . setCurrentClient ( client ) ;
48+ setCurrentClient ( client ) ;
4949 client . init ( ) ;
5050
5151 const transportSpy = jest . spyOn ( transport , 'send' ) . mockReturnValue ( Promise . resolve ( { } ) ) ;
5252
53- const transaction = Sentry . startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
53+ const transaction = startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
5454 await wait ( 500 ) ;
5555 transaction . end ( ) ;
5656
57- await Sentry . flush ( 1000 ) ;
57+ await flush ( 1000 ) ;
5858 expect ( transportSpy . mock . calls ?. [ 0 ] ?. [ 0 ] ?. [ 1 ] ?. [ 0 ] ?. [ 1 ] ) . toMatchObject ( { environment : 'test-environment' } ) ;
5959 } ) ;
6060
6161 it ( 'logger warns user if there are insufficient samples and discards the profile' , async ( ) => {
6262 const logSpy = jest . spyOn ( logger , 'log' ) ;
6363
6464 const [ client , transport ] = makeClientWithHooks ( ) ;
65- Sentry . setCurrentClient ( client ) ;
65+ setCurrentClient ( client ) ;
6666 client . init ( ) ;
6767
6868 jest . spyOn ( CpuProfilerBindings , 'stopProfiling' ) . mockImplementation ( ( ) => {
@@ -84,10 +84,10 @@ describe('spanProfileUtils', () => {
8484
8585 jest . spyOn ( transport , 'send' ) . mockReturnValue ( Promise . resolve ( { } ) ) ;
8686
87- const transaction = Sentry . startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
87+ const transaction = startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
8888 transaction . end ( ) ;
8989
90- await Sentry . flush ( 1000 ) ;
90+ await flush ( 1000 ) ;
9191
9292 expect ( logSpy ) . toHaveBeenCalledWith ( '[Profiling] Discarding profile because it contains less than 2 samples' ) ;
9393
@@ -100,7 +100,7 @@ describe('spanProfileUtils', () => {
100100 const logSpy = jest . spyOn ( logger , 'log' ) ;
101101
102102 const [ client , transport ] = makeClientWithHooks ( ) ;
103- Sentry . setCurrentClient ( client ) ;
103+ setCurrentClient ( client ) ;
104104 client . init ( ) ;
105105
106106 jest . spyOn ( CpuProfilerBindings , 'stopProfiling' ) . mockImplementation ( ( ) => {
@@ -127,48 +127,48 @@ describe('spanProfileUtils', () => {
127127
128128 jest . spyOn ( transport , 'send' ) . mockReturnValue ( Promise . resolve ( { } ) ) ;
129129
130- const transaction = Sentry . startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' , traceId : 'boop' } ) ;
130+ const transaction = startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' , traceId : 'boop' } ) ;
131131 await wait ( 500 ) ;
132132 transaction . end ( ) ;
133133
134- await Sentry . flush ( 1000 ) ;
134+ await flush ( 1000 ) ;
135135
136136 expect ( logSpy ) . toHaveBeenCalledWith ( '[Profiling] Invalid traceId: ' + 'boop' + ' on profiled event' ) ;
137137 } ) ;
138138
139139 describe ( 'with hooks' , ( ) => {
140140 it ( 'calls profiler when transaction is started/stopped' , async ( ) => {
141141 const [ client , transport ] = makeClientWithHooks ( ) ;
142- Sentry . setCurrentClient ( client ) ;
142+ setCurrentClient ( client ) ;
143143 client . init ( ) ;
144144
145145 const startProfilingSpy = jest . spyOn ( CpuProfilerBindings , 'startProfiling' ) ;
146146 const stopProfilingSpy = jest . spyOn ( CpuProfilerBindings , 'stopProfiling' ) ;
147147
148148 jest . spyOn ( transport , 'send' ) . mockReturnValue ( Promise . resolve ( { } ) ) ;
149149
150- const transaction = Sentry . startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
150+ const transaction = startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
151151 await wait ( 500 ) ;
152152 transaction . end ( ) ;
153153
154- await Sentry . flush ( 1000 ) ;
154+ await flush ( 1000 ) ;
155155
156156 expect ( startProfilingSpy ) . toHaveBeenCalledTimes ( 1 ) ;
157157 expect ( ( stopProfilingSpy . mock . calls [ stopProfilingSpy . mock . calls . length - 1 ] ?. [ 0 ] as string ) . length ) . toBe ( 32 ) ;
158158 } ) ;
159159
160160 it ( 'sends profile in the same envelope as transaction' , async ( ) => {
161161 const [ client , transport ] = makeClientWithHooks ( ) ;
162- Sentry . setCurrentClient ( client ) ;
162+ setCurrentClient ( client ) ;
163163 client . init ( ) ;
164164
165165 const transportSpy = jest . spyOn ( transport , 'send' ) . mockReturnValue ( Promise . resolve ( { } ) ) ;
166166
167- const transaction = Sentry . startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
167+ const transaction = startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
168168 await wait ( 500 ) ;
169169 transaction . end ( ) ;
170170
171- await Sentry . flush ( 1000 ) ;
171+ await flush ( 1000 ) ;
172172
173173 // One for profile, the other for transaction
174174 expect ( transportSpy ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -177,7 +177,7 @@ describe('spanProfileUtils', () => {
177177
178178 it ( 'does not crash if transaction has no profile context or it is invalid' , async ( ) => {
179179 const [ client ] = makeClientWithHooks ( ) ;
180- Sentry . setCurrentClient ( client ) ;
180+ setCurrentClient ( client ) ;
181181 client . init ( ) ;
182182
183183 // @ts -expect-error transaction is partial
@@ -201,7 +201,7 @@ describe('spanProfileUtils', () => {
201201
202202 it ( 'if transaction was profiled, but profiler returned null' , async ( ) => {
203203 const [ client , transport ] = makeClientWithHooks ( ) ;
204- Sentry . setCurrentClient ( client ) ;
204+ setCurrentClient ( client ) ;
205205 client . init ( ) ;
206206
207207 jest . spyOn ( CpuProfilerBindings , 'stopProfiling' ) . mockReturnValue ( null ) ;
@@ -211,11 +211,11 @@ describe('spanProfileUtils', () => {
211211 return Promise . resolve ( { } ) ;
212212 } ) ;
213213
214- const transaction = Sentry . startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
214+ const transaction = startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
215215 await wait ( 500 ) ;
216216 transaction . end ( ) ;
217217
218- await Sentry . flush ( 1000 ) ;
218+ await flush ( 1000 ) ;
219219
220220 // Only transaction is sent
221221 expect ( transportSpy . mock . calls ?. [ 0 ] ?. [ 0 ] ?. [ 1 ] ?. [ 0 ] ?. [ 0 ] ) . toMatchObject ( { type : 'transaction' } ) ;
@@ -224,18 +224,18 @@ describe('spanProfileUtils', () => {
224224
225225 it ( 'emits preprocessEvent for profile' , async ( ) => {
226226 const [ client ] = makeClientWithHooks ( ) ;
227- Sentry . setCurrentClient ( client ) ;
227+ setCurrentClient ( client ) ;
228228 client . init ( ) ;
229229
230230 const onPreprocessEvent = jest . fn ( ) ;
231231
232232 client . on ( 'preprocessEvent' , onPreprocessEvent ) ;
233233
234- const transaction = Sentry . startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
234+ const transaction = startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
235235 await wait ( 500 ) ;
236236 transaction . end ( ) ;
237237
238- await Sentry . flush ( 1000 ) ;
238+ await flush ( 1000 ) ;
239239
240240 expect ( onPreprocessEvent . mock . calls [ 1 ] [ 0 ] ) . toMatchObject ( {
241241 profile : {
@@ -250,10 +250,10 @@ describe('spanProfileUtils', () => {
250250 const stopProfilingSpy = jest . spyOn ( CpuProfilerBindings , 'stopProfiling' ) ;
251251
252252 const [ client ] = makeClientWithHooks ( ) ;
253- Sentry . setCurrentClient ( client ) ;
253+ setCurrentClient ( client ) ;
254254 client . init ( ) ;
255255
256- const transaction = Sentry . startInactiveSpan ( { forceTransaction : true , name : 'txn' } ) ;
256+ const transaction = startInactiveSpan ( { forceTransaction : true , name : 'txn' } ) ;
257257 transaction . end ( ) ;
258258 transaction . end ( ) ;
259259 expect ( stopProfilingSpy ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -289,16 +289,16 @@ describe('spanProfileUtils', () => {
289289 } ) ;
290290
291291 const [ client , transport ] = makeClientWithHooks ( ) ;
292- Sentry . setCurrentClient ( client ) ;
292+ setCurrentClient ( client ) ;
293293 client . init ( ) ;
294294
295295 const transportSpy = jest . spyOn ( transport , 'send' ) . mockReturnValue ( Promise . resolve ( { } ) ) ;
296296
297- const transaction = Sentry . startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
297+ const transaction = startInactiveSpan ( { forceTransaction : true , name : 'profile_hub' } ) ;
298298 await wait ( 500 ) ;
299299 transaction . end ( ) ;
300300
301- await Sentry . flush ( 1000 ) ;
301+ await flush ( 1000 ) ;
302302
303303 expect ( transportSpy . mock . calls ?. [ 0 ] ?. [ 0 ] ?. [ 1 ] ?. [ 1 ] ?. [ 1 ] ) . toMatchObject ( {
304304 debug_meta : {
0 commit comments