Skip to content
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
9 changes: 7 additions & 2 deletions packages/browser/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
addNonEnumerableProperty,
getGlobalObject,
getOriginalFunction,
isDebugBuild,
logger,
markFunctionWrapped,
} from '@sentry/utils';
Expand Down Expand Up @@ -191,12 +192,16 @@ export function injectReportDialog(options: ReportDialogOptions = {}): void {
}

if (!options.eventId) {
logger.error(`Missing eventId option in showReportDialog call`);
if (isDebugBuild()) {
logger.error(`Missing eventId option in showReportDialog call`);
}
return;
}

if (!options.dsn) {
logger.error(`Missing dsn option in showReportDialog call`);
if (isDebugBuild()) {
logger.error(`Missing dsn option in showReportDialog call`);
}
return;
}

Expand Down
5 changes: 4 additions & 1 deletion packages/browser/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
addExceptionMechanism,
addInstrumentationHandler,
getLocationHref,
isDebugBuild,
isErrorEvent,
isPrimitive,
isString,
Expand Down Expand Up @@ -239,7 +240,9 @@ function _enhanceEventWithInitialFrame(event: Event, url: any, line: any, column
}

function globalHandlerLog(type: string): void {
logger.log(`Global Handler attached: ${type}`);
if (isDebugBuild()) {
logger.log(`Global Handler attached: ${type}`);
}
}

function addMechanismAndCapture(hub: Hub, error: EventHint['originalException'], event: Event, type: string): void {
Expand Down
31 changes: 20 additions & 11 deletions packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getCurrentHub, initAndBind, Integrations as CoreIntegrations } from '@sentry/core';
import { addInstrumentationHandler, getGlobalObject, logger, resolvedSyncPromise } from '@sentry/utils';
import { Hub } from '@sentry/types';
import { addInstrumentationHandler, getGlobalObject, isDebugBuild, logger, resolvedSyncPromise } from '@sentry/utils';

import { BrowserOptions } from './backend';
import { BrowserClient } from './client';
Expand Down Expand Up @@ -161,7 +162,9 @@ export function flush(timeout?: number): PromiseLike<boolean> {
if (client) {
return client.flush(timeout);
}
logger.warn('Cannot flush events. No client defined.');
if (isDebugBuild()) {
logger.warn('Cannot flush events. No client defined.');
}
return resolvedSyncPromise(false);
}

Expand All @@ -178,7 +181,9 @@ export function close(timeout?: number): PromiseLike<boolean> {
if (client) {
return client.close(timeout);
}
logger.warn('Cannot flush events and disable SDK. No client defined.');
if (isDebugBuild()) {
logger.warn('Cannot flush events and disable SDK. No client defined.');
}
return resolvedSyncPromise(false);
}

Expand All @@ -194,6 +199,11 @@ export function wrap(fn: (...args: any) => any): any {
return internalWrap(fn)();
}

function startSessionOnHub(hub: Hub): void {
hub.startSession({ ignoreDuration: true });
hub.captureSession();
}

/**
* Enable automatic Session Tracking for the initial page load.
*/
Expand All @@ -202,7 +212,9 @@ function startSessionTracking(): void {
const document = window.document;

if (typeof document === 'undefined') {
logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
if (isDebugBuild()) {
logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
}
return;
}

Expand All @@ -214,24 +226,21 @@ function startSessionTracking(): void {
// https://github.com/getsentry/sentry-javascript/issues/3207 and
// https://github.com/getsentry/sentry-javascript/issues/3234 and
// https://github.com/getsentry/sentry-javascript/issues/3278.
if (typeof hub.startSession !== 'function' || typeof hub.captureSession !== 'function') {
if (!hub.captureSession) {
return;
}

// The session duration for browser sessions does not track a meaningful
// concept that can be used as a metric.
// Automatically captured sessions are akin to page views, and thus we
// discard their duration.
hub.startSession({ ignoreDuration: true });
hub.captureSession();
startSessionOnHub(hub);

// We want to create a session for every navigation as well
addInstrumentationHandler('history', ({ from, to }) => {
// Don't create an additional session for the initial route or if the location did not change
if (from === undefined || from === to) {
return;
if (!(from === undefined || from === to)) {
startSessionOnHub(getCurrentHub());
}
hub.startSession({ ignoreDuration: true });
hub.captureSession();
});
}
4 changes: 3 additions & 1 deletion packages/browser/src/transports/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
dsnToString,
eventStatusFromHttpCode,
getGlobalObject,
isDebugBuild,
logger,
makePromiseBuffer,
parseRetryAfterHeader,
Expand Down Expand Up @@ -173,8 +174,9 @@ export abstract class BaseTransport implements Transport {
* https://developer.mozilla.org/en-US/docs/Web/API/Headers/get
*/
const limited = this._handleRateLimit(headers);
if (limited)
if (limited && isDebugBuild()) {
logger.warn(`Too many ${requestType} requests, backing off until: ${this._disabledUntil(requestType)}`);
}

if (status === 'success') {
resolve({ status });
Expand Down
6 changes: 4 additions & 2 deletions packages/browser/src/transports/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { forget, getGlobalObject, isNativeFetch, logger, supportsFetch } from '@sentry/utils';
import { forget, getGlobalObject, isDebugBuild, isNativeFetch, logger, supportsFetch } from '@sentry/utils';

const global = getGlobalObject<Window>();
let cachedFetchImpl: FetchImpl;
Expand Down Expand Up @@ -69,7 +69,9 @@ export function getNativeFetchImplementation(): FetchImpl {
}
document.head.removeChild(sandbox);
} catch (e) {
logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
if (isDebugBuild()) {
logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
}
}
}

Expand Down
14 changes: 10 additions & 4 deletions packages/core/src/basebackend.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Event, EventHint, Options, Session, SeverityLevel, Transport } from '@sentry/types';
import { logger, SentryError } from '@sentry/utils';
import { isDebugBuild, logger, SentryError } from '@sentry/utils';

import { NoopTransport } from './transports/noop';

Expand Down Expand Up @@ -92,7 +92,9 @@ export abstract class BaseBackend<O extends Options> implements Backend {
*/
public sendEvent(event: Event): void {
void this._transport.sendEvent(event).then(null, reason => {
logger.error(`Error while sending event: ${reason}`);
if (isDebugBuild()) {
logger.error(`Error while sending event: ${reason}`);
}
});
}

Expand All @@ -101,12 +103,16 @@ export abstract class BaseBackend<O extends Options> implements Backend {
*/
public sendSession(session: Session): void {
if (!this._transport.sendSession) {
logger.warn("Dropping session because custom transport doesn't implement sendSession");
if (isDebugBuild()) {
logger.warn("Dropping session because custom transport doesn't implement sendSession");
}
return;
}

void this._transport.sendSession(session).then(null, reason => {
logger.error(`Error while sending session: ${reason}`);
if (isDebugBuild()) {
logger.error(`Error while sending session: ${reason}`);
}
});
}

Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import {
checkOrSetAlreadyCaught,
dateTimestampInSeconds,
isDebugBuild,
isPlainObject,
isPrimitive,
isThenable,
Expand Down Expand Up @@ -172,12 +173,16 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
*/
public captureSession(session: Session): void {
if (!this._isEnabled()) {
logger.warn('SDK not enabled, will not capture session.');
if (isDebugBuild()) {
logger.warn('SDK not enabled, will not capture session.');
}
return;
}

if (!(typeof session.release === 'string')) {
logger.warn('Discarded session because of missing or non-string release');
if (isDebugBuild()) {
logger.warn('Discarded session because of missing or non-string release');
}
} else {
this._sendSession(session);
// After sending, we set init false to indicate it's not the first occurrence
Expand Down
46 changes: 29 additions & 17 deletions packages/core/src/integrations/inboundfilters.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/hub';
import { Event, Integration, StackFrame } from '@sentry/types';
import { getEventDescription, isMatchingPattern, logger } from '@sentry/utils';
import { getEventDescription, isDebugBuild, isMatchingPattern, logger } from '@sentry/utils';

// "Script error." is hard coded into browsers for errors that it can't read.
// this is the result of a script being pulled in from an external domain and CORS.
Expand Down Expand Up @@ -64,29 +64,37 @@ export class InboundFilters implements Integration {
/** JSDoc */
private _shouldDropEvent(event: Event, options: Partial<InboundFiltersOptions>): boolean {
if (this._isSentryError(event, options)) {
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
if (isDebugBuild()) {
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
}
return true;
}
if (this._isIgnoredError(event, options)) {
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
if (isDebugBuild()) {
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
}
return true;
}
if (this._isDeniedUrl(event, options)) {
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${this._getEventFilterUrl(event)}`,
);
if (isDebugBuild()) {
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${this._getEventFilterUrl(event)}`,
);
}
return true;
}
if (!this._isAllowedUrl(event, options)) {
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${this._getEventFilterUrl(event)}`,
);
if (isDebugBuild()) {
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${this._getEventFilterUrl(event)}`,
);
}
return true;
}
return false;
Expand Down Expand Up @@ -179,7 +187,9 @@ export class InboundFilters implements Integration {
const { type = '', value = '' } = (event.exception.values && event.exception.values[0]) || {};
return [`${value}`, `${type}: ${value}`];
} catch (oO) {
logger.error(`Cannot extract message for event ${getEventDescription(event)}`);
if (isDebugBuild()) {
logger.error(`Cannot extract message for event ${getEventDescription(event)}`);
}
return [];
}
}
Expand Down Expand Up @@ -214,7 +224,9 @@ export class InboundFilters implements Integration {
}
return frames ? this._getLastValidUrl(frames) : null;
} catch (oO) {
logger.error(`Cannot extract url for event ${getEventDescription(event)}`);
if (isDebugBuild()) {
logger.error(`Cannot extract url for event ${getEventDescription(event)}`);
}
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,5 @@ export interface Hub {
* Sends the current session on the scope to Sentry
* @param endSession If set the session will be marked as exited and removed from the scope
*/
captureSession(endSession: boolean): void;
captureSession(endSession?: boolean): void;
}
13 changes: 8 additions & 5 deletions packages/utils/src/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/* eslint-disable @typescript-eslint/ban-types */
import { WrappedFunction } from '@sentry/types';

import { isDebugBuild } from '.';
import { getGlobalObject } from './global';
import { isInstanceOf, isString } from './is';
import { logger } from './logger';
Expand Down Expand Up @@ -93,11 +94,13 @@ function triggerHandlers(type: InstrumentHandlerType, data: any): void {
try {
handler(data);
} catch (e) {
logger.error(
`Error while triggering instrumentation handler.\nType: ${type}\nName: ${getFunctionName(
handler,
)}\nError: ${e}`,
);
if (isDebugBuild()) {
logger.error(
`Error while triggering instrumentation handler.\nType: ${type}\nName: ${getFunctionName(
handler,
)}\nError: ${e}`,
);
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion packages/utils/src/supports.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isDebugBuild } from './env';
import { getGlobalObject } from './global';
import { logger } from './logger';

Expand Down Expand Up @@ -112,7 +113,9 @@ export function supportsNativeFetch(): boolean {
}
doc.head.removeChild(sandbox);
} catch (err) {
logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', err);
if (isDebugBuild()) {
logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', err);
}
}
}

Expand Down