Skip to content

Commit 549f8b1

Browse files
committed
ref(browser): Use debug instead of logger
1 parent c3a2281 commit 549f8b1

File tree

13 files changed

+54
-56
lines changed

13 files changed

+54
-56
lines changed

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import {
1919
addBreadcrumb,
2020
addConsoleInstrumentationHandler,
2121
addFetchInstrumentationHandler,
22+
debug,
2223
defineIntegration,
2324
getBreadcrumbLogLevelFromHttpStatusCode,
2425
getClient,
2526
getComponentName,
2627
getEventDescription,
2728
htmlTreeAsString,
28-
logger,
2929
parseUrl,
3030
safeJoin,
3131
severityLevelFromString,
@@ -142,7 +142,7 @@ function _getDomBreadcrumbHandler(
142142
typeof dom === 'object' && typeof dom.maxStringLength === 'number' ? dom.maxStringLength : undefined;
143143
if (maxStringLength && maxStringLength > MAX_ALLOWED_STRING_LENGTH) {
144144
DEBUG_BUILD &&
145-
logger.warn(
145+
debug.warn(
146146
`\`dom.maxStringLength\` cannot exceed ${MAX_ALLOWED_STRING_LENGTH}, but a value of ${maxStringLength} was configured. Sentry will use ${MAX_ALLOWED_STRING_LENGTH} instead.`,
147147
);
148148
maxStringLength = MAX_ALLOWED_STRING_LENGTH;

packages/browser/src/integrations/browsersession.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { captureSession, defineIntegration, logger, startSession } from '@sentry/core';
1+
import { captureSession, debug, defineIntegration, startSession } from '@sentry/core';
22
import { addHistoryInstrumentationHandler } from '@sentry-internal/browser-utils';
33
import { DEBUG_BUILD } from '../debug-build';
44
import { WINDOW } from '../helpers';
@@ -15,7 +15,7 @@ export const browserSessionIntegration = defineIntegration(() => {
1515
setupOnce() {
1616
if (typeof WINDOW.document === 'undefined') {
1717
DEBUG_BUILD &&
18-
logger.warn('Using the `browserSessionIntegration` in non-browser environments is not supported.');
18+
debug.warn('Using the `browserSessionIntegration` in non-browser environments is not supported.');
1919
return;
2020
}
2121

packages/browser/src/integrations/featureFlags/unleash/integration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import {
33
_INTERNAL_addFeatureFlagToActiveSpan,
44
_INTERNAL_copyFlagsFromScopeToEvent,
55
_INTERNAL_insertFlagToScope,
6+
debug,
67
defineIntegration,
78
fill,
8-
logger,
99
} from '@sentry/core';
1010
import { DEBUG_BUILD } from '../../../debug-build';
1111
import type { UnleashClient, UnleashClientClass } from './types';
@@ -73,7 +73,7 @@ function _wrappedIsEnabled(
7373
_INTERNAL_insertFlagToScope(toggleName, result);
7474
_INTERNAL_addFeatureFlagToActiveSpan(toggleName, result);
7575
} else if (DEBUG_BUILD) {
76-
logger.error(
76+
debug.error(
7777
`[Feature Flags] UnleashClient.isEnabled does not match expected signature. arg0: ${toggleName} (${typeof toggleName}), result: ${result} (${typeof result})`,
7878
);
7979
}

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import {
33
addGlobalErrorInstrumentationHandler,
44
addGlobalUnhandledRejectionInstrumentationHandler,
55
captureEvent,
6+
debug,
67
defineIntegration,
78
getClient,
89
getLocationHref,
910
isPrimitive,
1011
isString,
11-
logger,
1212
UNKNOWN_FUNCTION,
1313
} from '@sentry/core';
1414
import type { BrowserClient } from '../client';
@@ -188,7 +188,7 @@ function _enhanceEventWithInitialFrame(
188188
}
189189

190190
function globalHandlerLog(type: string): void {
191-
DEBUG_BUILD && logger.log(`Global Handler attached: ${type}`);
191+
DEBUG_BUILD && debug.log(`Global Handler attached: ${type}`);
192192
}
193193

194194
function getOptions(): { stackParser: StackParser; attachStacktrace?: boolean } {

packages/browser/src/integrations/httpclient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import {
33
addExceptionMechanism,
44
addFetchInstrumentationHandler,
55
captureEvent,
6+
debug,
67
defineIntegration,
78
getClient,
89
GLOBAL_OBJ,
910
isSentryRequestUrl,
10-
logger,
1111
supportsNativeFetch,
1212
} from '@sentry/core';
1313
import { addXhrInstrumentationHandler, SENTRY_XHR_DATA_KEY } from '@sentry-internal/browser-utils';
@@ -333,7 +333,7 @@ function _wrapXHR(client: Client, options: HttpClientOptions): void {
333333
try {
334334
_xhrResponseHandler(options, xhr, method, headers, error || virtualError);
335335
} catch (e) {
336-
DEBUG_BUILD && logger.warn('Error while extracting response event form XHR response', e);
336+
DEBUG_BUILD && debug.warn('Error while extracting response event form XHR response', e);
337337
}
338338
});
339339
}

packages/browser/src/integrations/spotlight.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Client, Envelope, Event, IntegrationFn } from '@sentry/core';
2-
import { defineIntegration, logger, serializeEnvelope } from '@sentry/core';
2+
import { debug, defineIntegration, serializeEnvelope } from '@sentry/core';
33
import { getNativeImplementation } from '@sentry-internal/browser-utils';
44
import { DEBUG_BUILD } from '../debug-build';
55
import type { WINDOW } from '../helpers';
@@ -20,7 +20,7 @@ const _spotlightIntegration = ((options: Partial<SpotlightConnectionOptions> = {
2020
return {
2121
name: INTEGRATION_NAME,
2222
setup: () => {
23-
DEBUG_BUILD && logger.log('Using Sidecar URL', sidecarUrl);
23+
DEBUG_BUILD && debug.log('Using Sidecar URL', sidecarUrl);
2424
},
2525
// We don't want to send interaction transactions/root spans created from
2626
// 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 {
3838

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

@@ -58,7 +58,7 @@ function setupSidecarForwarding(client: Client, sidecarUrl: string): void {
5858
},
5959
err => {
6060
failCount++;
61-
logger.error(
61+
debug.error(
6262
"Sentry SDK can't connect to Sidecar is it running? See: https://spotlightjs.com/sidecar/npx/",
6363
err,
6464
);

packages/browser/src/profiling/integration.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { EventEnvelope, IntegrationFn, Profile, Span } from '@sentry/core';
2-
import { defineIntegration, getActiveSpan, getRootSpan, logger } from '@sentry/core';
2+
import { debug, defineIntegration, getActiveSpan, getRootSpan } from '@sentry/core';
33
import { DEBUG_BUILD } from '../debug-build';
44
import { startProfileForSpan } from './startProfileForSpan';
55
import type { ProfiledEvent } from './utils';
@@ -53,12 +53,12 @@ const _browserProfilingIntegration = (() => {
5353
const start_timestamp = context?.profile?.['start_timestamp'];
5454

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

6060
if (!profile_id) {
61-
DEBUG_BUILD && logger.log('[Profiling] cannot find profile for a span without a profile context');
61+
DEBUG_BUILD && debug.log('[Profiling] cannot find profile for a span without a profile context');
6262
continue;
6363
}
6464

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

7070
const profile = takeProfileFromGlobalCache(profile_id);
7171
if (!profile) {
72-
DEBUG_BUILD && logger.log(`[Profiling] Could not retrieve profile for span: ${profile_id}`);
72+
DEBUG_BUILD && debug.log(`[Profiling] Could not retrieve profile for span: ${profile_id}`);
7373
continue;
7474
}
7575

packages/browser/src/profiling/startProfileForSpan.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Span } from '@sentry/core';
2-
import { getCurrentScope, logger, spanToJSON, timestampInSeconds, uuid4 } from '@sentry/core';
2+
import { debug, getCurrentScope, spanToJSON, timestampInSeconds, uuid4 } from '@sentry/core';
33
import { DEBUG_BUILD } from '../debug-build';
44
import { WINDOW } from '../helpers';
55
import type { JSSelfProfile } from './jsSelfProfiling';
@@ -26,7 +26,7 @@ export function startProfileForSpan(span: Span): void {
2626
}
2727

2828
if (DEBUG_BUILD) {
29-
logger.log(`[Profiling] started profiling span: ${spanToJSON(span).description}`);
29+
debug.log(`[Profiling] started profiling span: ${spanToJSON(span).description}`);
3030
}
3131

3232
// We create "unique" span names to avoid concurrent spans with same names
@@ -62,7 +62,7 @@ export function startProfileForSpan(span: Span): void {
6262
}
6363
if (processedProfile) {
6464
if (DEBUG_BUILD) {
65-
logger.log('[Profiling] profile for:', spanToJSON(span).description, 'already exists, returning early');
65+
debug.log('[Profiling] profile for:', spanToJSON(span).description, 'already exists, returning early');
6666
}
6767
return;
6868
}
@@ -76,13 +76,13 @@ export function startProfileForSpan(span: Span): void {
7676
}
7777

7878
if (DEBUG_BUILD) {
79-
logger.log(`[Profiling] stopped profiling of span: ${spanToJSON(span).description}`);
79+
debug.log(`[Profiling] stopped profiling of span: ${spanToJSON(span).description}`);
8080
}
8181

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

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

packages/browser/src/profiling/utils.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import type { DebugImage, Envelope, Event, EventEnvelope, Profile, Span, ThreadCpuProfile } from '@sentry/core';
33
import {
44
browserPerformanceTimeOrigin,
5+
debug,
56
DEFAULT_ENVIRONMENT,
67
forEachEnvelopeItem,
78
getClient,
89
getDebugImagesForResources,
9-
logger,
1010
spanToJSON,
1111
timestampInSeconds,
1212
uuid4,
@@ -104,7 +104,7 @@ function getTraceId(event: Event): string {
104104
// warn users that this is happening if they enable debug flag
105105
if (typeof traceId === 'string' && traceId.length !== 32) {
106106
if (DEBUG_BUILD) {
107-
logger.log(`[Profiling] Invalid traceId: ${traceId} on profiled event`);
107+
debug.log(`[Profiling] Invalid traceId: ${traceId} on profiled event`);
108108
}
109109
}
110110
if (typeof traceId !== 'string') {
@@ -364,7 +364,7 @@ export function isValidSampleRate(rate: unknown): boolean {
364364
// we need to check NaN explicitly because it's of type 'number' and therefore wouldn't get caught by this typecheck
365365
if ((typeof rate !== 'number' && typeof rate !== 'boolean') || (typeof rate === 'number' && isNaN(rate))) {
366366
DEBUG_BUILD &&
367-
logger.warn(
367+
debug.warn(
368368
`[Profiling] Invalid sample rate. Sample rate must be a boolean or a number between 0 and 1. Got ${JSON.stringify(
369369
rate,
370370
)} of type ${JSON.stringify(typeof rate)}.`,
@@ -379,7 +379,7 @@ export function isValidSampleRate(rate: unknown): boolean {
379379

380380
// in case sampleRate is a boolean, it will get automatically cast to 1 if it's true and 0 if it's false
381381
if (rate < 0 || rate > 1) {
382-
DEBUG_BUILD && logger.warn(`[Profiling] Invalid sample rate. Sample rate must be between 0 and 1. Got ${rate}.`);
382+
DEBUG_BUILD && debug.warn(`[Profiling] Invalid sample rate. Sample rate must be between 0 and 1. Got ${rate}.`);
383383
return false;
384384
}
385385
return true;
@@ -391,14 +391,14 @@ function isValidProfile(profile: JSSelfProfile): profile is JSSelfProfile & { pr
391391
// Log a warning if the profile has less than 2 samples so users can know why
392392
// they are not seeing any profiling data and we cant avoid the back and forth
393393
// of asking them to provide us with a dump of the profile data.
394-
logger.log('[Profiling] Discarding profile because it contains less than 2 samples');
394+
debug.log('[Profiling] Discarding profile because it contains less than 2 samples');
395395
}
396396
return false;
397397
}
398398

399399
if (!profile.frames.length) {
400400
if (DEBUG_BUILD) {
401-
logger.log('[Profiling] Discarding profile because it contains no frames');
401+
debug.log('[Profiling] Discarding profile because it contains no frames');
402402
}
403403
return false;
404404
}
@@ -428,9 +428,7 @@ export function startJSSelfProfile(): JSSelfProfiler | undefined {
428428

429429
if (!isJSProfilerSupported(JSProfilerConstructor)) {
430430
if (DEBUG_BUILD) {
431-
logger.log(
432-
'[Profiling] Profiling is not supported by this browser, Profiler interface missing on window object.',
433-
);
431+
debug.log('[Profiling] Profiling is not supported by this browser, Profiler interface missing on window object.');
434432
}
435433
return;
436434
}
@@ -447,10 +445,10 @@ export function startJSSelfProfile(): JSSelfProfiler | undefined {
447445
return new JSProfilerConstructor({ sampleInterval: samplingIntervalMS, maxBufferSize: maxSamples });
448446
} catch (e) {
449447
if (DEBUG_BUILD) {
450-
logger.log(
448+
debug.log(
451449
"[Profiling] Failed to initialize the Profiling constructor, this is likely due to a missing 'Document-Policy': 'js-profiling' header.",
452450
);
453-
logger.log('[Profiling] Disabling profiling for current user session.');
451+
debug.log('[Profiling] Disabling profiling for current user session.');
454452
}
455453
PROFILING_CONSTRUCTOR_FAILED = true;
456454
}
@@ -465,22 +463,22 @@ export function shouldProfileSpan(span: Span): boolean {
465463
// If constructor failed once, it will always fail, so we can early return.
466464
if (PROFILING_CONSTRUCTOR_FAILED) {
467465
if (DEBUG_BUILD) {
468-
logger.log('[Profiling] Profiling has been disabled for the duration of the current user session.');
466+
debug.log('[Profiling] Profiling has been disabled for the duration of the current user session.');
469467
}
470468
return false;
471469
}
472470

473471
if (!span.isRecording()) {
474472
if (DEBUG_BUILD) {
475-
logger.log('[Profiling] Discarding profile because transaction was not sampled.');
473+
debug.log('[Profiling] Discarding profile because transaction was not sampled.');
476474
}
477475
return false;
478476
}
479477

480478
const client = getClient();
481479
const options = client?.getOptions();
482480
if (!options) {
483-
DEBUG_BUILD && logger.log('[Profiling] Profiling disabled, no options found.');
481+
DEBUG_BUILD && debug.log('[Profiling] Profiling disabled, no options found.');
484482
return false;
485483
}
486484

@@ -490,14 +488,14 @@ export function shouldProfileSpan(span: Span): boolean {
490488
// Since this is coming from the user (or from a function provided by the user), who knows what we might get. (The
491489
// only valid values are booleans or numbers between 0 and 1.)
492490
if (!isValidSampleRate(profilesSampleRate)) {
493-
DEBUG_BUILD && logger.warn('[Profiling] Discarding profile because of invalid sample rate.');
491+
DEBUG_BUILD && debug.warn('[Profiling] Discarding profile because of invalid sample rate.');
494492
return false;
495493
}
496494

497495
// if the function returned 0 (or false), or if `profileSampleRate` is 0, it's a sign the profile should be dropped
498496
if (!profilesSampleRate) {
499497
DEBUG_BUILD &&
500-
logger.log(
498+
debug.log(
501499
'[Profiling] Discarding profile because a negative sampling decision was inherited or profileSampleRate is set to 0',
502500
);
503501
return false;
@@ -509,7 +507,7 @@ export function shouldProfileSpan(span: Span): boolean {
509507
// Check if we should sample this profile
510508
if (!sampled) {
511509
DEBUG_BUILD &&
512-
logger.log(
510+
debug.log(
513511
`[Profiling] Discarding profile because it's not included in the random sample (sampling rate = ${Number(
514512
profilesSampleRate,
515513
)})`,

packages/browser/src/report-dialog.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ReportDialogOptions } from '@sentry/core';
2-
import { getClient, getCurrentScope, getReportDialogEndpoint, lastEventId, logger } from '@sentry/core';
2+
import { debug, getClient, getCurrentScope, getReportDialogEndpoint, lastEventId } from '@sentry/core';
33
import { DEBUG_BUILD } from './debug-build';
44
import { WINDOW } from './helpers';
55

@@ -14,7 +14,7 @@ export function showReportDialog(options: ReportDialogOptions = {}): void {
1414

1515
// doesn't work without a document (React Native)
1616
if (!injectionPoint) {
17-
DEBUG_BUILD && logger.error('[showReportDialog] Global document not defined');
17+
DEBUG_BUILD && debug.error('[showReportDialog] Global document not defined');
1818
return;
1919
}
2020

@@ -23,7 +23,7 @@ export function showReportDialog(options: ReportDialogOptions = {}): void {
2323
const dsn = client?.getDsn();
2424

2525
if (!dsn) {
26-
DEBUG_BUILD && logger.error('[showReportDialog] DSN not configured');
26+
DEBUG_BUILD && debug.error('[showReportDialog] DSN not configured');
2727
return;
2828
}
2929

0 commit comments

Comments
 (0)