Skip to content

Commit 8575cb0

Browse files
committed
ref(node): Use debug instead of logger
1 parent a3216ae commit 8575cb0

File tree

10 files changed

+52
-56
lines changed

10 files changed

+52
-56
lines changed

packages/node/src/integrations/tracing/express.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
55
import type { IntegrationFn } from '@sentry/core';
66
import {
77
captureException,
8+
debug,
89
defineIntegration,
910
getDefaultIsolationScope,
1011
getIsolationScope,
1112
httpRequestToRequestData,
12-
logger,
1313
SEMANTIC_ATTRIBUTE_SENTRY_OP,
1414
spanToJSON,
1515
} from '@sentry/core';
@@ -40,7 +40,7 @@ function requestHook(span: Span): void {
4040

4141
function spanNameHook(info: ExpressRequestInfo<unknown>, defaultName: string): string {
4242
if (getIsolationScope() === getDefaultIsolationScope()) {
43-
DEBUG_BUILD && logger.warn('Isolation scope is still default isolation scope - skipping setting transactionName');
43+
DEBUG_BUILD && debug.warn('Isolation scope is still default isolation scope - skipping setting transactionName');
4444
return defaultName;
4545
}
4646
if (info.layerType === 'request_handler') {

packages/node/src/integrations/tracing/fastify/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import type { Instrumentation, InstrumentationConfig } from '@opentelemetry/inst
33
import type { IntegrationFn, Span } from '@sentry/core';
44
import {
55
captureException,
6+
debug,
67
defineIntegration,
78
getClient,
89
getIsolationScope,
9-
logger,
1010
SEMANTIC_ATTRIBUTE_SENTRY_OP,
1111
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
1212
spanToJSON,
@@ -74,7 +74,7 @@ function handleFastifyError(
7474

7575
if (this.diagnosticsChannelExists && handlerOrigin === 'onError-hook') {
7676
DEBUG_BUILD &&
77-
logger.warn(
77+
debug.warn(
7878
'Fastify error handler was already registered via diagnostics channel.',
7979
'You can safely remove `setupFastifyErrorHandler` call.',
8080
);
@@ -100,7 +100,7 @@ export const instrumentFastify = generateInstrumentOnce(INTEGRATION_NAME, () =>
100100

101101
fastifyInstance?.register(plugin).after(err => {
102102
if (err) {
103-
DEBUG_BUILD && logger.error('Failed to setup Fastify instrumentation', err);
103+
DEBUG_BUILD && debug.error('Failed to setup Fastify instrumentation', err);
104104
} else {
105105
instrumentClient();
106106

packages/node/src/integrations/tracing/hapi/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { HapiInstrumentation } from '@opentelemetry/instrumentation-hapi';
22
import type { IntegrationFn, Span } from '@sentry/core';
33
import {
44
captureException,
5+
debug,
56
defineIntegration,
67
getClient,
78
getDefaultIsolationScope,
89
getIsolationScope,
9-
logger,
1010
SDK_VERSION,
1111
SEMANTIC_ATTRIBUTE_SENTRY_OP,
1212
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
@@ -78,7 +78,7 @@ export const hapiErrorPlugin = {
7878
}
7979
} else {
8080
DEBUG_BUILD &&
81-
logger.warn('Isolation scope is still the default isolation scope - skipping setting transactionName');
81+
debug.warn('Isolation scope is still the default isolation scope - skipping setting transactionName');
8282
}
8383

8484
if (isErrorEvent(event)) {

packages/node/src/integrations/tracing/koa.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
44
import type { IntegrationFn } from '@sentry/core';
55
import {
66
captureException,
7+
debug,
78
defineIntegration,
89
getDefaultIsolationScope,
910
getIsolationScope,
10-
logger,
1111
SEMANTIC_ATTRIBUTE_SENTRY_OP,
1212
spanToJSON,
1313
} from '@sentry/core';
@@ -49,7 +49,7 @@ export const instrumentKoa = generateInstrumentOnce(
4949
}
5050

5151
if (getIsolationScope() === getDefaultIsolationScope()) {
52-
DEBUG_BUILD && logger.warn('Isolation scope is default isolation scope - skipping setting transactionName');
52+
DEBUG_BUILD && debug.warn('Isolation scope is default isolation scope - skipping setting transactionName');
5353
return;
5454
}
5555
const route = attributes[ATTR_HTTP_ROUTE];

packages/node/src/integrations/tracing/postgresjs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import {
1919
} from '@opentelemetry/semantic-conventions';
2020
import type { IntegrationFn, Span } from '@sentry/core';
2121
import {
22+
debug,
2223
defineIntegration,
2324
getCurrentScope,
24-
logger,
2525
SDK_VERSION,
2626
SPAN_STATUS_ERROR,
2727
startSpanManual,
@@ -211,7 +211,7 @@ export class PostgresJsInstrumentation extends InstrumentationBase<PostgresJsIns
211211
() => requestHook(span, sanitizedSqlQuery, postgresConnectionContext),
212212
error => {
213213
if (error) {
214-
logger.error(`Error in requestHook for ${INTEGRATION_NAME} integration:`, error);
214+
debug.error(`Error in requestHook for ${INTEGRATION_NAME} integration:`, error);
215215
}
216216
},
217217
);

packages/node/src/sdk/initOtel.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
ATTR_SERVICE_VERSION,
88
SEMRESATTRS_SERVICE_NAMESPACE,
99
} from '@opentelemetry/semantic-conventions';
10-
import { consoleSandbox, GLOBAL_OBJ, logger, SDK_VERSION } from '@sentry/core';
10+
import { consoleSandbox, debug as coreDebug, GLOBAL_OBJ, SDK_VERSION } from '@sentry/core';
1111
import { type NodeClient, isCjs, SentryContextManager, setupOpenTelemetryLogger } from '@sentry/node-core';
1212
import { SentryPropagator, SentrySampler, SentrySpanProcessor } from '@sentry/opentelemetry';
1313
import { createAddHookMessageChannel } from 'import-in-the-middle';
@@ -50,7 +50,7 @@ export function maybeInitializeEsmLoader(): void {
5050
transferList: [addHookMessagePort],
5151
});
5252
} catch (error) {
53-
logger.warn('Failed to register ESM hook', error);
53+
coreDebug.warn('Failed to register ESM hook', error);
5454
}
5555
}
5656
} else {
@@ -77,7 +77,7 @@ export function preloadOpenTelemetry(options: NodePreloadOptions = {}): void {
7777
const { debug } = options;
7878

7979
if (debug) {
80-
logger.enable();
80+
coreDebug.enable();
8181
}
8282

8383
if (!isCjs()) {
@@ -89,7 +89,7 @@ export function preloadOpenTelemetry(options: NodePreloadOptions = {}): void {
8989
fn();
9090

9191
if (debug) {
92-
logger.log(`[Sentry] Preloaded ${fn.id} instrumentation`);
92+
coreDebug.log(`[Sentry] Preloaded ${fn.id} instrumentation`);
9393
}
9494
});
9595
}
@@ -142,10 +142,10 @@ export function _clampSpanProcessorTimeout(maxSpanWaitDuration: number | undefin
142142
// So if this value is too large, this would fail
143143
if (maxSpanWaitDuration > MAX_MAX_SPAN_WAIT_DURATION) {
144144
DEBUG_BUILD &&
145-
logger.warn(`\`maxSpanWaitDuration\` is too high, using the maximum value of ${MAX_MAX_SPAN_WAIT_DURATION}`);
145+
coreDebug.warn(`\`maxSpanWaitDuration\` is too high, using the maximum value of ${MAX_MAX_SPAN_WAIT_DURATION}`);
146146
return MAX_MAX_SPAN_WAIT_DURATION;
147147
} else if (maxSpanWaitDuration <= 0 || Number.isNaN(maxSpanWaitDuration)) {
148-
DEBUG_BUILD && logger.warn('`maxSpanWaitDuration` must be a positive number, using default value instead.');
148+
DEBUG_BUILD && coreDebug.warn('`maxSpanWaitDuration` must be a positive number, using default value instead.');
149149
return undefined;
150150
}
151151

packages/node/test/integration/transactions.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { context, trace, TraceFlags } from '@opentelemetry/api';
22
import type { SpanProcessor } from '@opentelemetry/sdk-trace-base';
33
import type { TransactionEvent } from '@sentry/core';
4-
import { debug, logger, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
4+
import { debug, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
55
import { SentrySpanProcessor } from '@sentry/opentelemetry';
66
import { afterEach, describe, expect, it, vi } from 'vitest';
77
import * as Sentry from '../../src';
@@ -558,8 +558,6 @@ describe('Integration | Transactions', () => {
558558
vi.setSystemTime(now);
559559

560560
const logs: unknown[] = [];
561-
// TODO: Remove this once node is using debug instead of logger
562-
vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg));
563561
vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg));
564562

565563
mockSdkInit({ tracesSampleRate: 1, beforeSendTransaction });
@@ -638,8 +636,6 @@ describe('Integration | Transactions', () => {
638636
vi.setSystemTime(now);
639637

640638
const logs: unknown[] = [];
641-
// TODO: Remove this once node is using debug instead of logger
642-
vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg));
643639
vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg));
644640

645641
mockSdkInit({

packages/node/test/sdk/init.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Integration } from '@sentry/core';
2-
import { logger, SDK_VERSION } from '@sentry/core';
2+
import { debug, SDK_VERSION } from '@sentry/core';
33
import * as SentryOpentelemetry from '@sentry/opentelemetry';
44
import { type Mock, type MockInstance, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
55
import { getClient, NodeClient, validateOpenTelemetrySetup } from '../../src/';
@@ -26,8 +26,8 @@ describe('init()', () => {
2626
beforeEach(() => {
2727
global.__SENTRY__ = {};
2828

29-
// prevent the logger from being enabled, resulting in console.log calls
30-
vi.spyOn(logger, 'enable').mockImplementation(() => {});
29+
// prevent the debug from being enabled, resulting in console.log calls
30+
vi.spyOn(debug, 'enable').mockImplementation(() => {});
3131

3232
mockAutoPerformanceIntegrations = vi.spyOn(auto, 'getAutoPerformanceIntegrations').mockImplementation(() => []);
3333
});
@@ -285,8 +285,8 @@ describe('validateOpenTelemetrySetup', () => {
285285
});
286286

287287
it('works with correct setup', () => {
288-
const errorSpy = vi.spyOn(logger, 'error').mockImplementation(() => {});
289-
const warnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {});
288+
const errorSpy = vi.spyOn(debug, 'error').mockImplementation(() => {});
289+
const warnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
290290

291291
vi.spyOn(SentryOpentelemetry, 'openTelemetrySetupCheck').mockImplementation(() => {
292292
return ['SentryContextManager', 'SentryPropagator', 'SentrySampler'];
@@ -299,8 +299,8 @@ describe('validateOpenTelemetrySetup', () => {
299299
});
300300

301301
it('works with missing setup, without tracing', () => {
302-
const errorSpy = vi.spyOn(logger, 'error').mockImplementation(() => {});
303-
const warnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {});
302+
const errorSpy = vi.spyOn(debug, 'error').mockImplementation(() => {});
303+
const warnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
304304

305305
vi.spyOn(SentryOpentelemetry, 'openTelemetrySetupCheck').mockImplementation(() => {
306306
return [];
@@ -318,8 +318,8 @@ describe('validateOpenTelemetrySetup', () => {
318318
});
319319

320320
it('works with missing setup, with tracing', () => {
321-
const errorSpy = vi.spyOn(logger, 'error').mockImplementation(() => {});
322-
const warnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {});
321+
const errorSpy = vi.spyOn(debug, 'error').mockImplementation(() => {});
322+
const warnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
323323

324324
vi.spyOn(SentryOpentelemetry, 'openTelemetrySetupCheck').mockImplementation(() => {
325325
return [];

packages/node/test/sdk/initOtel.test.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { logger } from '@sentry/core';
1+
import { debug } from '@sentry/core';
22
import { beforeEach, describe, expect, it, vi } from 'vitest';
33
import { _clampSpanProcessorTimeout } from '../../src/sdk/initOtel';
44

@@ -8,71 +8,71 @@ describe('_clampSpanProcessorTimeout', () => {
88
});
99

1010
it('works with undefined', () => {
11-
const loggerWarnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {});
11+
const debugWarnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
1212
const timeout = _clampSpanProcessorTimeout(undefined);
1313
expect(timeout).toBe(undefined);
14-
expect(loggerWarnSpy).not.toHaveBeenCalled();
14+
expect(debugWarnSpy).not.toHaveBeenCalled();
1515
});
1616

1717
it('works with positive number', () => {
18-
const loggerWarnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {});
18+
const debugWarnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
1919
const timeout = _clampSpanProcessorTimeout(10);
2020
expect(timeout).toBe(10);
21-
expect(loggerWarnSpy).not.toHaveBeenCalled();
21+
expect(debugWarnSpy).not.toHaveBeenCalled();
2222
});
2323

2424
it('works with 0', () => {
25-
const loggerWarnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {});
25+
const debugWarnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
2626
const timeout = _clampSpanProcessorTimeout(0);
2727
expect(timeout).toBe(undefined);
28-
expect(loggerWarnSpy).toHaveBeenCalledTimes(1);
29-
expect(loggerWarnSpy).toHaveBeenCalledWith(
28+
expect(debugWarnSpy).toHaveBeenCalledTimes(1);
29+
expect(debugWarnSpy).toHaveBeenCalledWith(
3030
'`maxSpanWaitDuration` must be a positive number, using default value instead.',
3131
);
3232
});
3333

3434
it('works with negative number', () => {
35-
const loggerWarnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {});
35+
const debugWarnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
3636
const timeout = _clampSpanProcessorTimeout(-10);
3737
expect(timeout).toBe(undefined);
38-
expect(loggerWarnSpy).toHaveBeenCalledTimes(1);
39-
expect(loggerWarnSpy).toHaveBeenCalledWith(
38+
expect(debugWarnSpy).toHaveBeenCalledTimes(1);
39+
expect(debugWarnSpy).toHaveBeenCalledWith(
4040
'`maxSpanWaitDuration` must be a positive number, using default value instead.',
4141
);
4242
});
4343

4444
it('works with -Infinity', () => {
45-
const loggerWarnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {});
45+
const debugWarnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
4646
const timeout = _clampSpanProcessorTimeout(-Infinity);
4747
expect(timeout).toBe(undefined);
48-
expect(loggerWarnSpy).toHaveBeenCalledTimes(1);
49-
expect(loggerWarnSpy).toHaveBeenCalledWith(
48+
expect(debugWarnSpy).toHaveBeenCalledTimes(1);
49+
expect(debugWarnSpy).toHaveBeenCalledWith(
5050
'`maxSpanWaitDuration` must be a positive number, using default value instead.',
5151
);
5252
});
5353

5454
it('works with Infinity', () => {
55-
const loggerWarnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {});
55+
const debugWarnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
5656
const timeout = _clampSpanProcessorTimeout(Infinity);
5757
expect(timeout).toBe(1_000_000);
58-
expect(loggerWarnSpy).toHaveBeenCalledTimes(1);
59-
expect(loggerWarnSpy).toHaveBeenCalledWith('`maxSpanWaitDuration` is too high, using the maximum value of 1000000');
58+
expect(debugWarnSpy).toHaveBeenCalledTimes(1);
59+
expect(debugWarnSpy).toHaveBeenCalledWith('`maxSpanWaitDuration` is too high, using the maximum value of 1000000');
6060
});
6161

6262
it('works with large number', () => {
63-
const loggerWarnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {});
63+
const debugWarnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
6464
const timeout = _clampSpanProcessorTimeout(1_000_000_000);
6565
expect(timeout).toBe(1_000_000);
66-
expect(loggerWarnSpy).toHaveBeenCalledTimes(1);
67-
expect(loggerWarnSpy).toHaveBeenCalledWith('`maxSpanWaitDuration` is too high, using the maximum value of 1000000');
66+
expect(debugWarnSpy).toHaveBeenCalledTimes(1);
67+
expect(debugWarnSpy).toHaveBeenCalledWith('`maxSpanWaitDuration` is too high, using the maximum value of 1000000');
6868
});
6969

7070
it('works with NaN', () => {
71-
const loggerWarnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {});
71+
const debugWarnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
7272
const timeout = _clampSpanProcessorTimeout(NaN);
7373
expect(timeout).toBe(undefined);
74-
expect(loggerWarnSpy).toHaveBeenCalledTimes(1);
75-
expect(loggerWarnSpy).toHaveBeenCalledWith(
74+
expect(debugWarnSpy).toHaveBeenCalledTimes(1);
75+
expect(debugWarnSpy).toHaveBeenCalledWith(
7676
'`maxSpanWaitDuration` must be a positive number, using default value instead.',
7777
);
7878
});

packages/node/test/sdk/preload.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { logger } from '@sentry/core';
1+
import { debug } from '@sentry/core';
22
import { afterEach, describe, expect, it, vi } from 'vitest';
33

44
describe('preload', () => {
55
afterEach(() => {
66
vi.resetAllMocks();
7-
logger.disable();
7+
debug.disable();
88

99
delete process.env.SENTRY_DEBUG;
1010
delete process.env.SENTRY_PRELOAD_INTEGRATIONS;

0 commit comments

Comments
 (0)