Skip to content

feat(core): Introduce debug to replace logger #16906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { dsnToString, makeDsn } from './utils/dsn';
import { addItemToEnvelope, createAttachmentEnvelopeItem } from './utils/envelope';
import { getPossibleEventMessages } from './utils/eventUtils';
import { isParameterizedString, isPlainObject, isPrimitive, isThenable } from './utils/is';
import { logger } from './utils/logger';
import { debug } from './utils/logger';
import { merge } from './utils/merge';
import { checkOrSetAlreadyCaught, uuid4 } from './utils/misc';
import { parseSampleRate } from './utils/parseSampleRate';
Expand Down Expand Up @@ -154,7 +154,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
if (options.dsn) {
this._dsn = makeDsn(options.dsn);
} else {
DEBUG_BUILD && logger.warn('No DSN provided, client will not send events.');
DEBUG_BUILD && debug.warn('No DSN provided, client will not send events.');
}

if (this._dsn) {
Expand Down Expand Up @@ -182,7 +182,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {

// ensure we haven't captured this very object before
if (checkOrSetAlreadyCaught(exception)) {
DEBUG_BUILD && logger.log(ALREADY_SEEN_ERROR);
DEBUG_BUILD && debug.log(ALREADY_SEEN_ERROR);
return eventId;
}

Expand Down Expand Up @@ -237,7 +237,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {

// ensure we haven't captured this very object before
if (hint?.originalException && checkOrSetAlreadyCaught(hint.originalException)) {
DEBUG_BUILD && logger.log(ALREADY_SEEN_ERROR);
DEBUG_BUILD && debug.log(ALREADY_SEEN_ERROR);
return eventId;
}

Expand Down Expand Up @@ -429,15 +429,15 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
if ('aggregates' in session) {
const sessionAttrs = session.attrs || {};
if (!sessionAttrs.release && !clientReleaseOption) {
DEBUG_BUILD && logger.warn(MISSING_RELEASE_FOR_SESSION_ERROR);
DEBUG_BUILD && debug.warn(MISSING_RELEASE_FOR_SESSION_ERROR);
return;
}
sessionAttrs.release = sessionAttrs.release || clientReleaseOption;
sessionAttrs.environment = sessionAttrs.environment || clientEnvironmentOption;
session.attrs = sessionAttrs;
} else {
if (!session.release && !clientReleaseOption) {
DEBUG_BUILD && logger.warn(MISSING_RELEASE_FOR_SESSION_ERROR);
DEBUG_BUILD && debug.warn(MISSING_RELEASE_FOR_SESSION_ERROR);
return;
}
session.release = session.release || clientReleaseOption;
Expand Down Expand Up @@ -465,7 +465,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
// would be `Partial<Record<SentryRequestType, Partial<Record<Outcome, number>>>>`
// With typescript 4.1 we could even use template literal types
const key = `${reason}:${category}`;
DEBUG_BUILD && logger.log(`Recording outcome: "${key}"${count > 1 ? ` (${count} times)` : ''}`);
DEBUG_BUILD && debug.log(`Recording outcome: "${key}"${count > 1 ? ` (${count} times)` : ''}`);
this._outcomes[key] = (this._outcomes[key] || 0) + count;
}
}
Expand Down Expand Up @@ -866,12 +866,12 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {

if (this._isEnabled() && this._transport) {
return this._transport.send(envelope).then(null, reason => {
DEBUG_BUILD && logger.error('Error while sending envelope:', reason);
DEBUG_BUILD && debug.error('Error while sending envelope:', reason);
return reason;
});
}

DEBUG_BUILD && logger.error('Transport disabled');
DEBUG_BUILD && debug.error('Transport disabled');

return resolvedSyncPromise({});
}
Expand Down Expand Up @@ -1021,7 +1021,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
isolationScope = getIsolationScope(),
): PromiseLike<string | undefined> {
if (DEBUG_BUILD && isErrorEvent(event)) {
logger.log(`Captured error event \`${getPossibleEventMessages(event)[0] || '<unknown>'}\``);
debug.log(`Captured error event \`${getPossibleEventMessages(event)[0] || '<unknown>'}\``);
}

return this._processEvent(event, hint, currentScope, isolationScope).then(
Expand All @@ -1031,11 +1031,11 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
reason => {
if (DEBUG_BUILD) {
if (_isDoNotSendEventError(reason)) {
logger.log(reason.message);
debug.log(reason.message);
} else if (_isInternalError(reason)) {
logger.warn(reason.message);
debug.warn(reason.message);
} else {
logger.warn(reason);
debug.warn(reason);
}
}
return undefined;
Expand Down Expand Up @@ -1196,22 +1196,22 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
* Sends client reports as an envelope.
*/
protected _flushOutcomes(): void {
DEBUG_BUILD && logger.log('Flushing outcomes...');
DEBUG_BUILD && debug.log('Flushing outcomes...');

const outcomes = this._clearOutcomes();

if (outcomes.length === 0) {
DEBUG_BUILD && logger.log('No outcomes to send');
DEBUG_BUILD && debug.log('No outcomes to send');
return;
}

// This is really the only place where we want to check for a DSN and only send outcomes then
if (!this._dsn) {
DEBUG_BUILD && logger.log('No dsn provided, will not send outcomes');
DEBUG_BUILD && debug.log('No dsn provided, will not send outcomes');
return;
}

DEBUG_BUILD && logger.log('Sending outcomes:', outcomes);
DEBUG_BUILD && debug.log('Sending outcomes:', outcomes);

const envelope = createClientReportEnvelope(outcomes, this._options.tunnel && dsnToString(this._dsn));

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/eventProcessors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DEBUG_BUILD } from './debug-build';
import type { Event, EventHint } from './types-hoist/event';
import type { EventProcessor } from './types-hoist/eventprocessor';
import { isThenable } from './utils/is';
import { logger } from './utils/logger';
import { debug } from './utils/logger';
import { SyncPromise } from './utils/syncpromise';

/**
Expand All @@ -21,7 +21,7 @@ export function notifyEventProcessors(
} else {
const result = processor({ ...event }, hint) as Event | null;

DEBUG_BUILD && processor.id && result === null && logger.log(`Event processor "${processor.id}" dropped event`);
DEBUG_BUILD && processor.id && result === null && debug.log(`Event processor "${processor.id}" dropped event`);

if (isThenable(result)) {
void result
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { Session, SessionContext } from './types-hoist/session';
import type { SeverityLevel } from './types-hoist/severity';
import type { User } from './types-hoist/user';
import { isThenable } from './utils/is';
import { logger } from './utils/logger';
import { debug } from './utils/logger';
import { uuid4 } from './utils/misc';
import type { ExclusiveEventHintOrCaptureContext } from './utils/prepareEvent';
import { parseEventHintOrCaptureContext } from './utils/prepareEvent';
Expand Down Expand Up @@ -136,9 +136,9 @@ export function captureCheckIn(checkIn: CheckIn, upsertMonitorConfig?: MonitorCo
const scope = getCurrentScope();
const client = getClient();
if (!client) {
DEBUG_BUILD && logger.warn('Cannot capture check-in. No client defined.');
DEBUG_BUILD && debug.warn('Cannot capture check-in. No client defined.');
} else if (!client.captureCheckIn) {
DEBUG_BUILD && logger.warn('Cannot capture check-in. Client does not support sending check-ins.');
DEBUG_BUILD && debug.warn('Cannot capture check-in. Client does not support sending check-ins.');
} else {
return client.captureCheckIn(checkIn, upsertMonitorConfig, scope);
}
Expand Down Expand Up @@ -206,7 +206,7 @@ export async function flush(timeout?: number): Promise<boolean> {
if (client) {
return client.flush(timeout);
}
DEBUG_BUILD && logger.warn('Cannot flush events. No client defined.');
DEBUG_BUILD && debug.warn('Cannot flush events. No client defined.');
return Promise.resolve(false);
}

Expand All @@ -223,7 +223,7 @@ export async function close(timeout?: number): Promise<boolean> {
if (client) {
return client.close(timeout);
}
DEBUG_BUILD && logger.warn('Cannot flush events and disable SDK. No client defined.');
DEBUG_BUILD && debug.warn('Cannot flush events and disable SDK. No client defined.');
return Promise.resolve(false);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export {
isVueViewModel,
} from './utils/is';
export { isBrowser } from './utils/isBrowser';
export { CONSOLE_LEVELS, consoleSandbox, logger, originalConsoleMethods } from './utils/logger';
export { CONSOLE_LEVELS, consoleSandbox, debug, logger, originalConsoleMethods } from './utils/logger';
export type { Logger } from './utils/logger';
export {
addContextToFrame,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/instrument/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DEBUG_BUILD } from '../debug-build';
import { logger } from '../utils/logger';
import { debug } from '../utils/logger';
import { getFunctionName } from '../utils/stacktrace';

export type InstrumentHandlerType =
Expand Down Expand Up @@ -41,7 +41,7 @@ export function maybeInstrument(type: InstrumentHandlerType, instrumentFn: () =>
try {
instrumentFn();
} catch (e) {
DEBUG_BUILD && logger.error(`Error while instrumenting ${type}`, e);
DEBUG_BUILD && debug.error(`Error while instrumenting ${type}`, e);
}
}
}
Expand All @@ -58,7 +58,7 @@ export function triggerHandlers(type: InstrumentHandlerType, data: unknown): voi
handler(data);
} catch (e) {
DEBUG_BUILD &&
logger.error(
debug.error(
`Error while triggering instrumentation handler.\nType: ${type}\nName: ${getFunctionName(handler)}\nError:`,
e,
);
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DEBUG_BUILD } from './debug-build';
import type { Event, EventHint } from './types-hoist/event';
import type { Integration, IntegrationFn } from './types-hoist/integration';
import type { Options } from './types-hoist/options';
import { logger } from './utils/logger';
import { debug } from './utils/logger';

export const installedIntegrations: string[] = [];

Expand Down Expand Up @@ -99,7 +99,7 @@ export function afterSetupIntegrations(client: Client, integrations: Integration
/** Setup a single integration. */
export function setupIntegration(client: Client, integration: Integration, integrationIndex: IntegrationIndex): void {
if (integrationIndex[integration.name]) {
DEBUG_BUILD && logger.log(`Integration skipped because it was already installed: ${integration.name}`);
DEBUG_BUILD && debug.log(`Integration skipped because it was already installed: ${integration.name}`);
return;
}
integrationIndex[integration.name] = integration;
Expand Down Expand Up @@ -130,15 +130,15 @@ export function setupIntegration(client: Client, integration: Integration, integ
client.addEventProcessor(processor);
}

DEBUG_BUILD && logger.log(`Integration installed: ${integration.name}`);
DEBUG_BUILD && debug.log(`Integration installed: ${integration.name}`);
}

/** Add an integration to the current scope's client. */
export function addIntegration(integration: Integration): void {
const client = getClient();

if (!client) {
DEBUG_BUILD && logger.warn(`Cannot add integration "${integration.name}" because no SDK Client is available.`);
DEBUG_BUILD && debug.warn(`Cannot add integration "${integration.name}" because no SDK Client is available.`);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/integrations/dedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Event } from '../types-hoist/event';
import type { Exception } from '../types-hoist/exception';
import type { IntegrationFn } from '../types-hoist/integration';
import type { StackFrame } from '../types-hoist/stackframe';
import { logger } from '../utils/logger';
import { debug } from '../utils/logger';
import { getFramesFromEvent } from '../utils/stacktrace';

const INTEGRATION_NAME = 'Dedupe';
Expand All @@ -24,7 +24,7 @@ const _dedupeIntegration = (() => {
// Juuust in case something goes wrong
try {
if (_shouldDropEvent(currentEvent, previousEvent)) {
DEBUG_BUILD && logger.warn('Event dropped due to being a duplicate of previously captured event.');
DEBUG_BUILD && debug.warn('Event dropped due to being a duplicate of previously captured event.');
return null;
}
} catch (_oO) {} // eslint-disable-line no-empty
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/integrations/eventFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Event } from '../types-hoist/event';
import type { IntegrationFn } from '../types-hoist/integration';
import type { StackFrame } from '../types-hoist/stackframe';
import { getPossibleEventMessages } from '../utils/eventUtils';
import { logger } from '../utils/logger';
import { debug } from '../utils/logger';
import { getEventDescription } from '../utils/misc';
import { stringMatchesSomePattern } from '../utils/string';

Expand Down Expand Up @@ -111,14 +111,14 @@ function _shouldDropEvent(event: Event, options: Partial<EventFiltersOptions>):
// Filter errors
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
debug.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
debug.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
Expand All @@ -127,7 +127,7 @@ function _shouldDropEvent(event: Event, options: Partial<EventFiltersOptions>):
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
debug.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
Expand All @@ -136,7 +136,7 @@ function _shouldDropEvent(event: Event, options: Partial<EventFiltersOptions>):
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
debug.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
Expand All @@ -148,7 +148,7 @@ function _shouldDropEvent(event: Event, options: Partial<EventFiltersOptions>):

if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
debug.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
Expand Down Expand Up @@ -212,7 +212,7 @@ function _getEventFilterUrl(event: Event): string | null {
const frames = rootException?.stacktrace?.frames;
return frames ? _getLastValidUrl(frames) : null;
} catch (oO) {
DEBUG_BUILD && logger.error(`Cannot extract url for event ${getEventDescription(event)}`);
DEBUG_BUILD && debug.error(`Cannot extract url for event ${getEventDescription(event)}`);
return null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/integrations/extraerrordata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { ExtendedError } from '../types-hoist/error';
import type { Event, EventHint } from '../types-hoist/event';
import type { IntegrationFn } from '../types-hoist/integration';
import { isError, isPlainObject } from '../utils/is';
import { logger } from '../utils/logger';
import { debug } from '../utils/logger';
import { normalize } from '../utils/normalize';
import { addNonEnumerableProperty } from '../utils/object';
import { truncate } from '../utils/string';
Expand Down Expand Up @@ -130,7 +130,7 @@ function _extractErrorData(

return extraErrorInfo;
} catch (oO) {
DEBUG_BUILD && logger.error('Unable to extract extra data from the Error object:', oO);
DEBUG_BUILD && debug.error('Unable to extract extra data from the Error object:', oO);
}

return null;
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/integrations/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '
import { setHttpStatus, SPAN_STATUS_ERROR, SPAN_STATUS_OK, startSpan } from '../tracing';
import type { IntegrationFn } from '../types-hoist/integration';
import { isPlainObject } from '../utils/is';
import { logger } from '../utils/logger';
import { debug } from '../utils/logger';

const AUTH_OPERATIONS_TO_INSTRUMENT = [
'reauthenticate',
Expand Down Expand Up @@ -481,7 +481,7 @@ function instrumentPostgRESTQueryBuilder(PostgRESTQueryBuilder: new () => PostgR
const rv = Reflect.apply(target, thisArg, argumentsList);
const PostgRESTFilterBuilder = (rv as PostgRESTFilterBuilder).constructor;

DEBUG_BUILD && logger.log(`Instrumenting ${operation} operation's PostgRESTFilterBuilder`);
DEBUG_BUILD && debug.log(`Instrumenting ${operation} operation's PostgRESTFilterBuilder`);

instrumentPostgRESTFilterBuilder(PostgRESTFilterBuilder);

Expand All @@ -496,7 +496,7 @@ function instrumentPostgRESTQueryBuilder(PostgRESTQueryBuilder: new () => PostgR

export const instrumentSupabaseClient = (supabaseClient: unknown): void => {
if (!supabaseClient) {
DEBUG_BUILD && logger.warn('Supabase integration was not installed because no Supabase client was provided.');
DEBUG_BUILD && debug.warn('Supabase integration was not installed because no Supabase client was provided.');
return;
}
const SupabaseClientConstructor =
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/logs/console-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../semanticAttributes';
import type { ConsoleLevel } from '../types-hoist/instrument';
import type { IntegrationFn } from '../types-hoist/integration';
import { isPrimitive } from '../utils/is';
import { CONSOLE_LEVELS, logger } from '../utils/logger';
import { CONSOLE_LEVELS, debug } from '../utils/logger';
import { normalize } from '../utils/normalize';
import { GLOBAL_OBJ } from '../utils/worldwide';
import { _INTERNAL_captureLog } from './exports';
Expand Down Expand Up @@ -35,7 +35,7 @@ const _consoleLoggingIntegration = ((options: Partial<CaptureConsoleOptions> = {
setup(client) {
const { _experiments, normalizeDepth = 3, normalizeMaxBreadth = 1_000 } = client.getOptions();
if (!_experiments?.enableLogs) {
DEBUG_BUILD && logger.warn('`_experiments.enableLogs` is not enabled, ConsoleLogs integration disabled');
DEBUG_BUILD && debug.warn('`_experiments.enableLogs` is not enabled, ConsoleLogs integration disabled');
return;
}

Expand Down
Loading
Loading