Skip to content

ref(browser): Use debug instead of logger #17029

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 3 commits into from
Jul 16, 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
4 changes: 2 additions & 2 deletions packages/browser-utils/src/getNativeImplementation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isNativeFunction, logger } from '@sentry/core';
import { debug, isNativeFunction } from '@sentry/core';
import { DEBUG_BUILD } from './debug-build';
import { WINDOW } from './types';

Expand Down Expand Up @@ -53,7 +53,7 @@ export function getNativeImplementation<T extends keyof CacheableImplementations
document.head.removeChild(sandbox);
} catch (e) {
// Could not create sandbox iframe, just use window.xxx
DEBUG_BUILD && logger.warn(`Could not create sandbox iframe for ${name} check, bailing to window.${name}: `, e);
DEBUG_BUILD && debug.warn(`Could not create sandbox iframe for ${name} check, bailing to window.${name}: `, e);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/browser-utils/src/metrics/cls.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Client, SpanAttributes } from '@sentry/core';
import {
browserPerformanceTimeOrigin,
debug,
getCurrentScope,
htmlTreeAsString,
logger,
SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME,
SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT,
SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE,
Expand Down Expand Up @@ -53,7 +53,7 @@ function sendStandaloneClsSpan(
pageloadSpanId: string,
reportEvent: WebVitalReportEvent,
) {
DEBUG_BUILD && logger.log(`Sending CLS span (${clsValue})`);
DEBUG_BUILD && debug.log(`Sending CLS span (${clsValue})`);

const startTime = msToSec((browserPerformanceTimeOrigin() || 0) + (entry?.startTime || 0));
const routeName = getCurrentScope().getScopeData().transactionName;
Expand Down
4 changes: 2 additions & 2 deletions packages/browser-utils/src/metrics/instrument.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getFunctionName, logger } from '@sentry/core';
import { debug, getFunctionName } from '@sentry/core';
import { DEBUG_BUILD } from '../debug-build';
import { onCLS } from './web-vitals/getCLS';
import { onFID } from './web-vitals/getFID';
Expand Down Expand Up @@ -214,7 +214,7 @@ function triggerHandlers(type: InstrumentHandlerType, data: unknown): void {
handler(data);
} catch (e) {
DEBUG_BUILD &&
logger.error(
debug.error(
`Error while triggering instrumentation handler.\nType: ${type}\nName: ${getFunctionName(handler)}\nError:`,
e,
);
Expand Down
4 changes: 2 additions & 2 deletions packages/browser-utils/src/metrics/lcp.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Client, SpanAttributes } from '@sentry/core';
import {
browserPerformanceTimeOrigin,
debug,
getCurrentScope,
htmlTreeAsString,
logger,
SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME,
SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT,
SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE,
Expand Down Expand Up @@ -56,7 +56,7 @@ export function _sendStandaloneLcpSpan(
pageloadSpanId: string,
reportEvent: WebVitalReportEvent,
) {
DEBUG_BUILD && logger.log(`Sending LCP span (${lcpValue})`);
DEBUG_BUILD && debug.log(`Sending LCP span (${lcpValue})`);

const startTime = msToSec((browserPerformanceTimeOrigin() || 0) + (entry?.startTime || 0));
const routeName = getCurrentScope().getScopeData().transactionName;
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import {
addBreadcrumb,
addConsoleInstrumentationHandler,
addFetchInstrumentationHandler,
debug,
defineIntegration,
getBreadcrumbLogLevelFromHttpStatusCode,
getClient,
getComponentName,
getEventDescription,
htmlTreeAsString,
logger,
parseUrl,
safeJoin,
severityLevelFromString,
Expand Down Expand Up @@ -142,7 +142,7 @@ function _getDomBreadcrumbHandler(
typeof dom === 'object' && typeof dom.maxStringLength === 'number' ? dom.maxStringLength : undefined;
if (maxStringLength && maxStringLength > MAX_ALLOWED_STRING_LENGTH) {
DEBUG_BUILD &&
logger.warn(
debug.warn(
`\`dom.maxStringLength\` cannot exceed ${MAX_ALLOWED_STRING_LENGTH}, but a value of ${maxStringLength} was configured. Sentry will use ${MAX_ALLOWED_STRING_LENGTH} instead.`,
);
maxStringLength = MAX_ALLOWED_STRING_LENGTH;
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/integrations/browsersession.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { captureSession, defineIntegration, logger, startSession } from '@sentry/core';
import { captureSession, debug, defineIntegration, startSession } from '@sentry/core';
import { addHistoryInstrumentationHandler } from '@sentry-internal/browser-utils';
import { DEBUG_BUILD } from '../debug-build';
import { WINDOW } from '../helpers';
Expand All @@ -15,7 +15,7 @@ export const browserSessionIntegration = defineIntegration(() => {
setupOnce() {
if (typeof WINDOW.document === 'undefined') {
DEBUG_BUILD &&
logger.warn('Using the `browserSessionIntegration` in non-browser environments is not supported.');
debug.warn('Using the `browserSessionIntegration` in non-browser environments is not supported.');
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
_INTERNAL_addFeatureFlagToActiveSpan,
_INTERNAL_copyFlagsFromScopeToEvent,
_INTERNAL_insertFlagToScope,
debug,
defineIntegration,
fill,
logger,
} from '@sentry/core';
import { DEBUG_BUILD } from '../../../debug-build';
import type { UnleashClient, UnleashClientClass } from './types';
Expand Down Expand Up @@ -73,7 +73,7 @@ function _wrappedIsEnabled(
_INTERNAL_insertFlagToScope(toggleName, result);
_INTERNAL_addFeatureFlagToActiveSpan(toggleName, result);
} else if (DEBUG_BUILD) {
logger.error(
debug.error(
`[Feature Flags] UnleashClient.isEnabled does not match expected signature. arg0: ${toggleName} (${typeof toggleName}), result: ${result} (${typeof result})`,
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {
addGlobalErrorInstrumentationHandler,
addGlobalUnhandledRejectionInstrumentationHandler,
captureEvent,
debug,
defineIntegration,
getClient,
getLocationHref,
isPrimitive,
isString,
logger,
UNKNOWN_FUNCTION,
} from '@sentry/core';
import type { BrowserClient } from '../client';
Expand Down Expand Up @@ -188,7 +188,7 @@ function _enhanceEventWithInitialFrame(
}

function globalHandlerLog(type: string): void {
DEBUG_BUILD && logger.log(`Global Handler attached: ${type}`);
DEBUG_BUILD && debug.log(`Global Handler attached: ${type}`);
}

function getOptions(): { stackParser: StackParser; attachStacktrace?: boolean } {
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/integrations/httpclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import {
addExceptionMechanism,
addFetchInstrumentationHandler,
captureEvent,
debug,
defineIntegration,
getClient,
GLOBAL_OBJ,
isSentryRequestUrl,
logger,
supportsNativeFetch,
} from '@sentry/core';
import { addXhrInstrumentationHandler, SENTRY_XHR_DATA_KEY } from '@sentry-internal/browser-utils';
Expand Down Expand Up @@ -333,7 +333,7 @@ function _wrapXHR(client: Client, options: HttpClientOptions): void {
try {
_xhrResponseHandler(options, xhr, method, headers, error || virtualError);
} catch (e) {
DEBUG_BUILD && logger.warn('Error while extracting response event form XHR response', e);
DEBUG_BUILD && debug.warn('Error while extracting response event form XHR response', e);
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions packages/browser/src/integrations/spotlight.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Client, Envelope, Event, IntegrationFn } from '@sentry/core';
import { defineIntegration, logger, serializeEnvelope } from '@sentry/core';
import { debug, defineIntegration, serializeEnvelope } from '@sentry/core';
import { getNativeImplementation } from '@sentry-internal/browser-utils';
import { DEBUG_BUILD } from '../debug-build';
import type { WINDOW } from '../helpers';
Expand All @@ -20,7 +20,7 @@ const _spotlightIntegration = ((options: Partial<SpotlightConnectionOptions> = {
return {
name: INTEGRATION_NAME,
setup: () => {
DEBUG_BUILD && logger.log('Using Sidecar URL', sidecarUrl);
DEBUG_BUILD && debug.log('Using Sidecar URL', sidecarUrl);
},
// We don't want to send interaction transactions/root spans created from
// clicks within Spotlight to Sentry. Neither do we want them to be sent to
Expand All @@ -38,7 +38,7 @@ function setupSidecarForwarding(client: Client, sidecarUrl: string): void {

client.on('beforeEnvelope', (envelope: Envelope) => {
if (failCount > 3) {
logger.warn('[Spotlight] Disabled Sentry -> Spotlight integration due to too many failed requests:', failCount);
debug.warn('[Spotlight] Disabled Sentry -> Spotlight integration due to too many failed requests:', failCount);
return;
}

Expand All @@ -58,7 +58,7 @@ function setupSidecarForwarding(client: Client, sidecarUrl: string): void {
},
err => {
failCount++;
logger.error(
debug.error(
"Sentry SDK can't connect to Sidecar is it running? See: https://spotlightjs.com/sidecar/npx/",
err,
);
Expand Down
8 changes: 4 additions & 4 deletions packages/browser/src/profiling/integration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { EventEnvelope, IntegrationFn, Profile, Span } from '@sentry/core';
import { defineIntegration, getActiveSpan, getRootSpan, logger } from '@sentry/core';
import { debug, defineIntegration, getActiveSpan, getRootSpan } from '@sentry/core';
import { DEBUG_BUILD } from '../debug-build';
import { startProfileForSpan } from './startProfileForSpan';
import type { ProfiledEvent } from './utils';
Expand Down Expand Up @@ -53,12 +53,12 @@ const _browserProfilingIntegration = (() => {
const start_timestamp = context?.profile?.['start_timestamp'];

if (typeof profile_id !== 'string') {
DEBUG_BUILD && logger.log('[Profiling] cannot find profile for a span without a profile context');
DEBUG_BUILD && debug.log('[Profiling] cannot find profile for a span without a profile context');
continue;
}

if (!profile_id) {
DEBUG_BUILD && logger.log('[Profiling] cannot find profile for a span without a profile context');
DEBUG_BUILD && debug.log('[Profiling] cannot find profile for a span without a profile context');
continue;
}

Expand All @@ -69,7 +69,7 @@ const _browserProfilingIntegration = (() => {

const profile = takeProfileFromGlobalCache(profile_id);
if (!profile) {
DEBUG_BUILD && logger.log(`[Profiling] Could not retrieve profile for span: ${profile_id}`);
DEBUG_BUILD && debug.log(`[Profiling] Could not retrieve profile for span: ${profile_id}`);
continue;
}

Expand Down
14 changes: 7 additions & 7 deletions packages/browser/src/profiling/startProfileForSpan.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Span } from '@sentry/core';
import { getCurrentScope, logger, spanToJSON, timestampInSeconds, uuid4 } from '@sentry/core';
import { debug, getCurrentScope, spanToJSON, timestampInSeconds, uuid4 } from '@sentry/core';
import { DEBUG_BUILD } from '../debug-build';
import { WINDOW } from '../helpers';
import type { JSSelfProfile } from './jsSelfProfiling';
Expand All @@ -26,7 +26,7 @@ export function startProfileForSpan(span: Span): void {
}

if (DEBUG_BUILD) {
logger.log(`[Profiling] started profiling span: ${spanToJSON(span).description}`);
debug.log(`[Profiling] started profiling span: ${spanToJSON(span).description}`);
}

// We create "unique" span names to avoid concurrent spans with same names
Expand Down Expand Up @@ -62,7 +62,7 @@ export function startProfileForSpan(span: Span): void {
}
if (processedProfile) {
if (DEBUG_BUILD) {
logger.log('[Profiling] profile for:', spanToJSON(span).description, 'already exists, returning early');
debug.log('[Profiling] profile for:', spanToJSON(span).description, 'already exists, returning early');
}
return;
}
Expand All @@ -76,13 +76,13 @@ export function startProfileForSpan(span: Span): void {
}

if (DEBUG_BUILD) {
logger.log(`[Profiling] stopped profiling of span: ${spanToJSON(span).description}`);
debug.log(`[Profiling] stopped profiling of span: ${spanToJSON(span).description}`);
}

// In case of an overlapping span, stopProfiling may return null and silently ignore the overlapping profile.
if (!profile) {
if (DEBUG_BUILD) {
logger.log(
debug.log(
`[Profiling] profiler returned null profile for: ${spanToJSON(span).description}`,
'this may indicate an overlapping span or a call to stopProfiling with a profile title that was never started',
);
Expand All @@ -94,15 +94,15 @@ export function startProfileForSpan(span: Span): void {
})
.catch(error => {
if (DEBUG_BUILD) {
logger.log('[Profiling] error while stopping profiler:', error);
debug.log('[Profiling] error while stopping profiler:', error);
}
});
}

// Enqueue a timeout to prevent profiles from running over max duration.
let maxDurationTimeoutID: number | undefined = WINDOW.setTimeout(() => {
if (DEBUG_BUILD) {
logger.log('[Profiling] max profile duration elapsed, stopping profiling for:', spanToJSON(span).description);
debug.log('[Profiling] max profile duration elapsed, stopping profiling for:', spanToJSON(span).description);
}
// If the timeout exceeds, we want to stop profiling, but not finish the span
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Expand Down
Loading
Loading