Skip to content

Commit e07cdfd

Browse files
ref(profiling-node): Use debug instead of logger (#16959)
resolves #16941 --------- Co-authored-by: Cursor Agent <[email protected]>
1 parent 92e55a9 commit e07cdfd

File tree

4 files changed

+62
-64
lines changed

4 files changed

+62
-64
lines changed

packages/profiling-node/src/integration.ts

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
import type { Event, IntegrationFn, Profile, ProfileChunk, ProfilingIntegration, Span } from '@sentry/core';
33
import {
44
consoleSandbox,
5+
debug,
56
defineIntegration,
67
getCurrentScope,
78
getGlobalScope,
89
getIsolationScope,
910
getRootSpan,
10-
logger,
1111
LRUMap,
1212
spanToJSON,
1313
uuid4,
@@ -75,7 +75,7 @@ class ContinuousProfiler {
7575
this._legacyProfilerMode =
7676
'profilesSampleRate' in options || 'profilesSampler' in options ? 'span' : 'continuous';
7777

78-
DEBUG_BUILD && logger.log(`[Profiling] Profiling mode is ${this._legacyProfilerMode}.`);
78+
DEBUG_BUILD && debug.log(`[Profiling] Profiling mode is ${this._legacyProfilerMode}.`);
7979

8080
switch (this._legacyProfilerMode) {
8181
case 'span': {
@@ -88,7 +88,7 @@ class ContinuousProfiler {
8888
}
8989
default: {
9090
DEBUG_BUILD &&
91-
logger.warn(
91+
debug.warn(
9292
`[Profiling] Unknown profiler mode: ${this._legacyProfilerMode}, profiler was not initialized`,
9393
);
9494
break;
@@ -100,7 +100,7 @@ class ContinuousProfiler {
100100
case 'current': {
101101
this._setupSpanChunkInstrumentation();
102102

103-
DEBUG_BUILD && logger.log(`[Profiling] Profiling mode is ${this._profileLifecycle}.`);
103+
DEBUG_BUILD && debug.log(`[Profiling] Profiling mode is ${this._profileLifecycle}.`);
104104

105105
switch (this._profileLifecycle) {
106106
case 'trace': {
@@ -113,14 +113,14 @@ class ContinuousProfiler {
113113
}
114114
default: {
115115
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`);
117117
break;
118118
}
119119
}
120120
break;
121121
}
122122
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`);
124124
break;
125125
}
126126
}
@@ -142,17 +142,17 @@ class ContinuousProfiler {
142142
}
143143

144144
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.');
146146
return;
147147
}
148148

149149
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.');
151151
return;
152152
}
153153

154154
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.');
156156
return;
157157
}
158158

@@ -176,17 +176,17 @@ class ContinuousProfiler {
176176
}
177177

178178
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.');
180180
return;
181181
}
182182

183183
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.');
185185
return;
186186
}
187187

188188
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.');
190190
return;
191191
}
192192

@@ -196,25 +196,25 @@ class ContinuousProfiler {
196196

197197
private _startProfiler(): void {
198198
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.');
200200
return;
201201
}
202202

203203
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.');
205205
return;
206206
}
207207

208208
if (this._mode === 'current') {
209209
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.');
211211
return;
212212
}
213213
}
214214

215215
if (this._profileLifecycle === 'trace') {
216216
DEBUG_BUILD &&
217-
logger.log(
217+
debug.log(
218218
'[Profiling] You are using the trace profile lifecycle, manual calls to profiler.startProfiler() and profiler.stopProfiler() will be ignored.',
219219
);
220220
return;
@@ -225,20 +225,20 @@ class ContinuousProfiler {
225225

226226
private _stopProfiler(): void {
227227
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.');
229229
return;
230230
}
231231

232232
if (this._profileLifecycle === 'trace') {
233233
DEBUG_BUILD &&
234-
logger.log(
234+
debug.log(
235235
'[Profiling] You are using the trace profile lifecycle, manual calls to profiler.startProfiler() and profiler.stopProfiler() will be ignored.',
236236
);
237237
return;
238238
}
239239

240240
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.');
242242
return;
243243
}
244244

@@ -251,7 +251,7 @@ class ContinuousProfiler {
251251
private _startTraceLifecycleProfiling(): void {
252252
if (!this._client) {
253253
DEBUG_BUILD &&
254-
logger.log(
254+
debug.log(
255255
'[Profiling] Failed to start trace lifecycle profiling, sentry client was never attached to the profiler.',
256256
);
257257
return;
@@ -276,7 +276,7 @@ class ContinuousProfiler {
276276
private _setupAutomaticSpanProfiling(): void {
277277
if (!this._client) {
278278
DEBUG_BUILD &&
279-
logger.log(
279+
debug.log(
280280
'[Profiling] Failed to setup automatic span profiling, sentry client was never attached to the profiler.',
281281
);
282282
return;
@@ -307,7 +307,7 @@ class ContinuousProfiler {
307307
// Enqueue a timeout to prevent profiles from running over max duration.
308308
const timeout = global.setTimeout(() => {
309309
DEBUG_BUILD &&
310-
logger.log(
310+
debug.log(
311311
'[Profiling] max profile duration elapsed, stopping profiling for:',
312312
spanToJSON(span).description,
313313
);
@@ -371,7 +371,7 @@ class ContinuousProfiler {
371371

372372
const cpuProfile = takeFromProfileQueue(profile_id);
373373
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}`);
375375
continue;
376376
}
377377

@@ -406,13 +406,13 @@ class ContinuousProfiler {
406406
// The client is not attached to the profiler if the user has not enabled continuous profiling.
407407
// In this case, calling start() and stop() is a noop action.The reason this exists is because
408408
// 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.');
410410
return;
411411
}
412412

413413
if (this._chunkData) {
414414
DEBUG_BUILD &&
415-
logger.log(
415+
debug.log(
416416
`[Profiling] Chunk with chunk_id ${this._chunkData.id} is still running, current chunk will be stopped a new chunk will be started.`,
417417
);
418418
this._stopChunkProfiling();
@@ -426,49 +426,49 @@ class ContinuousProfiler {
426426
*/
427427
private _stopChunkProfiling(): void {
428428
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.');
430430
return;
431431
}
432432

433433
if (this._chunkData?.timer) {
434434
global.clearTimeout(this._chunkData.timer);
435435
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}`);
437437
}
438438

439439
if (!this._client) {
440440
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.');
442442
this._resetChunkData();
443443
return;
444444
}
445445

446446
if (!this._chunkData?.id) {
447447
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.`);
449449
this._resetChunkData();
450450
return;
451451
}
452452

453453
const profile = CpuProfilerBindings.stopProfiling(this._chunkData.id, ProfileFormat.CHUNK);
454454

455455
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}`);
457457
this._resetChunkData();
458458
return;
459459
}
460460

461461
if (!this._profilerId) {
462462
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');
464464
this._resetChunkData();
465465
return;
466466
}
467467
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}.`);
469469
}
470470

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.`);
472472
const chunk = createProfilingChunkEvent(
473473
this._client,
474474
this._client.getOptions(),
@@ -482,7 +482,7 @@ class ContinuousProfiler {
482482
);
483483

484484
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}`);
486486
this._resetChunkData();
487487
return;
488488
}
@@ -502,13 +502,13 @@ class ContinuousProfiler {
502502
private _flush(chunk: ProfileChunk): void {
503503
if (!this._client) {
504504
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.');
506506
return;
507507
}
508508

509509
const transport = this._client.getTransport();
510510
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.');
512512
return;
513513
}
514514

@@ -518,7 +518,7 @@ class ContinuousProfiler {
518518

519519
const envelope = makeProfileChunkEnvelope('node', chunk, metadata?.sdk, tunnel, dsn);
520520
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);
522522
});
523523
}
524524

@@ -528,7 +528,7 @@ class ContinuousProfiler {
528528
*/
529529
private _startChunkProfiling(): void {
530530
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.');
532532
return;
533533
}
534534

@@ -537,12 +537,12 @@ class ContinuousProfiler {
537537
const chunk = this._initializeChunk(traceId);
538538

539539
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}`);
541541

542542
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}`);
544544
this._stopChunkProfiling();
545-
DEBUG_BUILD && logger.log('[Profiling] Starting new profiling chunk.');
545+
DEBUG_BUILD && debug.log('[Profiling] Starting new profiling chunk.');
546546
setImmediate(this._restartChunkProfiling.bind(this));
547547
}, CHUNK_INTERVAL_MS);
548548

@@ -557,9 +557,7 @@ class ContinuousProfiler {
557557
private _setupSpanChunkInstrumentation(): void {
558558
if (!this._client) {
559559
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.');
563561
return;
564562
}
565563

@@ -648,7 +646,7 @@ export const _nodeProfilingIntegration = ((): ProfilingIntegration<NodeClient> =
648646
name: 'ProfilingIntegration',
649647
_profiler: new ContinuousProfiler(),
650648
setup(client: NodeClient) {
651-
DEBUG_BUILD && logger.log('[Profiling] Profiling integration setup.');
649+
DEBUG_BUILD && debug.log('[Profiling] Profiling integration setup.');
652650
this._profiler.initialize(client);
653651
return;
654652
},

0 commit comments

Comments
 (0)