diff --git a/packages/node-core/src/integrations/anr/index.ts b/packages/node-core/src/integrations/anr/index.ts index 8f6adab4d3b6..0d8c4f14a53d 100644 --- a/packages/node-core/src/integrations/anr/index.ts +++ b/packages/node-core/src/integrations/anr/index.ts @@ -2,6 +2,7 @@ import { types } from 'node:util'; import { Worker } from 'node:worker_threads'; import type { Contexts, Event, EventHint, Integration, IntegrationFn, ScopeData } from '@sentry/core'; import { + debug, defineIntegration, getClient, getCurrentScope, @@ -9,7 +10,6 @@ import { getGlobalScope, getIsolationScope, GLOBAL_OBJ, - logger, mergeScopeData, } from '@sentry/core'; import { NODE_VERSION } from '../../nodeVersion'; @@ -26,7 +26,7 @@ const DEFAULT_INTERVAL = 50; const DEFAULT_HANG_THRESHOLD = 5000; function log(message: string, ...args: unknown[]): void { - logger.log(`[ANR] ${message}`, ...args); + debug.log(`[ANR] ${message}`, ...args); } function globalWithScopeFetchFn(): typeof GLOBAL_OBJ & { __SENTRY_GET_SCOPES__?: () => ScopeData } { @@ -104,7 +104,7 @@ const _anrIntegration = ((options: Partial = {}) => { client = initClient; if (options.captureStackTrace && (await isDebuggerEnabled())) { - logger.warn('ANR captureStackTrace has been disabled because the debugger was already enabled'); + debug.warn('ANR captureStackTrace has been disabled because the debugger was already enabled'); options.captureStackTrace = false; } @@ -188,7 +188,7 @@ async function _startWorker( } const options: WorkerStartData = { - debug: logger.isEnabled(), + debug: debug.isEnabled(), dsn, tunnel: initOptions.tunnel, environment: initOptions.environment || 'production', diff --git a/packages/node-core/src/integrations/contextlines.ts b/packages/node-core/src/integrations/contextlines.ts index 6667bed80e28..5c99166d0d54 100644 --- a/packages/node-core/src/integrations/contextlines.ts +++ b/packages/node-core/src/integrations/contextlines.ts @@ -1,7 +1,7 @@ import { createReadStream } from 'node:fs'; import { createInterface } from 'node:readline'; import type { Event, IntegrationFn, StackFrame } from '@sentry/core'; -import { defineIntegration, logger, LRUMap, snipLine } from '@sentry/core'; +import { debug, defineIntegration, LRUMap, snipLine } from '@sentry/core'; import { DEBUG_BUILD } from '../debug-build'; const LRU_FILE_CONTENTS_CACHE = new LRUMap>(10); @@ -167,7 +167,7 @@ function getContextLinesFromFile(path: string, ranges: ReadlineRange[], output: function onStreamError(e: Error): void { // Mark file path as failed to read and prevent multiple read attempts. LRU_FILE_CONTENTS_FS_READ_FAILED.set(path, 1); - DEBUG_BUILD && logger.error(`Failed to read file: ${path}. Error: ${e}`); + DEBUG_BUILD && debug.error(`Failed to read file: ${path}. Error: ${e}`); lineReaded.close(); lineReaded.removeAllListeners(); destroyStreamAndResolve(); @@ -281,7 +281,7 @@ async function addSourceContext(event: Event, contextLines: number): Promise { - DEBUG_BUILD && logger.log('Failed to read one or more source files and resolve context lines'); + DEBUG_BUILD && debug.log('Failed to read one or more source files and resolve context lines'); }); // Perform the same loop as above, but this time we can assume all files are in the cache @@ -339,7 +339,7 @@ export function addContextToFrame( // When there is no line number in the frame, attaching context is nonsensical and will even break grouping. // We already check for lineno before calling this, but since StackFrame lineno ism optional, we check it again. if (frame.lineno === undefined || contents === undefined) { - DEBUG_BUILD && logger.error('Cannot resolve context for frame with no lineno or file contents'); + DEBUG_BUILD && debug.error('Cannot resolve context for frame with no lineno or file contents'); return; } @@ -350,7 +350,7 @@ export function addContextToFrame( const line = contents[i]; if (line === undefined) { clearLineContext(frame); - DEBUG_BUILD && logger.error(`Could not find line ${i} in file ${frame.filename}`); + DEBUG_BUILD && debug.error(`Could not find line ${i} in file ${frame.filename}`); return; } @@ -361,7 +361,7 @@ export function addContextToFrame( // without adding any linecontext. if (contents[lineno] === undefined) { clearLineContext(frame); - DEBUG_BUILD && logger.error(`Could not find line ${lineno} in file ${frame.filename}`); + DEBUG_BUILD && debug.error(`Could not find line ${lineno} in file ${frame.filename}`); return; } diff --git a/packages/node-core/src/integrations/http/SentryHttpInstrumentation.ts b/packages/node-core/src/integrations/http/SentryHttpInstrumentation.ts index d1cfc3b1ea0c..daee4440e40c 100644 --- a/packages/node-core/src/integrations/http/SentryHttpInstrumentation.ts +++ b/packages/node-core/src/integrations/http/SentryHttpInstrumentation.ts @@ -12,6 +12,7 @@ import type { AggregationCounts, Client, SanitizedRequestData, Scope } from '@se import { addBreadcrumb, addNonEnumerableProperty, + debug, generateSpanId, getBreadcrumbLogLevelFromHttpStatusCode, getClient, @@ -21,7 +22,6 @@ import { getTraceData, httpRequestToRequestData, isError, - logger, LRUMap, parseUrl, SDK_VERSION, @@ -219,7 +219,7 @@ export class SentryHttpInstrumentation extends InstrumentationBase) => { @@ -503,13 +503,13 @@ function patchRequestToCaptureBody( chunks.push(bufferifiedChunk); bodyByteLength += bufferifiedChunk.byteLength; } else if (DEBUG_BUILD) { - logger.log( + debug.log( INSTRUMENTATION_NAME, `Dropping request body chunk because maximum body length of ${maxBodySize}b is exceeded.`, ); } } catch (err) { - DEBUG_BUILD && logger.error(INSTRUMENTATION_NAME, 'Encountered error while storing body chunk.'); + DEBUG_BUILD && debug.error(INSTRUMENTATION_NAME, 'Encountered error while storing body chunk.'); } return Reflect.apply(target, thisArg, args); @@ -561,13 +561,13 @@ function patchRequestToCaptureBody( } } catch (error) { if (DEBUG_BUILD) { - logger.error(INSTRUMENTATION_NAME, 'Error building captured request body', error); + debug.error(INSTRUMENTATION_NAME, 'Error building captured request body', error); } } }); } catch (error) { if (DEBUG_BUILD) { - logger.error(INSTRUMENTATION_NAME, 'Error patching request to capture body', error); + debug.error(INSTRUMENTATION_NAME, 'Error patching request to capture body', error); } } } @@ -611,7 +611,7 @@ export function recordRequestSession({ const requestSession = requestIsolationScope.getScopeData().sdkProcessingMetadata.requestSession; if (client && requestSession) { - DEBUG_BUILD && logger.debug(`Recorded request session with status: ${requestSession.status}`); + DEBUG_BUILD && debug.log(`Recorded request session with status: ${requestSession.status}`); const roundedDate = new Date(); roundedDate.setSeconds(0, 0); @@ -624,7 +624,7 @@ export function recordRequestSession({ if (existingClientAggregate) { existingClientAggregate[dateBucketKey] = bucket; } else { - DEBUG_BUILD && logger.debug('Opened new request session aggregate.'); + DEBUG_BUILD && debug.log('Opened new request session aggregate.'); const newClientAggregate = { [dateBucketKey]: bucket }; clientToRequestSessionAggregatesMap.set(client, newClientAggregate); @@ -645,11 +645,11 @@ export function recordRequestSession({ }; const unregisterClientFlushHook = client.on('flush', () => { - DEBUG_BUILD && logger.debug('Sending request session aggregate due to client flush'); + DEBUG_BUILD && debug.log('Sending request session aggregate due to client flush'); flushPendingClientAggregates(); }); const timeout = setTimeout(() => { - DEBUG_BUILD && logger.debug('Sending request session aggregate due to flushing schedule'); + DEBUG_BUILD && debug.log('Sending request session aggregate due to flushing schedule'); flushPendingClientAggregates(); }, sessionFlushingDelayMS).unref(); } diff --git a/packages/node-core/src/integrations/local-variables/local-variables-async.ts b/packages/node-core/src/integrations/local-variables/local-variables-async.ts index 6465760b5435..32fff66bab4e 100644 --- a/packages/node-core/src/integrations/local-variables/local-variables-async.ts +++ b/packages/node-core/src/integrations/local-variables/local-variables-async.ts @@ -1,6 +1,6 @@ import { Worker } from 'node:worker_threads'; import type { Event, EventHint, Exception, IntegrationFn } from '@sentry/core'; -import { defineIntegration, logger } from '@sentry/core'; +import { debug, defineIntegration } from '@sentry/core'; import type { NodeClient } from '../../sdk/client'; import { isDebuggerEnabled } from '../../utils/debug'; import type { FrameVariables, LocalVariablesIntegrationOptions, LocalVariablesWorkerArgs } from './common'; @@ -10,7 +10,7 @@ import { functionNamesMatch, LOCAL_VARIABLES_KEY } from './common'; export const base64WorkerScript = '###LocalVariablesWorkerScript###'; function log(...args: unknown[]): void { - logger.log('[LocalVariables]', ...args); + debug.log('[LocalVariables]', ...args); } /** @@ -111,13 +111,13 @@ export const localVariablesAsyncIntegration = defineIntegration((( } if (await isDebuggerEnabled()) { - logger.warn('Local variables capture has been disabled because the debugger was already enabled'); + debug.warn('Local variables capture has been disabled because the debugger was already enabled'); return; } const options: LocalVariablesWorkerArgs = { ...integrationOptions, - debug: logger.isEnabled(), + debug: debug.isEnabled(), }; startInspector().then( @@ -125,11 +125,11 @@ export const localVariablesAsyncIntegration = defineIntegration((( try { startWorker(options); } catch (e) { - logger.error('Failed to start worker', e); + debug.error('Failed to start worker', e); } }, e => { - logger.error('Failed to start inspector', e); + debug.error('Failed to start inspector', e); }, ); }, diff --git a/packages/node-core/src/integrations/local-variables/local-variables-sync.ts b/packages/node-core/src/integrations/local-variables/local-variables-sync.ts index eb8a057e4162..7de91a54276e 100644 --- a/packages/node-core/src/integrations/local-variables/local-variables-sync.ts +++ b/packages/node-core/src/integrations/local-variables/local-variables-sync.ts @@ -1,6 +1,6 @@ import type { Debugger, InspectorNotification, Runtime, Session } from 'node:inspector'; import type { Event, Exception, IntegrationFn, StackFrame, StackParser } from '@sentry/core'; -import { defineIntegration, getClient, logger, LRUMap } from '@sentry/core'; +import { debug, defineIntegration, getClient, LRUMap } from '@sentry/core'; import { NODE_MAJOR } from '../../nodeVersion'; import type { NodeClient } from '../../sdk/client'; import { isDebuggerEnabled } from '../../utils/debug'; @@ -303,12 +303,12 @@ const _localVariablesSyncIntegration = (( const unsupportedNodeVersion = NODE_MAJOR < 18; if (unsupportedNodeVersion) { - logger.log('The `LocalVariables` integration is only supported on Node >= v18.'); + debug.log('The `LocalVariables` integration is only supported on Node >= v18.'); return; } if (await isDebuggerEnabled()) { - logger.warn('Local variables capture has been disabled because the debugger was already enabled'); + debug.warn('Local variables capture has been disabled because the debugger was already enabled'); return; } @@ -384,11 +384,11 @@ const _localVariablesSyncIntegration = (( rateLimiter = createRateLimiter( max, () => { - logger.log('Local variables rate-limit lifted.'); + debug.log('Local variables rate-limit lifted.'); session.setPauseOnExceptions(true); }, seconds => { - logger.log( + debug.log( `Local variables rate-limit exceeded. Disabling capturing of caught exceptions for ${seconds} seconds.`, ); session.setPauseOnExceptions(false); @@ -399,7 +399,7 @@ const _localVariablesSyncIntegration = (( shouldProcessEvent = true; }, error => { - logger.log('The `LocalVariables` integration failed to start.', error); + debug.log('The `LocalVariables` integration failed to start.', error); }, ); }, diff --git a/packages/node-core/src/integrations/onuncaughtexception.ts b/packages/node-core/src/integrations/onuncaughtexception.ts index 0634159338a6..045e2e9f7736 100644 --- a/packages/node-core/src/integrations/onuncaughtexception.ts +++ b/packages/node-core/src/integrations/onuncaughtexception.ts @@ -1,4 +1,4 @@ -import { captureException, defineIntegration, getClient, logger } from '@sentry/core'; +import { captureException, debug, defineIntegration, getClient } from '@sentry/core'; import { DEBUG_BUILD } from '../debug-build'; import type { NodeClient } from '../sdk/client'; import { logAndExitProcess } from '../utils/errorhandling'; @@ -122,7 +122,7 @@ export function makeErrorHandler(client: NodeClient, options: OnUncaughtExceptio if (calledFatalError) { // we hit an error *after* calling onFatalError - pretty boned at this point, just shut it down DEBUG_BUILD && - logger.warn( + debug.warn( 'uncaught exception after calling fatal error shutdown callback - this is bad! forcing shutdown', ); logAndExitProcess(error); diff --git a/packages/node-core/src/integrations/spotlight.ts b/packages/node-core/src/integrations/spotlight.ts index fab83cbe579e..47d73b956628 100644 --- a/packages/node-core/src/integrations/spotlight.ts +++ b/packages/node-core/src/integrations/spotlight.ts @@ -1,6 +1,6 @@ import * as http from 'node:http'; import type { Client, Envelope, IntegrationFn } from '@sentry/core'; -import { defineIntegration, logger, serializeEnvelope, suppressTracing } from '@sentry/core'; +import { debug, defineIntegration, serializeEnvelope, suppressTracing } from '@sentry/core'; type SpotlightConnectionOptions = { /** @@ -22,7 +22,7 @@ const _spotlightIntegration = ((options: Partial = { setup(client) { try { if (process.env.NODE_ENV && process.env.NODE_ENV !== 'development') { - logger.warn("[Spotlight] It seems you're not in dev mode. Do you really want to have Spotlight enabled?"); + debug.warn("[Spotlight] It seems you're not in dev mode. Do you really want to have Spotlight enabled?"); } } catch { // ignore @@ -51,7 +51,7 @@ function connectToSpotlight(client: Client, options: Required { if (failedRequests > 3) { - logger.warn('[Spotlight] Disabled Sentry -> Spotlight integration due to too many failed requests'); + debug.warn('[Spotlight] Disabled Sentry -> Spotlight integration due to too many failed requests'); return; } @@ -85,7 +85,7 @@ function connectToSpotlight(client: Client, options: Required { failedRequests++; - logger.warn('[Spotlight] Failed to send envelope to Spotlight Sidecar'); + debug.warn('[Spotlight] Failed to send envelope to Spotlight Sidecar'); }); req.write(serializedEnvelope); req.end(); @@ -97,7 +97,7 @@ function parseSidecarUrl(url: string): URL | undefined { try { return new URL(`${url}`); } catch { - logger.warn(`[Spotlight] Invalid sidecar URL: ${url}`); + debug.warn(`[Spotlight] Invalid sidecar URL: ${url}`); return undefined; } } diff --git a/packages/node-core/src/otel/logger.ts b/packages/node-core/src/otel/logger.ts index 53cbdc63c3ee..7b4ecb6104ba 100644 --- a/packages/node-core/src/otel/logger.ts +++ b/packages/node-core/src/otel/logger.ts @@ -1,18 +1,20 @@ import { diag, DiagLogLevel } from '@opentelemetry/api'; -import { logger } from '@sentry/core'; +import { debug } from '@sentry/core'; /** - * Setup the OTEL logger to use our own logger. + * Setup the OTEL logger to use our own debug logger. */ export function setupOpenTelemetryLogger(): void { - const otelLogger = new Proxy(logger as typeof logger & { verbose: (typeof logger)['debug'] }, { - get(target, prop, receiver) { - const actualProp = prop === 'verbose' ? 'debug' : prop; - return Reflect.get(target, actualProp, receiver); - }, - }); - // Disable diag, to ensure this works even if called multiple times diag.disable(); - diag.setLogger(otelLogger, DiagLogLevel.DEBUG); + diag.setLogger( + { + error: debug.error, + warn: debug.warn, + info: debug.log, + debug: debug.log, + verbose: debug.log, + }, + DiagLogLevel.DEBUG, + ); } diff --git a/packages/node-core/src/proxy/index.ts b/packages/node-core/src/proxy/index.ts index 8ff6741623b2..21eccb157ae6 100644 --- a/packages/node-core/src/proxy/index.ts +++ b/packages/node-core/src/proxy/index.ts @@ -34,13 +34,13 @@ import type * as http from 'node:http'; import type { OutgoingHttpHeaders } from 'node:http'; import * as net from 'node:net'; import * as tls from 'node:tls'; -import { logger } from '@sentry/core'; +import { debug } from '@sentry/core'; import type { AgentConnectOpts } from './base'; import { Agent } from './base'; import { parseProxyResponse } from './parse-proxy-response'; -function debug(...args: unknown[]): void { - logger.log('[https-proxy-agent]', ...args); +function debugLog(...args: unknown[]): void { + debug.log('[https-proxy-agent]', ...args); } type Protocol = T extends `${infer Protocol}:${infer _}` ? Protocol : never; @@ -83,7 +83,7 @@ export class HttpsProxyAgent extends Agent { this.options = {}; this.proxy = typeof proxy === 'string' ? new URL(proxy) : proxy; this.proxyHeaders = opts?.headers ?? {}; - debug('Creating new HttpsProxyAgent instance: %o', this.proxy.href); + debugLog('Creating new HttpsProxyAgent instance: %o', this.proxy.href); // Trim off the brackets from IPv6 addresses const host = (this.proxy.hostname || this.proxy.host).replace(/^\[|\]$/g, ''); @@ -111,14 +111,14 @@ export class HttpsProxyAgent extends Agent { // Create a socket connection to the proxy server. let socket: net.Socket; if (proxy.protocol === 'https:') { - debug('Creating `tls.Socket`: %o', this.connectOpts); + debugLog('Creating `tls.Socket`: %o', this.connectOpts); const servername = this.connectOpts.servername || this.connectOpts.host; socket = tls.connect({ ...this.connectOpts, servername: servername && net.isIP(servername) ? undefined : servername, }); } else { - debug('Creating `net.Socket`: %o', this.connectOpts); + debugLog('Creating `net.Socket`: %o', this.connectOpts); socket = net.connect(this.connectOpts); } @@ -158,7 +158,7 @@ export class HttpsProxyAgent extends Agent { if (opts.secureEndpoint) { // The proxy is connecting to a TLS server, so upgrade // this socket connection to a TLS connection. - debug('Upgrading socket connection to TLS'); + debugLog('Upgrading socket connection to TLS'); const servername = opts.servername || opts.host; return tls.connect({ ...omit(opts, 'host', 'path', 'port'), @@ -188,7 +188,7 @@ export class HttpsProxyAgent extends Agent { // Need to wait for the "socket" event to re-play the "data" events. req.once('socket', (s: net.Socket) => { - debug('Replaying proxy buffer for failed request'); + debugLog('Replaying proxy buffer for failed request'); // Replay the "buffered" Buffer onto the fake `socket`, since at // this point the HTTP module machinery has been hooked up for // the user. diff --git a/packages/node-core/src/proxy/parse-proxy-response.ts b/packages/node-core/src/proxy/parse-proxy-response.ts index afad0d2435f4..0d7481b82621 100644 --- a/packages/node-core/src/proxy/parse-proxy-response.ts +++ b/packages/node-core/src/proxy/parse-proxy-response.ts @@ -30,10 +30,10 @@ /* eslint-disable jsdoc/require-jsdoc */ import type { IncomingHttpHeaders } from 'node:http'; import type { Readable } from 'node:stream'; -import { logger } from '@sentry/core'; +import { debug } from '@sentry/core'; -function debug(...args: unknown[]): void { - logger.log('[https-proxy-agent:parse-proxy-response]', ...args); +function debugLog(...args: unknown[]): void { + debug.log('[https-proxy-agent:parse-proxy-response]', ...args); } export interface ConnectResponse { @@ -65,13 +65,13 @@ export function parseProxyResponse(socket: Readable): Promise<{ connect: Connect function onend() { cleanup(); - debug('onend'); + debugLog('onend'); reject(new Error('Proxy connection ended before receiving CONNECT response')); } function onerror(err: Error) { cleanup(); - debug('onerror %o', err); + debugLog('onerror %o', err); reject(err); } @@ -84,7 +84,7 @@ export function parseProxyResponse(socket: Readable): Promise<{ connect: Connect if (endOfHeaders === -1) { // keep buffering - debug('have not received end of HTTP headers yet...'); + debugLog('have not received end of HTTP headers yet...'); read(); return; } @@ -117,7 +117,7 @@ export function parseProxyResponse(socket: Readable): Promise<{ connect: Connect headers[key] = value; } } - debug('got proxy server response: %o %o', firstLine, headers); + debugLog('got proxy server response: %o %o', firstLine, headers); cleanup(); resolve({ connect: { diff --git a/packages/node-core/src/sdk/client.ts b/packages/node-core/src/sdk/client.ts index 022e3cb1ac33..50b0d4d92b6e 100644 --- a/packages/node-core/src/sdk/client.ts +++ b/packages/node-core/src/sdk/client.ts @@ -4,7 +4,7 @@ import { trace } from '@opentelemetry/api'; import { registerInstrumentations } from '@opentelemetry/instrumentation'; import type { BasicTracerProvider } from '@opentelemetry/sdk-trace-base'; import type { DynamicSamplingContext, Scope, ServerRuntimeClientOptions, TraceContext } from '@sentry/core'; -import { _INTERNAL_flushLogsBuffer, applySdkMetadata, logger, SDK_VERSION, ServerRuntimeClient } from '@sentry/core'; +import { _INTERNAL_flushLogsBuffer, applySdkMetadata, debug, SDK_VERSION, ServerRuntimeClient } from '@sentry/core'; import { getTraceContextForScope } from '@sentry/opentelemetry'; import { isMainThread, threadId } from 'worker_threads'; import { DEBUG_BUILD } from '../debug-build'; @@ -41,9 +41,7 @@ export class NodeClient extends ServerRuntimeClient { applySdkMetadata(clientOptions, 'node'); - logger.log( - `Initializing Sentry: process: ${process.pid}, thread: ${isMainThread ? 'main' : `worker-${threadId}`}.`, - ); + debug.log(`Initializing Sentry: process: ${process.pid}, thread: ${isMainThread ? 'main' : `worker-${threadId}`}.`); super(clientOptions); @@ -134,7 +132,7 @@ export class NodeClient extends ServerRuntimeClient { }; this._clientReportInterval = setInterval(() => { - DEBUG_BUILD && logger.log('Flushing client reports based on interval.'); + DEBUG_BUILD && debug.log('Flushing client reports based on interval.'); this._flushOutcomes(); }, clientOptions.clientReportFlushInterval ?? DEFAULT_CLIENT_REPORT_FLUSH_INTERVAL_MS) // Unref is critical for not preventing the process from exiting because the interval is active. diff --git a/packages/node-core/src/sdk/esmLoader.ts b/packages/node-core/src/sdk/esmLoader.ts index 487e2ce0c613..2f0d8b405333 100644 --- a/packages/node-core/src/sdk/esmLoader.ts +++ b/packages/node-core/src/sdk/esmLoader.ts @@ -1,4 +1,4 @@ -import { consoleSandbox, GLOBAL_OBJ, logger } from '@sentry/core'; +import { consoleSandbox, debug, GLOBAL_OBJ } from '@sentry/core'; import { createAddHookMessageChannel } from 'import-in-the-middle'; import moduleModule from 'module'; @@ -17,7 +17,7 @@ export function maybeInitializeEsmLoader(): void { transferList: [addHookMessagePort], }); } catch (error) { - logger.warn('Failed to register ESM hook', error); + debug.warn('Failed to register ESM hook', error); } } } else { diff --git a/packages/node-core/src/sdk/index.ts b/packages/node-core/src/sdk/index.ts index 9ec30a892927..7d9bf6e90fd7 100644 --- a/packages/node-core/src/sdk/index.ts +++ b/packages/node-core/src/sdk/index.ts @@ -3,13 +3,13 @@ import { applySdkMetadata, consoleIntegration, consoleSandbox, + debug, functionToStringIntegration, getCurrentScope, getIntegrationsToSetup, hasSpansEnabled, inboundFiltersIntegration, linkedErrorsIntegration, - logger, propagationContextFromHeaders, requestDataIntegration, stackParserFromStackParserOptions, @@ -94,9 +94,9 @@ function _init( if (options.debug === true) { if (DEBUG_BUILD) { - logger.enable(); + debug.enable(); } else { - // use `console.warn` rather than `logger.warn` since by non-debug bundles have all `logger.x` statements stripped + // use `console.warn` rather than `debug.warn` since by non-debug bundles have all `debug.x` statements stripped consoleSandbox(() => { // eslint-disable-next-line no-console console.warn('[Sentry] Cannot initialize SDK with `debug` option using a non-debug bundle.'); @@ -129,7 +129,7 @@ function _init( client.init(); - logger.log(`Running in ${isCjs() ? 'CommonJS' : 'ESM'} mode.`); + debug.log(`Running in ${isCjs() ? 'CommonJS' : 'ESM'} mode.`); client.startClientReportTracking(); @@ -159,14 +159,14 @@ export function validateOpenTelemetrySetup(): void { for (const k of required) { if (!setup.includes(k)) { - logger.error( + debug.error( `You have to set up the ${k}. Without this, the OpenTelemetry & Sentry integration will not work properly.`, ); } } if (!setup.includes('SentrySampler')) { - logger.warn( + debug.warn( 'You have to set up the SentrySampler. Without this, the OpenTelemetry & Sentry integration may still work, but sample rates set for the Sentry SDK will not be respected. If you use a custom sampler, make sure to use `wrapSamplingDecision`.', ); } diff --git a/packages/node-core/src/utils/errorhandling.ts b/packages/node-core/src/utils/errorhandling.ts index bac86d09ccb5..bb22766b5155 100644 --- a/packages/node-core/src/utils/errorhandling.ts +++ b/packages/node-core/src/utils/errorhandling.ts @@ -1,4 +1,4 @@ -import { consoleSandbox, getClient, logger } from '@sentry/core'; +import { consoleSandbox, debug, getClient } from '@sentry/core'; import { DEBUG_BUILD } from '../debug-build'; import type { NodeClient } from '../sdk/client'; @@ -16,7 +16,7 @@ export function logAndExitProcess(error: unknown): void { const client = getClient(); if (client === undefined) { - DEBUG_BUILD && logger.warn('No NodeClient was defined, we are exiting the process now.'); + DEBUG_BUILD && debug.warn('No NodeClient was defined, we are exiting the process now.'); global.process.exit(1); return; } @@ -27,12 +27,12 @@ export function logAndExitProcess(error: unknown): void { client.close(timeout).then( (result: boolean) => { if (!result) { - DEBUG_BUILD && logger.warn('We reached the timeout for emptying the request buffer, still exiting now!'); + DEBUG_BUILD && debug.warn('We reached the timeout for emptying the request buffer, still exiting now!'); } global.process.exit(1); }, error => { - DEBUG_BUILD && logger.error(error); + DEBUG_BUILD && debug.error(error); }, ); } diff --git a/packages/node-core/test/helpers/mockSdkInit.ts b/packages/node-core/test/helpers/mockSdkInit.ts index f627e9999946..ce82f92de3d8 100644 --- a/packages/node-core/test/helpers/mockSdkInit.ts +++ b/packages/node-core/test/helpers/mockSdkInit.ts @@ -8,11 +8,11 @@ import { } from '@opentelemetry/semantic-conventions'; import { createTransport, + debug, getClient, getCurrentScope, getGlobalScope, getIsolationScope, - logger, resolvedSyncPromise, SDK_VERSION, } from '@sentry/core'; @@ -36,10 +36,10 @@ function clampSpanProcessorTimeout(maxSpanWaitDuration: number | undefined): num // We guard for a max. value here, because we create an array with this length // So if this value is too large, this would fail if (maxSpanWaitDuration > MAX_MAX_SPAN_WAIT_DURATION) { - logger.warn(`\`maxSpanWaitDuration\` is too high, using the maximum value of ${MAX_MAX_SPAN_WAIT_DURATION}`); + debug.warn(`\`maxSpanWaitDuration\` is too high, using the maximum value of ${MAX_MAX_SPAN_WAIT_DURATION}`); return MAX_MAX_SPAN_WAIT_DURATION; } else if (maxSpanWaitDuration <= 0 || Number.isNaN(maxSpanWaitDuration)) { - logger.warn('`maxSpanWaitDuration` must be a positive number, using default value instead.'); + debug.warn('`maxSpanWaitDuration` must be a positive number, using default value instead.'); return undefined; } diff --git a/packages/node-core/test/integration/transactions.test.ts b/packages/node-core/test/integration/transactions.test.ts index 2fd27789f1ef..0ce3f7c99984 100644 --- a/packages/node-core/test/integration/transactions.test.ts +++ b/packages/node-core/test/integration/transactions.test.ts @@ -1,7 +1,7 @@ import { context, trace, TraceFlags } from '@opentelemetry/api'; import type { SpanProcessor } from '@opentelemetry/sdk-trace-base'; import type { TransactionEvent } from '@sentry/core'; -import { debug, logger, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; +import { debug, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; import { SentrySpanProcessor } from '@sentry/opentelemetry'; import { afterEach, describe, expect, it, vi } from 'vitest'; import * as Sentry from '../../src'; @@ -558,8 +558,6 @@ describe('Integration | Transactions', () => { vi.setSystemTime(now); const logs: unknown[] = []; - // TODO: Remove this once node is using debug instead of logger - vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg)); vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg)); mockSdkInit({ tracesSampleRate: 1, beforeSendTransaction }); @@ -638,8 +636,6 @@ describe('Integration | Transactions', () => { vi.setSystemTime(now); const logs: unknown[] = []; - // TODO: Remove this once node is using debug instead of logger - vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg)); vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg)); mockSdkInit({ diff --git a/packages/node-core/test/integrations/spotlight.test.ts b/packages/node-core/test/integrations/spotlight.test.ts index 2bd10080fd31..19d52ebcdb21 100644 --- a/packages/node-core/test/integrations/spotlight.test.ts +++ b/packages/node-core/test/integrations/spotlight.test.ts @@ -1,6 +1,6 @@ import * as http from 'node:http'; import type { Envelope, EventEnvelope } from '@sentry/core'; -import { createEnvelope, logger } from '@sentry/core'; +import { createEnvelope, debug } from '@sentry/core'; import { afterEach, describe, expect, it, vi } from 'vitest'; import { spotlightIntegration } from '../../src/integrations/spotlight'; import { NodeClient } from '../../src/sdk/client'; @@ -16,10 +16,10 @@ vi.mock('node:http', async () => { }); describe('Spotlight', () => { - const loggerSpy = vi.spyOn(logger, 'warn'); + const debugSpy = vi.spyOn(debug, 'warn'); afterEach(() => { - loggerSpy.mockClear(); + debugSpy.mockClear(); vi.clearAllMocks(); }); @@ -124,7 +124,7 @@ describe('Spotlight', () => { it('an invalid URL is passed', () => { const integration = spotlightIntegration({ sidecarUrl: 'invalid-url' }); integration.setup!(client); - expect(loggerSpy).toHaveBeenCalledWith(expect.stringContaining('Invalid sidecar URL: invalid-url')); + expect(debugSpy).toHaveBeenCalledWith(expect.stringContaining('Invalid sidecar URL: invalid-url')); }); }); @@ -135,7 +135,7 @@ describe('Spotlight', () => { const integration = spotlightIntegration({ sidecarUrl: 'http://localhost:8969' }); integration.setup!(client); - expect(loggerSpy).toHaveBeenCalledWith( + expect(debugSpy).toHaveBeenCalledWith( expect.stringContaining("It seems you're not in dev mode. Do you really want to have Spotlight enabled?"), ); @@ -149,7 +149,7 @@ describe('Spotlight', () => { const integration = spotlightIntegration({ sidecarUrl: 'http://localhost:8969' }); integration.setup!(client); - expect(loggerSpy).not.toHaveBeenCalledWith( + expect(debugSpy).not.toHaveBeenCalledWith( expect.stringContaining("It seems you're not in dev mode. Do you really want to have Spotlight enabled?"), ); @@ -165,7 +165,7 @@ describe('Spotlight', () => { const integration = spotlightIntegration({ sidecarUrl: 'http://localhost:8969' }); integration.setup!(client); - expect(loggerSpy).not.toHaveBeenCalledWith( + expect(debugSpy).not.toHaveBeenCalledWith( expect.stringContaining("It seems you're not in dev mode. Do you really want to have Spotlight enabled?"), ); @@ -181,7 +181,7 @@ describe('Spotlight', () => { const integration = spotlightIntegration({ sidecarUrl: 'http://localhost:8969' }); integration.setup!(client); - expect(loggerSpy).not.toHaveBeenCalledWith( + expect(debugSpy).not.toHaveBeenCalledWith( expect.stringContaining("It seems you're not in dev mode. Do you really want to have Spotlight enabled?"), ); diff --git a/packages/node-core/test/sdk/init.test.ts b/packages/node-core/test/sdk/init.test.ts index 02115fa26ff7..c0c574ab2b35 100644 --- a/packages/node-core/test/sdk/init.test.ts +++ b/packages/node-core/test/sdk/init.test.ts @@ -1,5 +1,5 @@ import type { Integration } from '@sentry/core'; -import { logger, SDK_VERSION } from '@sentry/core'; +import { debug, SDK_VERSION } from '@sentry/core'; import * as SentryOpentelemetry from '@sentry/opentelemetry'; import { type Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { getClient } from '../../src/'; @@ -227,8 +227,8 @@ describe('validateOpenTelemetrySetup', () => { }); it('works with correct setup', () => { - const errorSpy = vi.spyOn(logger, 'error').mockImplementation(() => {}); - const warnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); + const errorSpy = vi.spyOn(debug, 'error').mockImplementation(() => {}); + const warnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {}); vi.spyOn(SentryOpentelemetry, 'openTelemetrySetupCheck').mockImplementation(() => { return ['SentryContextManager', 'SentryPropagator', 'SentrySampler']; @@ -241,8 +241,8 @@ describe('validateOpenTelemetrySetup', () => { }); it('works with missing setup, without tracing', () => { - const errorSpy = vi.spyOn(logger, 'error').mockImplementation(() => {}); - const warnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); + const errorSpy = vi.spyOn(debug, 'error').mockImplementation(() => {}); + const warnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {}); vi.spyOn(SentryOpentelemetry, 'openTelemetrySetupCheck').mockImplementation(() => { return []; @@ -260,8 +260,8 @@ describe('validateOpenTelemetrySetup', () => { }); it('works with missing setup, with tracing', () => { - const errorSpy = vi.spyOn(logger, 'error').mockImplementation(() => {}); - const warnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); + const errorSpy = vi.spyOn(debug, 'error').mockImplementation(() => {}); + const warnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {}); vi.spyOn(SentryOpentelemetry, 'openTelemetrySetupCheck').mockImplementation(() => { return []; diff --git a/packages/node/src/integrations/tracing/express.ts b/packages/node/src/integrations/tracing/express.ts index 52dfc373d470..24155e2f5452 100644 --- a/packages/node/src/integrations/tracing/express.ts +++ b/packages/node/src/integrations/tracing/express.ts @@ -5,11 +5,11 @@ import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express'; import type { IntegrationFn } from '@sentry/core'; import { captureException, + debug, defineIntegration, getDefaultIsolationScope, getIsolationScope, httpRequestToRequestData, - logger, SEMANTIC_ATTRIBUTE_SENTRY_OP, spanToJSON, } from '@sentry/core'; @@ -40,7 +40,7 @@ function requestHook(span: Span): void { function spanNameHook(info: ExpressRequestInfo, defaultName: string): string { if (getIsolationScope() === getDefaultIsolationScope()) { - DEBUG_BUILD && logger.warn('Isolation scope is still default isolation scope - skipping setting transactionName'); + DEBUG_BUILD && debug.warn('Isolation scope is still default isolation scope - skipping setting transactionName'); return defaultName; } if (info.layerType === 'request_handler') { diff --git a/packages/node/src/integrations/tracing/fastify/index.ts b/packages/node/src/integrations/tracing/fastify/index.ts index b2202a915a47..0aaf7814e9e3 100644 --- a/packages/node/src/integrations/tracing/fastify/index.ts +++ b/packages/node/src/integrations/tracing/fastify/index.ts @@ -3,10 +3,10 @@ import type { Instrumentation, InstrumentationConfig } from '@opentelemetry/inst import type { IntegrationFn, Span } from '@sentry/core'; import { captureException, + debug, defineIntegration, getClient, getIsolationScope, - logger, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, spanToJSON, @@ -74,7 +74,7 @@ function handleFastifyError( if (this.diagnosticsChannelExists && handlerOrigin === 'onError-hook') { DEBUG_BUILD && - logger.warn( + debug.warn( 'Fastify error handler was already registered via diagnostics channel.', 'You can safely remove `setupFastifyErrorHandler` call.', ); @@ -100,7 +100,7 @@ export const instrumentFastify = generateInstrumentOnce(INTEGRATION_NAME, () => fastifyInstance?.register(plugin).after(err => { if (err) { - DEBUG_BUILD && logger.error('Failed to setup Fastify instrumentation', err); + DEBUG_BUILD && debug.error('Failed to setup Fastify instrumentation', err); } else { instrumentClient(); diff --git a/packages/node/src/integrations/tracing/hapi/index.ts b/packages/node/src/integrations/tracing/hapi/index.ts index f06bfeb18478..eaa8d9c56ad9 100644 --- a/packages/node/src/integrations/tracing/hapi/index.ts +++ b/packages/node/src/integrations/tracing/hapi/index.ts @@ -2,11 +2,11 @@ import { HapiInstrumentation } from '@opentelemetry/instrumentation-hapi'; import type { IntegrationFn, Span } from '@sentry/core'; import { captureException, + debug, defineIntegration, getClient, getDefaultIsolationScope, getIsolationScope, - logger, SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, @@ -78,7 +78,7 @@ export const hapiErrorPlugin = { } } else { DEBUG_BUILD && - logger.warn('Isolation scope is still the default isolation scope - skipping setting transactionName'); + debug.warn('Isolation scope is still the default isolation scope - skipping setting transactionName'); } if (isErrorEvent(event)) { diff --git a/packages/node/src/integrations/tracing/koa.ts b/packages/node/src/integrations/tracing/koa.ts index 049cc9064f9a..487f471a9a12 100644 --- a/packages/node/src/integrations/tracing/koa.ts +++ b/packages/node/src/integrations/tracing/koa.ts @@ -4,10 +4,10 @@ import { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions'; import type { IntegrationFn } from '@sentry/core'; import { captureException, + debug, defineIntegration, getDefaultIsolationScope, getIsolationScope, - logger, SEMANTIC_ATTRIBUTE_SENTRY_OP, spanToJSON, } from '@sentry/core'; @@ -49,7 +49,7 @@ export const instrumentKoa = generateInstrumentOnce( } if (getIsolationScope() === getDefaultIsolationScope()) { - DEBUG_BUILD && logger.warn('Isolation scope is default isolation scope - skipping setting transactionName'); + DEBUG_BUILD && debug.warn('Isolation scope is default isolation scope - skipping setting transactionName'); return; } const route = attributes[ATTR_HTTP_ROUTE]; diff --git a/packages/node/src/integrations/tracing/postgresjs.ts b/packages/node/src/integrations/tracing/postgresjs.ts index 45d581edc45f..1a0eae973bc6 100644 --- a/packages/node/src/integrations/tracing/postgresjs.ts +++ b/packages/node/src/integrations/tracing/postgresjs.ts @@ -19,9 +19,9 @@ import { } from '@opentelemetry/semantic-conventions'; import type { IntegrationFn, Span } from '@sentry/core'; import { + debug, defineIntegration, getCurrentScope, - logger, SDK_VERSION, SPAN_STATUS_ERROR, startSpanManual, @@ -211,7 +211,7 @@ export class PostgresJsInstrumentation extends InstrumentationBase requestHook(span, sanitizedSqlQuery, postgresConnectionContext), error => { if (error) { - logger.error(`Error in requestHook for ${INTEGRATION_NAME} integration:`, error); + debug.error(`Error in requestHook for ${INTEGRATION_NAME} integration:`, error); } }, ); diff --git a/packages/node/src/sdk/initOtel.ts b/packages/node/src/sdk/initOtel.ts index 3c35a1fecc3a..4e58414f347a 100644 --- a/packages/node/src/sdk/initOtel.ts +++ b/packages/node/src/sdk/initOtel.ts @@ -7,7 +7,7 @@ import { ATTR_SERVICE_VERSION, SEMRESATTRS_SERVICE_NAMESPACE, } from '@opentelemetry/semantic-conventions'; -import { consoleSandbox, GLOBAL_OBJ, logger, SDK_VERSION } from '@sentry/core'; +import { consoleSandbox, debug as coreDebug, GLOBAL_OBJ, SDK_VERSION } from '@sentry/core'; import { type NodeClient, isCjs, SentryContextManager, setupOpenTelemetryLogger } from '@sentry/node-core'; import { SentryPropagator, SentrySampler, SentrySpanProcessor } from '@sentry/opentelemetry'; import { createAddHookMessageChannel } from 'import-in-the-middle'; @@ -50,7 +50,7 @@ export function maybeInitializeEsmLoader(): void { transferList: [addHookMessagePort], }); } catch (error) { - logger.warn('Failed to register ESM hook', error); + coreDebug.warn('Failed to register ESM hook', error); } } } else { @@ -77,7 +77,7 @@ export function preloadOpenTelemetry(options: NodePreloadOptions = {}): void { const { debug } = options; if (debug) { - logger.enable(); + coreDebug.enable(); } if (!isCjs()) { @@ -89,7 +89,7 @@ export function preloadOpenTelemetry(options: NodePreloadOptions = {}): void { fn(); if (debug) { - logger.log(`[Sentry] Preloaded ${fn.id} instrumentation`); + coreDebug.log(`[Sentry] Preloaded ${fn.id} instrumentation`); } }); } @@ -142,10 +142,10 @@ export function _clampSpanProcessorTimeout(maxSpanWaitDuration: number | undefin // So if this value is too large, this would fail if (maxSpanWaitDuration > MAX_MAX_SPAN_WAIT_DURATION) { DEBUG_BUILD && - logger.warn(`\`maxSpanWaitDuration\` is too high, using the maximum value of ${MAX_MAX_SPAN_WAIT_DURATION}`); + coreDebug.warn(`\`maxSpanWaitDuration\` is too high, using the maximum value of ${MAX_MAX_SPAN_WAIT_DURATION}`); return MAX_MAX_SPAN_WAIT_DURATION; } else if (maxSpanWaitDuration <= 0 || Number.isNaN(maxSpanWaitDuration)) { - DEBUG_BUILD && logger.warn('`maxSpanWaitDuration` must be a positive number, using default value instead.'); + DEBUG_BUILD && coreDebug.warn('`maxSpanWaitDuration` must be a positive number, using default value instead.'); return undefined; } diff --git a/packages/node/test/integration/transactions.test.ts b/packages/node/test/integration/transactions.test.ts index 2fd27789f1ef..0ce3f7c99984 100644 --- a/packages/node/test/integration/transactions.test.ts +++ b/packages/node/test/integration/transactions.test.ts @@ -1,7 +1,7 @@ import { context, trace, TraceFlags } from '@opentelemetry/api'; import type { SpanProcessor } from '@opentelemetry/sdk-trace-base'; import type { TransactionEvent } from '@sentry/core'; -import { debug, logger, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; +import { debug, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; import { SentrySpanProcessor } from '@sentry/opentelemetry'; import { afterEach, describe, expect, it, vi } from 'vitest'; import * as Sentry from '../../src'; @@ -558,8 +558,6 @@ describe('Integration | Transactions', () => { vi.setSystemTime(now); const logs: unknown[] = []; - // TODO: Remove this once node is using debug instead of logger - vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg)); vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg)); mockSdkInit({ tracesSampleRate: 1, beforeSendTransaction }); @@ -638,8 +636,6 @@ describe('Integration | Transactions', () => { vi.setSystemTime(now); const logs: unknown[] = []; - // TODO: Remove this once node is using debug instead of logger - vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg)); vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg)); mockSdkInit({ diff --git a/packages/node/test/sdk/init.test.ts b/packages/node/test/sdk/init.test.ts index 1aa11387f5c3..422bbdc924f4 100644 --- a/packages/node/test/sdk/init.test.ts +++ b/packages/node/test/sdk/init.test.ts @@ -1,5 +1,5 @@ import type { Integration } from '@sentry/core'; -import { logger, SDK_VERSION } from '@sentry/core'; +import { debug, SDK_VERSION } from '@sentry/core'; import * as SentryOpentelemetry from '@sentry/opentelemetry'; import { type Mock, type MockInstance, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { getClient, NodeClient, validateOpenTelemetrySetup } from '../../src/'; @@ -26,8 +26,8 @@ describe('init()', () => { beforeEach(() => { global.__SENTRY__ = {}; - // prevent the logger from being enabled, resulting in console.log calls - vi.spyOn(logger, 'enable').mockImplementation(() => {}); + // prevent the debug from being enabled, resulting in console.log calls + vi.spyOn(debug, 'enable').mockImplementation(() => {}); mockAutoPerformanceIntegrations = vi.spyOn(auto, 'getAutoPerformanceIntegrations').mockImplementation(() => []); }); @@ -285,8 +285,8 @@ describe('validateOpenTelemetrySetup', () => { }); it('works with correct setup', () => { - const errorSpy = vi.spyOn(logger, 'error').mockImplementation(() => {}); - const warnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); + const errorSpy = vi.spyOn(debug, 'error').mockImplementation(() => {}); + const warnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {}); vi.spyOn(SentryOpentelemetry, 'openTelemetrySetupCheck').mockImplementation(() => { return ['SentryContextManager', 'SentryPropagator', 'SentrySampler']; @@ -299,8 +299,8 @@ describe('validateOpenTelemetrySetup', () => { }); it('works with missing setup, without tracing', () => { - const errorSpy = vi.spyOn(logger, 'error').mockImplementation(() => {}); - const warnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); + const errorSpy = vi.spyOn(debug, 'error').mockImplementation(() => {}); + const warnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {}); vi.spyOn(SentryOpentelemetry, 'openTelemetrySetupCheck').mockImplementation(() => { return []; @@ -318,8 +318,8 @@ describe('validateOpenTelemetrySetup', () => { }); it('works with missing setup, with tracing', () => { - const errorSpy = vi.spyOn(logger, 'error').mockImplementation(() => {}); - const warnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); + const errorSpy = vi.spyOn(debug, 'error').mockImplementation(() => {}); + const warnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {}); vi.spyOn(SentryOpentelemetry, 'openTelemetrySetupCheck').mockImplementation(() => { return []; diff --git a/packages/node/test/sdk/initOtel.test.ts b/packages/node/test/sdk/initOtel.test.ts index 69c1da3fc258..a373d733457b 100644 --- a/packages/node/test/sdk/initOtel.test.ts +++ b/packages/node/test/sdk/initOtel.test.ts @@ -1,4 +1,4 @@ -import { logger } from '@sentry/core'; +import { debug } from '@sentry/core'; import { beforeEach, describe, expect, it, vi } from 'vitest'; import { _clampSpanProcessorTimeout } from '../../src/sdk/initOtel'; @@ -8,71 +8,71 @@ describe('_clampSpanProcessorTimeout', () => { }); it('works with undefined', () => { - const loggerWarnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); + const debugWarnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {}); const timeout = _clampSpanProcessorTimeout(undefined); expect(timeout).toBe(undefined); - expect(loggerWarnSpy).not.toHaveBeenCalled(); + expect(debugWarnSpy).not.toHaveBeenCalled(); }); it('works with positive number', () => { - const loggerWarnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); + const debugWarnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {}); const timeout = _clampSpanProcessorTimeout(10); expect(timeout).toBe(10); - expect(loggerWarnSpy).not.toHaveBeenCalled(); + expect(debugWarnSpy).not.toHaveBeenCalled(); }); it('works with 0', () => { - const loggerWarnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); + const debugWarnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {}); const timeout = _clampSpanProcessorTimeout(0); expect(timeout).toBe(undefined); - expect(loggerWarnSpy).toHaveBeenCalledTimes(1); - expect(loggerWarnSpy).toHaveBeenCalledWith( + expect(debugWarnSpy).toHaveBeenCalledTimes(1); + expect(debugWarnSpy).toHaveBeenCalledWith( '`maxSpanWaitDuration` must be a positive number, using default value instead.', ); }); it('works with negative number', () => { - const loggerWarnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); + const debugWarnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {}); const timeout = _clampSpanProcessorTimeout(-10); expect(timeout).toBe(undefined); - expect(loggerWarnSpy).toHaveBeenCalledTimes(1); - expect(loggerWarnSpy).toHaveBeenCalledWith( + expect(debugWarnSpy).toHaveBeenCalledTimes(1); + expect(debugWarnSpy).toHaveBeenCalledWith( '`maxSpanWaitDuration` must be a positive number, using default value instead.', ); }); it('works with -Infinity', () => { - const loggerWarnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); + const debugWarnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {}); const timeout = _clampSpanProcessorTimeout(-Infinity); expect(timeout).toBe(undefined); - expect(loggerWarnSpy).toHaveBeenCalledTimes(1); - expect(loggerWarnSpy).toHaveBeenCalledWith( + expect(debugWarnSpy).toHaveBeenCalledTimes(1); + expect(debugWarnSpy).toHaveBeenCalledWith( '`maxSpanWaitDuration` must be a positive number, using default value instead.', ); }); it('works with Infinity', () => { - const loggerWarnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); + const debugWarnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {}); const timeout = _clampSpanProcessorTimeout(Infinity); expect(timeout).toBe(1_000_000); - expect(loggerWarnSpy).toHaveBeenCalledTimes(1); - expect(loggerWarnSpy).toHaveBeenCalledWith('`maxSpanWaitDuration` is too high, using the maximum value of 1000000'); + expect(debugWarnSpy).toHaveBeenCalledTimes(1); + expect(debugWarnSpy).toHaveBeenCalledWith('`maxSpanWaitDuration` is too high, using the maximum value of 1000000'); }); it('works with large number', () => { - const loggerWarnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); + const debugWarnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {}); const timeout = _clampSpanProcessorTimeout(1_000_000_000); expect(timeout).toBe(1_000_000); - expect(loggerWarnSpy).toHaveBeenCalledTimes(1); - expect(loggerWarnSpy).toHaveBeenCalledWith('`maxSpanWaitDuration` is too high, using the maximum value of 1000000'); + expect(debugWarnSpy).toHaveBeenCalledTimes(1); + expect(debugWarnSpy).toHaveBeenCalledWith('`maxSpanWaitDuration` is too high, using the maximum value of 1000000'); }); it('works with NaN', () => { - const loggerWarnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); + const debugWarnSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {}); const timeout = _clampSpanProcessorTimeout(NaN); expect(timeout).toBe(undefined); - expect(loggerWarnSpy).toHaveBeenCalledTimes(1); - expect(loggerWarnSpy).toHaveBeenCalledWith( + expect(debugWarnSpy).toHaveBeenCalledTimes(1); + expect(debugWarnSpy).toHaveBeenCalledWith( '`maxSpanWaitDuration` must be a positive number, using default value instead.', ); }); diff --git a/packages/node/test/sdk/preload.test.ts b/packages/node/test/sdk/preload.test.ts index 8daf8ada5c4b..97badc28c9eb 100644 --- a/packages/node/test/sdk/preload.test.ts +++ b/packages/node/test/sdk/preload.test.ts @@ -1,10 +1,10 @@ -import { logger } from '@sentry/core'; +import { debug } from '@sentry/core'; import { afterEach, describe, expect, it, vi } from 'vitest'; describe('preload', () => { afterEach(() => { vi.resetAllMocks(); - logger.disable(); + debug.disable(); delete process.env.SENTRY_DEBUG; delete process.env.SENTRY_PRELOAD_INTEGRATIONS;