Skip to content

Commit a188c9a

Browse files
committed
add debug guards to remaining calls to logger methods
1 parent 928e27e commit a188c9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+242
-193
lines changed

packages/angular/src/tracing.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AfterViewInit, Directive, Injectable, Input, NgModule, OnDestroy, OnIni
22
import { Event, NavigationEnd, NavigationStart, Router } from '@angular/router';
33
import { getCurrentHub } from '@sentry/browser';
44
import { Span, Transaction, TransactionContext } from '@sentry/types';
5-
import { getGlobalObject, logger, stripUrlQueryAndFragment, timestampWithMs } from '@sentry/utils';
5+
import { getGlobalObject, isDebugBuild, logger, stripUrlQueryAndFragment, timestampWithMs } from '@sentry/utils';
66
import { Observable, Subscription } from 'rxjs';
77
import { filter, tap } from 'rxjs/operators';
88

@@ -63,7 +63,8 @@ export class TraceService implements OnDestroy {
6363
filter(event => event instanceof NavigationStart),
6464
tap(event => {
6565
if (!instrumentationInitialized) {
66-
logger.error('Angular integration has tracing enabled, but Tracing integration is not configured');
66+
isDebugBuild() &&
67+
logger.error('Angular integration has tracing enabled, but Tracing integration is not configured');
6768
return;
6869
}
6970

packages/browser/src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
22
import { Event, EventHint } from '@sentry/types';
3-
import { getGlobalObject, logger } from '@sentry/utils';
3+
import { getGlobalObject, isDebugBuild, logger } from '@sentry/utils';
44

55
import { BrowserBackend, BrowserOptions } from './backend';
66
import { injectReportDialog, ReportDialogOptions } from './helpers';
@@ -47,7 +47,7 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
4747
}
4848

4949
if (!this._isEnabled()) {
50-
logger.error('Trying to call showReportDialog with Sentry Client disabled');
50+
isDebugBuild() && logger.error('Trying to call showReportDialog with Sentry Client disabled');
5151
return;
5252
}
5353

packages/browser/src/integrations/dedupe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Event, EventProcessor, Exception, Hub, Integration, StackFrame } from '@sentry/types';
2-
import { logger } from '@sentry/utils';
2+
import { isDebugBuild, logger } from '@sentry/utils';
33

44
/** Deduplication filter */
55
export class Dedupe implements Integration {
@@ -28,7 +28,7 @@ export class Dedupe implements Integration {
2828
// Juuust in case something goes wrong
2929
try {
3030
if (_shouldDropEvent(currentEvent, self._previousEvent)) {
31-
logger.warn('Event dropped due to being a duplicate of previously captured event.');
31+
isDebugBuild() && logger.warn('Event dropped due to being a duplicate of previously captured event.');
3232
return null;
3333
}
3434
} catch (_oO) {

packages/browser/src/transports/base.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export abstract class BaseTransport implements Transport {
105105
// A correct type for map-based implementation if we want to go that route
106106
// would be `Partial<Record<SentryRequestType, Partial<Record<Outcome, number>>>>`
107107
const key = `${requestTypeToCategory(category)}:${reason}`;
108-
logger.log(`Adding outcome: ${key}`);
108+
isDebugBuild() && logger.log(`Adding outcome: ${key}`);
109109
this._outcomes[key] = (this._outcomes[key] ?? 0) + 1;
110110
}
111111

@@ -122,11 +122,11 @@ export abstract class BaseTransport implements Transport {
122122

123123
// Nothing to send
124124
if (!Object.keys(outcomes).length) {
125-
logger.log('No outcomes to flush');
125+
isDebugBuild() && logger.log('No outcomes to flush');
126126
return;
127127
}
128128

129-
logger.log(`Flushing outcomes:\n${JSON.stringify(outcomes, null, 2)}`);
129+
isDebugBuild() && logger.log(`Flushing outcomes:\n${JSON.stringify(outcomes, null, 2)}`);
130130

131131
const url = getEnvelopeEndpointWithUrlEncodedAuth(this._api.dsn, this._api.tunnel);
132132

@@ -144,7 +144,7 @@ export abstract class BaseTransport implements Transport {
144144
try {
145145
sendReport(url, serializeEnvelope(envelope));
146146
} catch (e) {
147-
logger.error(e);
147+
isDebugBuild() && logger.error(e);
148148
}
149149
}
150150

@@ -170,8 +170,9 @@ export abstract class BaseTransport implements Transport {
170170
* https://developer.mozilla.org/en-US/docs/Web/API/Headers/get
171171
*/
172172
const limited = this._handleRateLimit(headers);
173-
if (limited && isDebugBuild()) {
174-
logger.warn(`Too many ${requestType} requests, backing off until: ${this._disabledUntil(requestType)}`);
173+
if (limited) {
174+
isDebugBuild() &&
175+
logger.warn(`Too many ${requestType} requests, backing off until: ${this._disabledUntil(requestType)}`);
175176
}
176177

177178
if (status === 'success') {

packages/core/src/basebackend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export abstract class BaseBackend<O extends Options> implements Backend {
6767
public constructor(options: O) {
6868
this._options = options;
6969
if (!this._options.dsn) {
70-
logger.warn('No DSN provided, backend will not do anything.');
70+
isDebugBuild() && logger.warn('No DSN provided, backend will not do anything.');
7171
}
7272
this._transport = this._setupTransport();
7373
}

packages/core/src/baseclient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
108108
public captureException(exception: any, hint?: EventHint, scope?: Scope): string | undefined {
109109
// ensure we haven't captured this very object before
110110
if (checkOrSetAlreadyCaught(exception)) {
111-
logger.log(ALREADY_SEEN_ERROR);
111+
isDebugBuild() && logger.log(ALREADY_SEEN_ERROR);
112112
return;
113113
}
114114

@@ -153,7 +153,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
153153
public captureEvent(event: Event, hint?: EventHint, scope?: Scope): string | undefined {
154154
// ensure we haven't captured this very object before
155155
if (hint && hint.originalException && checkOrSetAlreadyCaught(hint.originalException)) {
156-
logger.log(ALREADY_SEEN_ERROR);
156+
isDebugBuild() && logger.log(ALREADY_SEEN_ERROR);
157157
return;
158158
}
159159

@@ -244,7 +244,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
244244
try {
245245
return (this._integrations[integration.id] as T) || null;
246246
} catch (_oO) {
247-
logger.warn(`Cannot retrieve integration ${integration.id} from the current Client`);
247+
isDebugBuild() && logger.warn(`Cannot retrieve integration ${integration.id} from the current Client`);
248248
return null;
249249
}
250250
}
@@ -503,7 +503,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
503503
return finalEvent.event_id;
504504
},
505505
reason => {
506-
logger.error(reason);
506+
isDebugBuild() && logger.error(reason);
507507
return undefined;
508508
},
509509
);

packages/core/src/integration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/hub';
22
import { Integration, Options } from '@sentry/types';
3-
import { addNonEnumerableProperty, logger } from '@sentry/utils';
3+
import { addNonEnumerableProperty, isDebugBuild, logger } from '@sentry/utils';
44

55
export const installedIntegrations: string[] = [];
66

@@ -59,7 +59,7 @@ export function setupIntegration(integration: Integration): void {
5959
}
6060
integration.setupOnce(addGlobalEventProcessor, getCurrentHub);
6161
installedIntegrations.push(integration.name);
62-
logger.log(`Integration installed: ${integration.name}`);
62+
isDebugBuild() && logger.log(`Integration installed: ${integration.name}`);
6363
}
6464

6565
/**

packages/hub/src/hub.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ import {
2020
TransactionContext,
2121
User,
2222
} from '@sentry/types';
23-
import { consoleSandbox, dateTimestampInSeconds, getGlobalObject, isNodeEnv, logger, uuid4 } from '@sentry/utils';
23+
import {
24+
consoleSandbox,
25+
dateTimestampInSeconds,
26+
getGlobalObject,
27+
isDebugBuild,
28+
isNodeEnv,
29+
logger,
30+
uuid4,
31+
} from '@sentry/utils';
2432

2533
import { Scope } from './scope';
2634
import { Session } from './session';
@@ -371,7 +379,7 @@ export class Hub implements HubInterface {
371379
try {
372380
return client.getIntegration(integration);
373381
} catch (_oO) {
374-
logger.warn(`Cannot retrieve integration ${integration.id} from the current Hub`);
382+
isDebugBuild() && logger.warn(`Cannot retrieve integration ${integration.id} from the current Hub`);
375383
return null;
376384
}
377385
}
@@ -503,7 +511,7 @@ export class Hub implements HubInterface {
503511
if (sentry && sentry.extensions && typeof sentry.extensions[method] === 'function') {
504512
return sentry.extensions[method].apply(this, args);
505513
}
506-
logger.warn(`Extension method ${method} couldn't be found, doing nothing.`);
514+
isDebugBuild() && logger.warn(`Extension method ${method} couldn't be found, doing nothing.`);
507515
}
508516
}
509517

@@ -566,7 +574,7 @@ export function getCurrentHub(): Hub {
566574
*/
567575
// eslint-disable-next-line deprecation/deprecation
568576
export function getActiveDomain(): DomainAsCarrier | undefined {
569-
logger.warn('Function `getActiveDomain` is deprecated and will be removed in a future version.');
577+
isDebugBuild() && logger.warn('Function `getActiveDomain` is deprecated and will be removed in a future version.');
570578

571579
const sentry = getMainCarrier().__SENTRY__;
572580

packages/hub/src/sessionflusher.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
SessionFlusherLike,
66
Transport,
77
} from '@sentry/types';
8-
import { dropUndefinedKeys, logger } from '@sentry/utils';
8+
import { dropUndefinedKeys, isDebugBuild, logger } from '@sentry/utils';
99

1010
import { getCurrentHub } from './hub';
1111

@@ -35,11 +35,11 @@ export class SessionFlusher implements SessionFlusherLike {
3535
/** Sends session aggregates to Transport */
3636
public sendSessionAggregates(sessionAggregates: SessionAggregates): void {
3737
if (!this._transport.sendSession) {
38-
logger.warn("Dropping session because custom transport doesn't implement sendSession");
38+
isDebugBuild() && logger.warn("Dropping session because custom transport doesn't implement sendSession");
3939
return;
4040
}
4141
void this._transport.sendSession(sessionAggregates).then(null, reason => {
42-
logger.error('Error while sending session:', reason);
42+
isDebugBuild() && logger.error('Error while sending session:', reason);
4343
});
4444
}
4545

packages/integrations/src/angular.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Event, EventProcessor, Hub, Integration } from '@sentry/types';
2-
import { getGlobalObject, logger } from '@sentry/utils';
2+
import { getGlobalObject, isDebugBuild, logger } from '@sentry/utils';
33

44
// See https://github.com/angular/angular.js/blob/v1.4.7/src/minErr.js
55
const angularPattern = /^\[((?:[$a-zA-Z0-9]+:)?(?:[$a-zA-Z0-9]+))\] (.*?)\n?(\S+)$/;
@@ -47,13 +47,13 @@ export class Angular implements Integration {
4747
*/
4848
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4949
public constructor(options: { angular?: any } = {}) {
50-
logger.log('You are still using the Angular integration, consider moving to @sentry/angular');
50+
isDebugBuild() && logger.log('You are still using the Angular integration, consider moving to @sentry/angular');
5151

5252
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
5353
this._angular = options.angular || getGlobalObject<any>().angular;
5454

5555
if (!this._angular) {
56-
logger.error('AngularIntegration is missing an Angular instance');
56+
isDebugBuild() && logger.error('AngularIntegration is missing an Angular instance');
5757
return;
5858
}
5959

packages/integrations/src/dedupe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Event, EventProcessor, Exception, Hub, Integration, StackFrame } from '@sentry/types';
2-
import { logger } from '@sentry/utils';
2+
import { isDebugBuild, logger } from '@sentry/utils';
33

44
/** Deduplication filter */
55
export class Dedupe implements Integration {
@@ -28,7 +28,7 @@ export class Dedupe implements Integration {
2828
// Juuust in case something goes wrong
2929
try {
3030
if (_shouldDropEvent(currentEvent, self._previousEvent)) {
31-
logger.warn('Event dropped due to being a duplicate of previously captured event.');
31+
isDebugBuild() && logger.warn('Event dropped due to being a duplicate of previously captured event.');
3232
return null;
3333
}
3434
} catch (_oO) {

packages/integrations/src/ember.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EventProcessor, Hub, Integration } from '@sentry/types';
2-
import { getGlobalObject, isInstanceOf, logger } from '@sentry/utils';
2+
import { getGlobalObject, isDebugBuild, isInstanceOf, logger } from '@sentry/utils';
33

44
/** JSDoc */
55
export class Ember implements Integration {
@@ -33,7 +33,7 @@ export class Ember implements Integration {
3333
*/
3434
public setupOnce(_: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
3535
if (!this._Ember) {
36-
logger.error('EmberIntegration is missing an Ember instance');
36+
isDebugBuild() && logger.error('EmberIntegration is missing an Ember instance');
3737
return;
3838
}
3939

packages/integrations/src/extraerrordata.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Event, EventHint, EventProcessor, ExtendedError, Hub, Integration } from '@sentry/types';
2-
import { isError, isPlainObject, logger, normalize } from '@sentry/utils';
2+
import { isDebugBuild, isError, isPlainObject, logger, normalize } from '@sentry/utils';
33

44
/** JSDoc */
55
interface ExtraErrorDataOptions {
@@ -120,7 +120,7 @@ export class ExtraErrorData implements Integration {
120120

121121
return extraErrorInfo;
122122
} catch (oO) {
123-
logger.error('Unable to extract extra data from the Error object:', oO);
123+
isDebugBuild() && logger.error('Unable to extract extra data from the Error object:', oO);
124124
}
125125

126126
return null;

packages/integrations/src/offline.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
33
import { Event, EventProcessor, Hub, Integration } from '@sentry/types';
4-
import { getGlobalObject, logger, normalize, uuid4 } from '@sentry/utils';
4+
import { getGlobalObject, isDebugBuild, logger, normalize, uuid4 } from '@sentry/utils';
55
import localForage from 'localforage';
66

77
type LocalForage = {
@@ -70,7 +70,7 @@ export class Offline implements Integration {
7070
if ('addEventListener' in this.global) {
7171
this.global.addEventListener('online', () => {
7272
void this._sendEvents().catch(() => {
73-
logger.warn('could not send cached events');
73+
isDebugBuild() && logger.warn('could not send cached events');
7474
});
7575
});
7676
}
@@ -82,7 +82,7 @@ export class Offline implements Integration {
8282
void this._cacheEvent(event)
8383
.then((_event: Event): Promise<void> => this._enforceMaxEvents())
8484
.catch((_error): void => {
85-
logger.warn('could not cache event while offline');
85+
isDebugBuild() && logger.warn('could not cache event while offline');
8686
});
8787

8888
// return null on success or failure, because being offline will still result in an error
@@ -96,7 +96,7 @@ export class Offline implements Integration {
9696
// if online now, send any events stored in a previous offline session
9797
if ('navigator' in this.global && 'onLine' in this.global.navigator && this.global.navigator.onLine) {
9898
void this._sendEvents().catch(() => {
99-
logger.warn('could not send cached events');
99+
isDebugBuild() && logger.warn('could not send cached events');
100100
});
101101
}
102102
}
@@ -132,7 +132,7 @@ export class Offline implements Integration {
132132
),
133133
)
134134
.catch((_error): void => {
135-
logger.warn('could not enforce max events');
135+
isDebugBuild() && logger.warn('could not enforce max events');
136136
});
137137
}
138138

@@ -160,10 +160,10 @@ export class Offline implements Integration {
160160
this.hub.captureEvent(event);
161161

162162
void this._purgeEvent(cacheKey).catch((_error): void => {
163-
logger.warn('could not purge event from cache');
163+
isDebugBuild() && logger.warn('could not purge event from cache');
164164
});
165165
} else {
166-
logger.warn('no hub found - could not send cached event');
166+
isDebugBuild() && logger.warn('no hub found - could not send cached event');
167167
}
168168
});
169169
}

0 commit comments

Comments
 (0)