diff --git a/packages/browser-utils/src/getNativeImplementation.ts b/packages/browser-utils/src/getNativeImplementation.ts index 398a40045119..410d2abf4de0 100644 --- a/packages/browser-utils/src/getNativeImplementation.ts +++ b/packages/browser-utils/src/getNativeImplementation.ts @@ -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'; @@ -53,7 +53,7 @@ export function getNativeImplementation 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; diff --git a/packages/browser/src/integrations/browsersession.ts b/packages/browser/src/integrations/browsersession.ts index ac74951b6596..78a9228e3b29 100644 --- a/packages/browser/src/integrations/browsersession.ts +++ b/packages/browser/src/integrations/browsersession.ts @@ -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'; @@ -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; } diff --git a/packages/browser/src/integrations/featureFlags/unleash/integration.ts b/packages/browser/src/integrations/featureFlags/unleash/integration.ts index 699c797edecf..c822b49f8810 100644 --- a/packages/browser/src/integrations/featureFlags/unleash/integration.ts +++ b/packages/browser/src/integrations/featureFlags/unleash/integration.ts @@ -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'; @@ -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})`, ); } diff --git a/packages/browser/src/integrations/globalhandlers.ts b/packages/browser/src/integrations/globalhandlers.ts index fa4420a0416e..74e78c37679e 100644 --- a/packages/browser/src/integrations/globalhandlers.ts +++ b/packages/browser/src/integrations/globalhandlers.ts @@ -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'; @@ -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 } { diff --git a/packages/browser/src/integrations/httpclient.ts b/packages/browser/src/integrations/httpclient.ts index 11763b34d581..9aaa476b7618 100644 --- a/packages/browser/src/integrations/httpclient.ts +++ b/packages/browser/src/integrations/httpclient.ts @@ -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'; @@ -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); } }); } diff --git a/packages/browser/src/integrations/spotlight.ts b/packages/browser/src/integrations/spotlight.ts index 703d3c14492f..481648f31138 100644 --- a/packages/browser/src/integrations/spotlight.ts +++ b/packages/browser/src/integrations/spotlight.ts @@ -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'; @@ -20,7 +20,7 @@ const _spotlightIntegration = ((options: Partial = { 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 @@ -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; } @@ -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, ); diff --git a/packages/browser/src/profiling/integration.ts b/packages/browser/src/profiling/integration.ts index 0f676bc1156c..7ad77d8920e5 100644 --- a/packages/browser/src/profiling/integration.ts +++ b/packages/browser/src/profiling/integration.ts @@ -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'; @@ -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; } @@ -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; } diff --git a/packages/browser/src/profiling/startProfileForSpan.ts b/packages/browser/src/profiling/startProfileForSpan.ts index 548508331646..b60a207abbce 100644 --- a/packages/browser/src/profiling/startProfileForSpan.ts +++ b/packages/browser/src/profiling/startProfileForSpan.ts @@ -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'; @@ -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 @@ -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; } @@ -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', ); @@ -94,7 +94,7 @@ 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); } }); } @@ -102,7 +102,7 @@ export function startProfileForSpan(span: Span): void { // 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 diff --git a/packages/browser/src/profiling/utils.ts b/packages/browser/src/profiling/utils.ts index 9e5718805b52..66b202c8517f 100644 --- a/packages/browser/src/profiling/utils.ts +++ b/packages/browser/src/profiling/utils.ts @@ -2,11 +2,11 @@ import type { DebugImage, Envelope, Event, EventEnvelope, Profile, Span, ThreadCpuProfile } from '@sentry/core'; import { browserPerformanceTimeOrigin, + debug, DEFAULT_ENVIRONMENT, forEachEnvelopeItem, getClient, getDebugImagesForResources, - logger, spanToJSON, timestampInSeconds, uuid4, @@ -104,7 +104,7 @@ function getTraceId(event: Event): string { // warn users that this is happening if they enable debug flag if (typeof traceId === 'string' && traceId.length !== 32) { if (DEBUG_BUILD) { - logger.log(`[Profiling] Invalid traceId: ${traceId} on profiled event`); + debug.log(`[Profiling] Invalid traceId: ${traceId} on profiled event`); } } if (typeof traceId !== 'string') { @@ -364,7 +364,7 @@ export function isValidSampleRate(rate: unknown): boolean { // we need to check NaN explicitly because it's of type 'number' and therefore wouldn't get caught by this typecheck if ((typeof rate !== 'number' && typeof rate !== 'boolean') || (typeof rate === 'number' && isNaN(rate))) { DEBUG_BUILD && - logger.warn( + debug.warn( `[Profiling] Invalid sample rate. Sample rate must be a boolean or a number between 0 and 1. Got ${JSON.stringify( rate, )} of type ${JSON.stringify(typeof rate)}.`, @@ -379,7 +379,7 @@ export function isValidSampleRate(rate: unknown): boolean { // in case sampleRate is a boolean, it will get automatically cast to 1 if it's true and 0 if it's false if (rate < 0 || rate > 1) { - DEBUG_BUILD && logger.warn(`[Profiling] Invalid sample rate. Sample rate must be between 0 and 1. Got ${rate}.`); + DEBUG_BUILD && debug.warn(`[Profiling] Invalid sample rate. Sample rate must be between 0 and 1. Got ${rate}.`); return false; } return true; @@ -391,14 +391,14 @@ function isValidProfile(profile: JSSelfProfile): profile is JSSelfProfile & { pr // Log a warning if the profile has less than 2 samples so users can know why // they are not seeing any profiling data and we cant avoid the back and forth // of asking them to provide us with a dump of the profile data. - logger.log('[Profiling] Discarding profile because it contains less than 2 samples'); + debug.log('[Profiling] Discarding profile because it contains less than 2 samples'); } return false; } if (!profile.frames.length) { if (DEBUG_BUILD) { - logger.log('[Profiling] Discarding profile because it contains no frames'); + debug.log('[Profiling] Discarding profile because it contains no frames'); } return false; } @@ -428,9 +428,7 @@ export function startJSSelfProfile(): JSSelfProfiler | undefined { if (!isJSProfilerSupported(JSProfilerConstructor)) { if (DEBUG_BUILD) { - logger.log( - '[Profiling] Profiling is not supported by this browser, Profiler interface missing on window object.', - ); + debug.log('[Profiling] Profiling is not supported by this browser, Profiler interface missing on window object.'); } return; } @@ -447,10 +445,10 @@ export function startJSSelfProfile(): JSSelfProfiler | undefined { return new JSProfilerConstructor({ sampleInterval: samplingIntervalMS, maxBufferSize: maxSamples }); } catch (e) { if (DEBUG_BUILD) { - logger.log( + debug.log( "[Profiling] Failed to initialize the Profiling constructor, this is likely due to a missing 'Document-Policy': 'js-profiling' header.", ); - logger.log('[Profiling] Disabling profiling for current user session.'); + debug.log('[Profiling] Disabling profiling for current user session.'); } PROFILING_CONSTRUCTOR_FAILED = true; } @@ -465,14 +463,14 @@ export function shouldProfileSpan(span: Span): boolean { // If constructor failed once, it will always fail, so we can early return. if (PROFILING_CONSTRUCTOR_FAILED) { if (DEBUG_BUILD) { - logger.log('[Profiling] Profiling has been disabled for the duration of the current user session.'); + debug.log('[Profiling] Profiling has been disabled for the duration of the current user session.'); } return false; } if (!span.isRecording()) { if (DEBUG_BUILD) { - logger.log('[Profiling] Discarding profile because transaction was not sampled.'); + debug.log('[Profiling] Discarding profile because transaction was not sampled.'); } return false; } @@ -480,7 +478,7 @@ export function shouldProfileSpan(span: Span): boolean { const client = getClient(); const options = client?.getOptions(); if (!options) { - DEBUG_BUILD && logger.log('[Profiling] Profiling disabled, no options found.'); + DEBUG_BUILD && debug.log('[Profiling] Profiling disabled, no options found.'); return false; } @@ -490,14 +488,14 @@ export function shouldProfileSpan(span: Span): boolean { // Since this is coming from the user (or from a function provided by the user), who knows what we might get. (The // only valid values are booleans or numbers between 0 and 1.) if (!isValidSampleRate(profilesSampleRate)) { - DEBUG_BUILD && logger.warn('[Profiling] Discarding profile because of invalid sample rate.'); + DEBUG_BUILD && debug.warn('[Profiling] Discarding profile because of invalid sample rate.'); return false; } // if the function returned 0 (or false), or if `profileSampleRate` is 0, it's a sign the profile should be dropped if (!profilesSampleRate) { DEBUG_BUILD && - logger.log( + debug.log( '[Profiling] Discarding profile because a negative sampling decision was inherited or profileSampleRate is set to 0', ); return false; @@ -509,7 +507,7 @@ export function shouldProfileSpan(span: Span): boolean { // Check if we should sample this profile if (!sampled) { DEBUG_BUILD && - logger.log( + debug.log( `[Profiling] Discarding profile because it's not included in the random sample (sampling rate = ${Number( profilesSampleRate, )})`, diff --git a/packages/browser/src/report-dialog.ts b/packages/browser/src/report-dialog.ts index 99b9cbd7733b..03255a7db91d 100644 --- a/packages/browser/src/report-dialog.ts +++ b/packages/browser/src/report-dialog.ts @@ -1,5 +1,5 @@ import type { ReportDialogOptions } from '@sentry/core'; -import { getClient, getCurrentScope, getReportDialogEndpoint, lastEventId, logger } from '@sentry/core'; +import { debug, getClient, getCurrentScope, getReportDialogEndpoint, lastEventId } from '@sentry/core'; import { DEBUG_BUILD } from './debug-build'; import { WINDOW } from './helpers'; @@ -14,7 +14,7 @@ export function showReportDialog(options: ReportDialogOptions = {}): void { // doesn't work without a document (React Native) if (!injectionPoint) { - DEBUG_BUILD && logger.error('[showReportDialog] Global document not defined'); + DEBUG_BUILD && debug.error('[showReportDialog] Global document not defined'); return; } @@ -23,7 +23,7 @@ export function showReportDialog(options: ReportDialogOptions = {}): void { const dsn = client?.getDsn(); if (!dsn) { - DEBUG_BUILD && logger.error('[showReportDialog] DSN not configured'); + DEBUG_BUILD && debug.error('[showReportDialog] DSN not configured'); return; } diff --git a/packages/browser/src/tracing/backgroundtab.ts b/packages/browser/src/tracing/backgroundtab.ts index e6241794d6d1..f8aeca761d85 100644 --- a/packages/browser/src/tracing/backgroundtab.ts +++ b/packages/browser/src/tracing/backgroundtab.ts @@ -1,4 +1,4 @@ -import { getActiveSpan, getRootSpan, logger, SPAN_STATUS_ERROR, spanToJSON } from '@sentry/core'; +import { debug, getActiveSpan, getRootSpan, SPAN_STATUS_ERROR, spanToJSON } from '@sentry/core'; import { DEBUG_BUILD } from '../debug-build'; import { WINDOW } from '../helpers'; @@ -22,7 +22,7 @@ export function registerBackgroundTabDetection(): void { const { op, status } = spanToJSON(rootSpan); if (DEBUG_BUILD) { - logger.log(`[Tracing] Transaction: ${cancelledStatus} -> since tab moved to the background, op: ${op}`); + debug.log(`[Tracing] Transaction: ${cancelledStatus} -> since tab moved to the background, op: ${op}`); } // We should not set status if it is already set, this prevent important statuses like @@ -36,6 +36,6 @@ export function registerBackgroundTabDetection(): void { } }); } else { - DEBUG_BUILD && logger.warn('[Tracing] Could not set up background tab detection due to lack of global document'); + DEBUG_BUILD && debug.warn('[Tracing] Could not set up background tab detection due to lack of global document'); } } diff --git a/packages/browser/src/tracing/browserTracingIntegration.ts b/packages/browser/src/tracing/browserTracingIntegration.ts index f010030c47c3..2a38f7afe7be 100644 --- a/packages/browser/src/tracing/browserTracingIntegration.ts +++ b/packages/browser/src/tracing/browserTracingIntegration.ts @@ -4,6 +4,7 @@ import { addNonEnumerableProperty, browserPerformanceTimeOrigin, dateTimestampInSeconds, + debug, generateTraceId, getClient, getCurrentScope, @@ -11,7 +12,6 @@ import { getIsolationScope, getLocationHref, GLOBAL_OBJ, - logger, parseStringToURLObject, propagationContextFromHeaders, registerSpanErrorInstrumentation, @@ -478,7 +478,7 @@ export const browserTracingIntegration = ((_options: Partial