Skip to content
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

Log every console.error log into sentry.io #926

Merged
merged 2 commits into from
Feb 12, 2020
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: 1 addition & 3 deletions libraries/common/actions/client/fetchClientInformation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
logger,
hasSGJavaScriptBridge,
defaultClientInformation,
getWebStorageEntry,
Expand All @@ -25,8 +24,7 @@ function fetchClientInformation() {

getWebStorageEntry({ name: 'clientInformation' })
.then(response => dispatch(receiveClientInformation(response.value)))
.catch((error) => {
logger.error(error);
.catch(() => {
dispatch(errorClientInformation());
});
};
Expand Down
9 changes: 8 additions & 1 deletion libraries/common/subscriptions/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
ENETUNREACH,
EUNKNOWN,
} from '@shopgate/pwa-core';
import { SOURCE_TRACKING, Severity } from '@shopgate/pwa-core/constants/ErrorManager';
import { SOURCE_TRACKING, SOURCE_CONSOLE, Severity } from '@shopgate/pwa-core/constants/ErrorManager';
import {
// eslint-disable-next-line import/no-named-default
default as appConfig,
Expand Down Expand Up @@ -182,6 +182,13 @@ export default (subscribe) => {
captureException(error);
});
});
emitter.addListener(SOURCE_CONSOLE, (args) => {
withScope((scope) => {
scope.setLevel(SentrySeverity.Error);
scope.setExtra('error', args);
captureMessage('Console error');
});
});
});

subscribe(userDidUpdate$, ({ getState }) => {
Expand Down
1 change: 1 addition & 0 deletions libraries/core/constants/ErrorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const DEFAULT_CONTEXT = '*';
export const SOURCE_APP = 'app';
export const SOURCE_PIPELINE = 'pipeline';
export const SOURCE_TRACKING = 'tracking';
export const SOURCE_CONSOLE = 'console';

export const CODE_TRACKING = 'ETRACKING';

Expand Down
8 changes: 7 additions & 1 deletion libraries/core/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { emitter } from '../classes/ErrorManager';
import { SOURCE_CONSOLE } from '../constants/ErrorManager';

const csl = console;

/**
Expand All @@ -22,7 +25,10 @@ export const logger = {
debug: (...args) => csl.debug(...convertLogArgs(args)),
dir: (...args) => csl.dir(...convertLogArgs(args)),
dirxml: (...args) => csl.dirxml(...convertLogArgs(args)),
error: (...args) => csl.error(...convertLogArgs(args)),
error: (...args) => {
emitter.emit(SOURCE_CONSOLE, args);
csl.error(...convertLogArgs(args));
},
info: (...args) => csl.info(...convertLogArgs(args)),
log: (...args) => csl.log(...convertLogArgs(args)),
warn: (...args) => csl.warn(...convertLogArgs(args)),
Expand Down