2
2
import type { Event , IntegrationFn , Profile , ProfileChunk , ProfilingIntegration , Span } from '@sentry/core' ;
3
3
import {
4
4
consoleSandbox ,
5
+ debug ,
5
6
defineIntegration ,
6
7
getCurrentScope ,
7
8
getGlobalScope ,
8
9
getIsolationScope ,
9
10
getRootSpan ,
10
- logger ,
11
11
LRUMap ,
12
12
spanToJSON ,
13
13
uuid4 ,
@@ -75,7 +75,7 @@ class ContinuousProfiler {
75
75
this . _legacyProfilerMode =
76
76
'profilesSampleRate' in options || 'profilesSampler' in options ? 'span' : 'continuous' ;
77
77
78
- DEBUG_BUILD && logger . log ( `[Profiling] Profiling mode is ${ this . _legacyProfilerMode } .` ) ;
78
+ DEBUG_BUILD && debug . log ( `[Profiling] Profiling mode is ${ this . _legacyProfilerMode } .` ) ;
79
79
80
80
switch ( this . _legacyProfilerMode ) {
81
81
case 'span' : {
@@ -88,7 +88,7 @@ class ContinuousProfiler {
88
88
}
89
89
default : {
90
90
DEBUG_BUILD &&
91
- logger . warn (
91
+ debug . warn (
92
92
`[Profiling] Unknown profiler mode: ${ this . _legacyProfilerMode } , profiler was not initialized` ,
93
93
) ;
94
94
break ;
@@ -100,7 +100,7 @@ class ContinuousProfiler {
100
100
case 'current' : {
101
101
this . _setupSpanChunkInstrumentation ( ) ;
102
102
103
- DEBUG_BUILD && logger . log ( `[Profiling] Profiling mode is ${ this . _profileLifecycle } .` ) ;
103
+ DEBUG_BUILD && debug . log ( `[Profiling] Profiling mode is ${ this . _profileLifecycle } .` ) ;
104
104
105
105
switch ( this . _profileLifecycle ) {
106
106
case 'trace' : {
@@ -113,14 +113,14 @@ class ContinuousProfiler {
113
113
}
114
114
default : {
115
115
DEBUG_BUILD &&
116
- logger . warn ( `[Profiling] Unknown profiler mode: ${ this . _profileLifecycle } , profiler was not initialized` ) ;
116
+ debug . warn ( `[Profiling] Unknown profiler mode: ${ this . _profileLifecycle } , profiler was not initialized` ) ;
117
117
break ;
118
118
}
119
119
}
120
120
break ;
121
121
}
122
122
default : {
123
- DEBUG_BUILD && logger . warn ( `[Profiling] Unknown profiler mode: ${ this . _mode } , profiler was not initialized` ) ;
123
+ DEBUG_BUILD && debug . warn ( `[Profiling] Unknown profiler mode: ${ this . _mode } , profiler was not initialized` ) ;
124
124
break ;
125
125
}
126
126
}
@@ -142,17 +142,17 @@ class ContinuousProfiler {
142
142
}
143
143
144
144
if ( ! this . _client ) {
145
- DEBUG_BUILD && logger . log ( '[Profiling] Failed to start, sentry client was never attached to the profiler.' ) ;
145
+ DEBUG_BUILD && debug . log ( '[Profiling] Failed to start, sentry client was never attached to the profiler.' ) ;
146
146
return ;
147
147
}
148
148
149
149
if ( this . _mode !== 'legacy' ) {
150
- DEBUG_BUILD && logger . log ( '[Profiling] Continuous profiling is not supported in the current mode.' ) ;
150
+ DEBUG_BUILD && debug . log ( '[Profiling] Continuous profiling is not supported in the current mode.' ) ;
151
151
return ;
152
152
}
153
153
154
154
if ( this . _legacyProfilerMode === 'span' ) {
155
- DEBUG_BUILD && logger . log ( '[Profiling] Calls to profiler.start() are not supported in span profiling mode.' ) ;
155
+ DEBUG_BUILD && debug . log ( '[Profiling] Calls to profiler.start() are not supported in span profiling mode.' ) ;
156
156
return ;
157
157
}
158
158
@@ -176,17 +176,17 @@ class ContinuousProfiler {
176
176
}
177
177
178
178
if ( ! this . _client ) {
179
- DEBUG_BUILD && logger . log ( '[Profiling] Failed to stop, sentry client was never attached to the profiler.' ) ;
179
+ DEBUG_BUILD && debug . log ( '[Profiling] Failed to stop, sentry client was never attached to the profiler.' ) ;
180
180
return ;
181
181
}
182
182
183
183
if ( this . _mode !== 'legacy' ) {
184
- DEBUG_BUILD && logger . log ( '[Profiling] Continuous profiling is not supported in the current mode.' ) ;
184
+ DEBUG_BUILD && debug . log ( '[Profiling] Continuous profiling is not supported in the current mode.' ) ;
185
185
return ;
186
186
}
187
187
188
188
if ( this . _legacyProfilerMode === 'span' ) {
189
- DEBUG_BUILD && logger . log ( '[Profiling] Calls to profiler.stop() are not supported in span profiling mode.' ) ;
189
+ DEBUG_BUILD && debug . log ( '[Profiling] Calls to profiler.stop() are not supported in span profiling mode.' ) ;
190
190
return ;
191
191
}
192
192
@@ -196,25 +196,25 @@ class ContinuousProfiler {
196
196
197
197
private _startProfiler ( ) : void {
198
198
if ( this . _mode !== 'current' ) {
199
- DEBUG_BUILD && logger . log ( '[Profiling] Continuous profiling is not supported in the current mode.' ) ;
199
+ DEBUG_BUILD && debug . log ( '[Profiling] Continuous profiling is not supported in the current mode.' ) ;
200
200
return ;
201
201
}
202
202
203
203
if ( this . _chunkData !== undefined ) {
204
- DEBUG_BUILD && logger . log ( '[Profiling] Profile session already running, no-op.' ) ;
204
+ DEBUG_BUILD && debug . log ( '[Profiling] Profile session already running, no-op.' ) ;
205
205
return ;
206
206
}
207
207
208
208
if ( this . _mode === 'current' ) {
209
209
if ( ! this . _sampled ) {
210
- DEBUG_BUILD && logger . log ( '[Profiling] Profile session not sampled, no-op.' ) ;
210
+ DEBUG_BUILD && debug . log ( '[Profiling] Profile session not sampled, no-op.' ) ;
211
211
return ;
212
212
}
213
213
}
214
214
215
215
if ( this . _profileLifecycle === 'trace' ) {
216
216
DEBUG_BUILD &&
217
- logger . log (
217
+ debug . log (
218
218
'[Profiling] You are using the trace profile lifecycle, manual calls to profiler.startProfiler() and profiler.stopProfiler() will be ignored.' ,
219
219
) ;
220
220
return ;
@@ -225,20 +225,20 @@ class ContinuousProfiler {
225
225
226
226
private _stopProfiler ( ) : void {
227
227
if ( this . _mode !== 'current' ) {
228
- DEBUG_BUILD && logger . log ( '[Profiling] Continuous profiling is not supported in the current mode.' ) ;
228
+ DEBUG_BUILD && debug . log ( '[Profiling] Continuous profiling is not supported in the current mode.' ) ;
229
229
return ;
230
230
}
231
231
232
232
if ( this . _profileLifecycle === 'trace' ) {
233
233
DEBUG_BUILD &&
234
- logger . log (
234
+ debug . log (
235
235
'[Profiling] You are using the trace profile lifecycle, manual calls to profiler.startProfiler() and profiler.stopProfiler() will be ignored.' ,
236
236
) ;
237
237
return ;
238
238
}
239
239
240
240
if ( ! this . _chunkData ) {
241
- DEBUG_BUILD && logger . log ( '[Profiling] No profile session running, no-op.' ) ;
241
+ DEBUG_BUILD && debug . log ( '[Profiling] No profile session running, no-op.' ) ;
242
242
return ;
243
243
}
244
244
@@ -251,7 +251,7 @@ class ContinuousProfiler {
251
251
private _startTraceLifecycleProfiling ( ) : void {
252
252
if ( ! this . _client ) {
253
253
DEBUG_BUILD &&
254
- logger . log (
254
+ debug . log (
255
255
'[Profiling] Failed to start trace lifecycle profiling, sentry client was never attached to the profiler.' ,
256
256
) ;
257
257
return ;
@@ -276,7 +276,7 @@ class ContinuousProfiler {
276
276
private _setupAutomaticSpanProfiling ( ) : void {
277
277
if ( ! this . _client ) {
278
278
DEBUG_BUILD &&
279
- logger . log (
279
+ debug . log (
280
280
'[Profiling] Failed to setup automatic span profiling, sentry client was never attached to the profiler.' ,
281
281
) ;
282
282
return ;
@@ -307,7 +307,7 @@ class ContinuousProfiler {
307
307
// Enqueue a timeout to prevent profiles from running over max duration.
308
308
const timeout = global . setTimeout ( ( ) => {
309
309
DEBUG_BUILD &&
310
- logger . log (
310
+ debug . log (
311
311
'[Profiling] max profile duration elapsed, stopping profiling for:' ,
312
312
spanToJSON ( span ) . description ,
313
313
) ;
@@ -371,7 +371,7 @@ class ContinuousProfiler {
371
371
372
372
const cpuProfile = takeFromProfileQueue ( profile_id ) ;
373
373
if ( ! cpuProfile ) {
374
- DEBUG_BUILD && logger . log ( `[Profiling] Could not retrieve profile for transaction: ${ profile_id } ` ) ;
374
+ DEBUG_BUILD && debug . log ( `[Profiling] Could not retrieve profile for transaction: ${ profile_id } ` ) ;
375
375
continue ;
376
376
}
377
377
@@ -406,13 +406,13 @@ class ContinuousProfiler {
406
406
// The client is not attached to the profiler if the user has not enabled continuous profiling.
407
407
// In this case, calling start() and stop() is a noop action.The reason this exists is because
408
408
// it makes the types easier to work with and avoids users having to do null checks.
409
- DEBUG_BUILD && logger . log ( '[Profiling] Profiler was never attached to the client.' ) ;
409
+ DEBUG_BUILD && debug . log ( '[Profiling] Profiler was never attached to the client.' ) ;
410
410
return ;
411
411
}
412
412
413
413
if ( this . _chunkData ) {
414
414
DEBUG_BUILD &&
415
- logger . log (
415
+ debug . log (
416
416
`[Profiling] Chunk with chunk_id ${ this . _chunkData . id } is still running, current chunk will be stopped a new chunk will be started.` ,
417
417
) ;
418
418
this . _stopChunkProfiling ( ) ;
@@ -426,49 +426,49 @@ class ContinuousProfiler {
426
426
*/
427
427
private _stopChunkProfiling ( ) : void {
428
428
if ( ! this . _chunkData ) {
429
- DEBUG_BUILD && logger . log ( '[Profiling] No chunk data found, no-op.' ) ;
429
+ DEBUG_BUILD && debug . log ( '[Profiling] No chunk data found, no-op.' ) ;
430
430
return ;
431
431
}
432
432
433
433
if ( this . _chunkData ?. timer ) {
434
434
global . clearTimeout ( this . _chunkData . timer ) ;
435
435
this . _chunkData . timer = undefined ;
436
- DEBUG_BUILD && logger . log ( `[Profiling] Stopping profiling chunk: ${ this . _chunkData . id } ` ) ;
436
+ DEBUG_BUILD && debug . log ( `[Profiling] Stopping profiling chunk: ${ this . _chunkData . id } ` ) ;
437
437
}
438
438
439
439
if ( ! this . _client ) {
440
440
DEBUG_BUILD &&
441
- logger . log ( '[Profiling] Failed to collect profile, sentry client was never attached to the profiler.' ) ;
441
+ debug . log ( '[Profiling] Failed to collect profile, sentry client was never attached to the profiler.' ) ;
442
442
this . _resetChunkData ( ) ;
443
443
return ;
444
444
}
445
445
446
446
if ( ! this . _chunkData ?. id ) {
447
447
DEBUG_BUILD &&
448
- logger . log ( `[Profiling] Failed to collect profile for: ${ this . _chunkData ?. id } , the chunk_id is missing.` ) ;
448
+ debug . log ( `[Profiling] Failed to collect profile for: ${ this . _chunkData ?. id } , the chunk_id is missing.` ) ;
449
449
this . _resetChunkData ( ) ;
450
450
return ;
451
451
}
452
452
453
453
const profile = CpuProfilerBindings . stopProfiling ( this . _chunkData . id , ProfileFormat . CHUNK ) ;
454
454
455
455
if ( ! profile ) {
456
- DEBUG_BUILD && logger . log ( `[Profiling] Failed to collect profile for: ${ this . _chunkData . id } ` ) ;
456
+ DEBUG_BUILD && debug . log ( `[Profiling] Failed to collect profile for: ${ this . _chunkData . id } ` ) ;
457
457
this . _resetChunkData ( ) ;
458
458
return ;
459
459
}
460
460
461
461
if ( ! this . _profilerId ) {
462
462
DEBUG_BUILD &&
463
- logger . log ( '[Profiling] Profile chunk does not contain a valid profiler_id, this is a bug in the SDK' ) ;
463
+ debug . log ( '[Profiling] Profile chunk does not contain a valid profiler_id, this is a bug in the SDK' ) ;
464
464
this . _resetChunkData ( ) ;
465
465
return ;
466
466
}
467
467
if ( profile ) {
468
- DEBUG_BUILD && logger . log ( `[Profiling] Sending profile chunk ${ this . _chunkData . id } .` ) ;
468
+ DEBUG_BUILD && debug . log ( `[Profiling] Sending profile chunk ${ this . _chunkData . id } .` ) ;
469
469
}
470
470
471
- DEBUG_BUILD && logger . log ( `[Profiling] Profile chunk ${ this . _chunkData . id } sent to Sentry.` ) ;
471
+ DEBUG_BUILD && debug . log ( `[Profiling] Profile chunk ${ this . _chunkData . id } sent to Sentry.` ) ;
472
472
const chunk = createProfilingChunkEvent (
473
473
this . _client ,
474
474
this . _client . getOptions ( ) ,
@@ -482,7 +482,7 @@ class ContinuousProfiler {
482
482
) ;
483
483
484
484
if ( ! chunk ) {
485
- DEBUG_BUILD && logger . log ( `[Profiling] Failed to create profile chunk for: ${ this . _chunkData . id } ` ) ;
485
+ DEBUG_BUILD && debug . log ( `[Profiling] Failed to create profile chunk for: ${ this . _chunkData . id } ` ) ;
486
486
this . _resetChunkData ( ) ;
487
487
return ;
488
488
}
@@ -502,13 +502,13 @@ class ContinuousProfiler {
502
502
private _flush ( chunk : ProfileChunk ) : void {
503
503
if ( ! this . _client ) {
504
504
DEBUG_BUILD &&
505
- logger . log ( '[Profiling] Failed to collect profile, sentry client was never attached to the profiler.' ) ;
505
+ debug . log ( '[Profiling] Failed to collect profile, sentry client was never attached to the profiler.' ) ;
506
506
return ;
507
507
}
508
508
509
509
const transport = this . _client . getTransport ( ) ;
510
510
if ( ! transport ) {
511
- DEBUG_BUILD && logger . log ( '[Profiling] No transport available to send profile chunk.' ) ;
511
+ DEBUG_BUILD && debug . log ( '[Profiling] No transport available to send profile chunk.' ) ;
512
512
return ;
513
513
}
514
514
@@ -518,7 +518,7 @@ class ContinuousProfiler {
518
518
519
519
const envelope = makeProfileChunkEnvelope ( 'node' , chunk , metadata ?. sdk , tunnel , dsn ) ;
520
520
transport . send ( envelope ) . then ( null , reason => {
521
- DEBUG_BUILD && logger . error ( 'Error while sending profile chunk envelope:' , reason ) ;
521
+ DEBUG_BUILD && debug . error ( 'Error while sending profile chunk envelope:' , reason ) ;
522
522
} ) ;
523
523
}
524
524
@@ -528,7 +528,7 @@ class ContinuousProfiler {
528
528
*/
529
529
private _startChunkProfiling ( ) : void {
530
530
if ( this . _chunkData ) {
531
- DEBUG_BUILD && logger . log ( '[Profiling] Chunk is already running, no-op.' ) ;
531
+ DEBUG_BUILD && debug . log ( '[Profiling] Chunk is already running, no-op.' ) ;
532
532
return ;
533
533
}
534
534
@@ -537,12 +537,12 @@ class ContinuousProfiler {
537
537
const chunk = this . _initializeChunk ( traceId ) ;
538
538
539
539
CpuProfilerBindings . startProfiling ( chunk . id ) ;
540
- DEBUG_BUILD && logger . log ( `[Profiling] starting profiling chunk: ${ chunk . id } ` ) ;
540
+ DEBUG_BUILD && debug . log ( `[Profiling] starting profiling chunk: ${ chunk . id } ` ) ;
541
541
542
542
chunk . timer = global . setTimeout ( ( ) => {
543
- DEBUG_BUILD && logger . log ( `[Profiling] Stopping profiling chunk: ${ chunk . id } ` ) ;
543
+ DEBUG_BUILD && debug . log ( `[Profiling] Stopping profiling chunk: ${ chunk . id } ` ) ;
544
544
this . _stopChunkProfiling ( ) ;
545
- DEBUG_BUILD && logger . log ( '[Profiling] Starting new profiling chunk.' ) ;
545
+ DEBUG_BUILD && debug . log ( '[Profiling] Starting new profiling chunk.' ) ;
546
546
setImmediate ( this . _restartChunkProfiling . bind ( this ) ) ;
547
547
} , CHUNK_INTERVAL_MS ) ;
548
548
@@ -557,9 +557,7 @@ class ContinuousProfiler {
557
557
private _setupSpanChunkInstrumentation ( ) : void {
558
558
if ( ! this . _client ) {
559
559
DEBUG_BUILD &&
560
- logger . log (
561
- '[Profiling] Failed to initialize span profiling, sentry client was never attached to the profiler.' ,
562
- ) ;
560
+ debug . log ( '[Profiling] Failed to initialize span profiling, sentry client was never attached to the profiler.' ) ;
563
561
return ;
564
562
}
565
563
@@ -648,7 +646,7 @@ export const _nodeProfilingIntegration = ((): ProfilingIntegration<NodeClient> =
648
646
name : 'ProfilingIntegration' ,
649
647
_profiler : new ContinuousProfiler ( ) ,
650
648
setup ( client : NodeClient ) {
651
- DEBUG_BUILD && logger . log ( '[Profiling] Profiling integration setup.' ) ;
649
+ DEBUG_BUILD && debug . log ( '[Profiling] Profiling integration setup.' ) ;
652
650
this . _profiler . initialize ( client ) ;
653
651
return ;
654
652
} ,
0 commit comments