From 728617fed2fee99b2accdcf6d2ddc9036c9ad266 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Tue, 20 Nov 2018 12:06:10 -0800 Subject: feat(instant): Report errors to rollbar --- packages/instant/src/util/error_reporter.ts | 68 +++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 packages/instant/src/util/error_reporter.ts (limited to 'packages/instant/src/util/error_reporter.ts') diff --git a/packages/instant/src/util/error_reporter.ts b/packages/instant/src/util/error_reporter.ts new file mode 100644 index 000000000..81a90e7f5 --- /dev/null +++ b/packages/instant/src/util/error_reporter.ts @@ -0,0 +1,68 @@ +import { logUtils } from '@0x/utils'; + +import { ROLLBAR_CLIENT_TOKEN, ROLLBAR_ENVIRONMENT } from '../constants'; + +// Import version of Rollbar designed for embedded components +// See https://docs.rollbar.com/docs/using-rollbarjs-inside-an-embedded-component +// tslint:disable-next-line:no-var-requires +const Rollbar = require('rollbar/dist/rollbar.noconflict.umd'); + +const shouldAllowRollbar = () => { + if (ROLLBAR_ENVIRONMENT === 'development') { + return process.env.ROLLBAR_FORCE_DEVELOPMENT_REPORT ? true : false; + } + return true; +}; + +let rollbar: any; +if (ROLLBAR_CLIENT_TOKEN && ROLLBAR_ENVIRONMENT && shouldAllowRollbar()) { + rollbar = new Rollbar({ + accessToken: ROLLBAR_CLIENT_TOKEN, + captureUncaught: true, + captureUnhandledRejections: true, + enabled: true, + itemsPerMinute: 10, + maxItems: 500, + payload: { + environment: ROLLBAR_ENVIRONMENT, + client: { + javascript: { + source_map_enabled: true, + code_version: process.env.GIT_SHA, + guess_uncaught_frames: true, + }, + }, + }, + uncaughtErrorLevel: 'error', + ignoredMessages: [ + // Errors from the third-party scripts + 'Script error', + // Network errors or ad-blockers + 'TypeError: Failed to fetch', + 'Exchange has not been deployed to detected network (network/artifact mismatch)', + // Source: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-discuss/7VU0_VvC7mE + "undefined is not an object (evaluating '__gCrWeb.autofill.extractForms')", + // Source: http://stackoverflow.com/questions/43399818/securityerror-from-facebook-and-cross-domain-messaging + 'SecurityError (DOM Exception 18)', + ], + }); +} + +export const setupRollbar = (): any => { + return rollbar as any; +}; + +export const errorReporter = { + report(err: Error): void { + if (!rollbar) { + logUtils.log('Not reporting to rollbar because not configured', err); + return; + } + + rollbar.error(err, (rollbarErr: Error) => { + if (rollbarErr) { + logUtils.log(`Error reporting to rollbar, ignoring: ${rollbarErr}`); + } + }); + }, +}; -- cgit v1.2.3 From 094aabfcee8828eb5c5ba452edda306ef04757ce Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Tue, 20 Nov 2018 13:28:28 -0800 Subject: Linting --- packages/instant/src/util/error_reporter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/instant/src/util/error_reporter.ts') diff --git a/packages/instant/src/util/error_reporter.ts b/packages/instant/src/util/error_reporter.ts index 81a90e7f5..a03b5e65e 100644 --- a/packages/instant/src/util/error_reporter.ts +++ b/packages/instant/src/util/error_reporter.ts @@ -49,7 +49,7 @@ if (ROLLBAR_CLIENT_TOKEN && ROLLBAR_ENVIRONMENT && shouldAllowRollbar()) { } export const setupRollbar = (): any => { - return rollbar as any; + return rollbar; }; export const errorReporter = { -- cgit v1.2.3 From 22a31246622e7139185d080cae9bef275087e245 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 21 Nov 2018 09:35:24 -0800 Subject: Move rollbar setup into function, move setting up into provider --- packages/instant/src/util/error_reporter.ts | 66 ++++++++++++++--------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'packages/instant/src/util/error_reporter.ts') diff --git a/packages/instant/src/util/error_reporter.ts b/packages/instant/src/util/error_reporter.ts index a03b5e65e..c5766b469 100644 --- a/packages/instant/src/util/error_reporter.ts +++ b/packages/instant/src/util/error_reporter.ts @@ -1,4 +1,5 @@ import { logUtils } from '@0x/utils'; +import * as _ from 'lodash'; import { ROLLBAR_CLIENT_TOKEN, ROLLBAR_ENVIRONMENT } from '../constants'; @@ -15,41 +16,40 @@ const shouldAllowRollbar = () => { }; let rollbar: any; -if (ROLLBAR_CLIENT_TOKEN && ROLLBAR_ENVIRONMENT && shouldAllowRollbar()) { - rollbar = new Rollbar({ - accessToken: ROLLBAR_CLIENT_TOKEN, - captureUncaught: true, - captureUnhandledRejections: true, - enabled: true, - itemsPerMinute: 10, - maxItems: 500, - payload: { - environment: ROLLBAR_ENVIRONMENT, - client: { - javascript: { - source_map_enabled: true, - code_version: process.env.GIT_SHA, - guess_uncaught_frames: true, +// Configures rollbar and sets up error catching +export const setupRollbar = (): any => { + if (_.isUndefined(rollbar) && ROLLBAR_CLIENT_TOKEN && ROLLBAR_ENVIRONMENT && shouldAllowRollbar()) { + rollbar = new Rollbar({ + accessToken: ROLLBAR_CLIENT_TOKEN, + captureUncaught: true, + captureUnhandledRejections: true, + enabled: true, + itemsPerMinute: 10, + maxItems: 500, + payload: { + environment: ROLLBAR_ENVIRONMENT, + client: { + javascript: { + source_map_enabled: true, + code_version: process.env.GIT_SHA, + guess_uncaught_frames: true, + }, }, }, - }, - uncaughtErrorLevel: 'error', - ignoredMessages: [ - // Errors from the third-party scripts - 'Script error', - // Network errors or ad-blockers - 'TypeError: Failed to fetch', - 'Exchange has not been deployed to detected network (network/artifact mismatch)', - // Source: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-discuss/7VU0_VvC7mE - "undefined is not an object (evaluating '__gCrWeb.autofill.extractForms')", - // Source: http://stackoverflow.com/questions/43399818/securityerror-from-facebook-and-cross-domain-messaging - 'SecurityError (DOM Exception 18)', - ], - }); -} - -export const setupRollbar = (): any => { - return rollbar; + uncaughtErrorLevel: 'error', + ignoredMessages: [ + // Errors from the third-party scripts + 'Script error', + // Network errors or ad-blockers + 'TypeError: Failed to fetch', + 'Exchange has not been deployed to detected network (network/artifact mismatch)', + // Source: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-discuss/7VU0_VvC7mE + "undefined is not an object (evaluating '__gCrWeb.autofill.extractForms')", + // Source: http://stackoverflow.com/questions/43399818/securityerror-from-facebook-and-cross-domain-messaging + 'SecurityError (DOM Exception 18)', + ], + }); + } }; export const errorReporter = { -- cgit v1.2.3 From e2a16f3f336c6787501c6a2366e7793a135009f8 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 21 Nov 2018 10:25:10 -0800 Subject: Use ROLLBAR_ENABLED constant, and change ROLLBAR_ENVIRONMENT to INSTANT_ENVIRONMENT --- packages/instant/src/util/error_reporter.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'packages/instant/src/util/error_reporter.ts') diff --git a/packages/instant/src/util/error_reporter.ts b/packages/instant/src/util/error_reporter.ts index c5766b469..89c5b6bd3 100644 --- a/packages/instant/src/util/error_reporter.ts +++ b/packages/instant/src/util/error_reporter.ts @@ -1,24 +1,17 @@ import { logUtils } from '@0x/utils'; import * as _ from 'lodash'; -import { ROLLBAR_CLIENT_TOKEN, ROLLBAR_ENVIRONMENT } from '../constants'; +import { INSTANT_ENVIRONMENT, ROLLBAR_CLIENT_TOKEN, ROLLBAR_ENABLED } from '../constants'; // Import version of Rollbar designed for embedded components // See https://docs.rollbar.com/docs/using-rollbarjs-inside-an-embedded-component // tslint:disable-next-line:no-var-requires const Rollbar = require('rollbar/dist/rollbar.noconflict.umd'); -const shouldAllowRollbar = () => { - if (ROLLBAR_ENVIRONMENT === 'development') { - return process.env.ROLLBAR_FORCE_DEVELOPMENT_REPORT ? true : false; - } - return true; -}; - let rollbar: any; // Configures rollbar and sets up error catching export const setupRollbar = (): any => { - if (_.isUndefined(rollbar) && ROLLBAR_CLIENT_TOKEN && ROLLBAR_ENVIRONMENT && shouldAllowRollbar()) { + if (_.isUndefined(rollbar) && ROLLBAR_CLIENT_TOKEN && INSTANT_ENVIRONMENT && ROLLBAR_ENABLED) { rollbar = new Rollbar({ accessToken: ROLLBAR_CLIENT_TOKEN, captureUncaught: true, @@ -27,7 +20,7 @@ export const setupRollbar = (): any => { itemsPerMinute: 10, maxItems: 500, payload: { - environment: ROLLBAR_ENVIRONMENT, + environment: INSTANT_ENVIRONMENT, client: { javascript: { source_map_enabled: true, -- cgit v1.2.3 From c6ae7b8d3f720f637db2d5ec9abee14cc00fb7a7 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 21 Nov 2018 13:19:26 -0800 Subject: Host whitelist so we don't get errors from embedded site --- packages/instant/src/util/error_reporter.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages/instant/src/util/error_reporter.ts') diff --git a/packages/instant/src/util/error_reporter.ts b/packages/instant/src/util/error_reporter.ts index 89c5b6bd3..c0ef3e30e 100644 --- a/packages/instant/src/util/error_reporter.ts +++ b/packages/instant/src/util/error_reporter.ts @@ -1,7 +1,7 @@ import { logUtils } from '@0x/utils'; import * as _ from 'lodash'; -import { INSTANT_ENVIRONMENT, ROLLBAR_CLIENT_TOKEN, ROLLBAR_ENABLED } from '../constants'; +import { EMBEDDED_DOMAINS, INSTANT_ENVIRONMENT, ROLLBAR_CLIENT_TOKEN, ROLLBAR_ENABLED } from '../constants'; // Import version of Rollbar designed for embedded components // See https://docs.rollbar.com/docs/using-rollbarjs-inside-an-embedded-component @@ -29,6 +29,7 @@ export const setupRollbar = (): any => { }, }, }, + hostWhiteList: EMBEDDED_DOMAINS, uncaughtErrorLevel: 'error', ignoredMessages: [ // Errors from the third-party scripts -- cgit v1.2.3 From 717a3bce8cd0d4cb782918b3ad806f6c1bdb825e Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 26 Nov 2018 09:12:51 -0800 Subject: EMBEDDED_DOMAINS -> HOST_DOMAINS --- packages/instant/src/util/error_reporter.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/instant/src/util/error_reporter.ts') diff --git a/packages/instant/src/util/error_reporter.ts b/packages/instant/src/util/error_reporter.ts index c0ef3e30e..8e21c8881 100644 --- a/packages/instant/src/util/error_reporter.ts +++ b/packages/instant/src/util/error_reporter.ts @@ -1,7 +1,7 @@ import { logUtils } from '@0x/utils'; import * as _ from 'lodash'; -import { EMBEDDED_DOMAINS, INSTANT_ENVIRONMENT, ROLLBAR_CLIENT_TOKEN, ROLLBAR_ENABLED } from '../constants'; +import { HOST_DOMAINS, INSTANT_ENVIRONMENT, ROLLBAR_CLIENT_TOKEN, ROLLBAR_ENABLED } from '../constants'; // Import version of Rollbar designed for embedded components // See https://docs.rollbar.com/docs/using-rollbarjs-inside-an-embedded-component @@ -29,7 +29,7 @@ export const setupRollbar = (): any => { }, }, }, - hostWhiteList: EMBEDDED_DOMAINS, + hostWhiteList: HOST_DOMAINS, uncaughtErrorLevel: 'error', ignoredMessages: [ // Errors from the third-party scripts -- cgit v1.2.3 From a138ee7e836a2ddb7a2ae317fe56dddaca5703ff Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Tue, 4 Dec 2018 16:10:56 -0800 Subject: Add GIT_SHA and NPM_VERSION constants, report git and npm version in error --- packages/instant/src/util/error_reporter.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/instant/src/util/error_reporter.ts') diff --git a/packages/instant/src/util/error_reporter.ts b/packages/instant/src/util/error_reporter.ts index 3ec7b6daa..b1824eaf9 100644 --- a/packages/instant/src/util/error_reporter.ts +++ b/packages/instant/src/util/error_reporter.ts @@ -1,7 +1,7 @@ import { logUtils } from '@0x/utils'; import * as _ from 'lodash'; -import { HOST_DOMAINS, INSTANT_DISCHARGE_TARGET, ROLLBAR_CLIENT_TOKEN, ROLLBAR_ENABLED } from '../constants'; +import { GIT_SHA, HOST_DOMAINS, INSTANT_DISCHARGE_TARGET, ROLLBAR_CLIENT_TOKEN, ROLLBAR_ENABLED } from '../constants'; // Import version of Rollbar designed for embedded components // See https://docs.rollbar.com/docs/using-rollbarjs-inside-an-embedded-component @@ -24,7 +24,7 @@ export const setupRollbar = (): any => { client: { javascript: { source_map_enabled: true, - code_version: process.env.GIT_SHA, + code_version: GIT_SHA, guess_uncaught_frames: true, }, }, -- cgit v1.2.3 From 9eff85741617d9d64c674e41a344e42325153292 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 5 Dec 2018 09:45:34 -0800 Subject: Only include localhost in host domains if in development mode --- packages/instant/src/util/error_reporter.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'packages/instant/src/util/error_reporter.ts') diff --git a/packages/instant/src/util/error_reporter.ts b/packages/instant/src/util/error_reporter.ts index b1824eaf9..ec074c440 100644 --- a/packages/instant/src/util/error_reporter.ts +++ b/packages/instant/src/util/error_reporter.ts @@ -1,17 +1,35 @@ import { logUtils } from '@0x/utils'; import * as _ from 'lodash'; -import { GIT_SHA, HOST_DOMAINS, INSTANT_DISCHARGE_TARGET, ROLLBAR_CLIENT_TOKEN, ROLLBAR_ENABLED } from '../constants'; +import { + GIT_SHA, + HOST_DOMAINS_EXTERNAL, + HOST_DOMAINS_LOCAL, + INSTANT_DISCHARGE_TARGET, + NODE_ENV, + ROLLBAR_CLIENT_TOKEN, + ROLLBAR_ENABLED, +} from '../constants'; // Import version of Rollbar designed for embedded components // See https://docs.rollbar.com/docs/using-rollbarjs-inside-an-embedded-component // tslint:disable-next-line:no-var-requires const Rollbar = require('rollbar/dist/rollbar.noconflict.umd'); +const getRollbarHostDomains = (): string[] => { + if (NODE_ENV === 'development') { + return HOST_DOMAINS_EXTERNAL.concat(HOST_DOMAINS_LOCAL); + } else { + return HOST_DOMAINS_EXTERNAL; + } +}; + let rollbar: any; // Configures rollbar and sets up error catching export const setupRollbar = (): any => { if (_.isUndefined(rollbar) && ROLLBAR_CLIENT_TOKEN && ROLLBAR_ENABLED) { + const hostDomains = getRollbarHostDomains(); + console.log('hostDomains', hostDomains); rollbar = new Rollbar({ accessToken: ROLLBAR_CLIENT_TOKEN, captureUncaught: true, @@ -20,7 +38,7 @@ export const setupRollbar = (): any => { itemsPerMinute: 10, maxItems: 500, payload: { - environment: INSTANT_DISCHARGE_TARGET || `Local ${process.env.NODE_ENV}`, + environment: INSTANT_DISCHARGE_TARGET || `Local ${NODE_ENV}`, client: { javascript: { source_map_enabled: true, @@ -29,7 +47,7 @@ export const setupRollbar = (): any => { }, }, }, - hostWhiteList: HOST_DOMAINS, + hostWhiteList: hostDomains, uncaughtErrorLevel: 'error', ignoredMessages: [ // Errors from the third-party scripts -- cgit v1.2.3 From 69d4e330cf312af99cf547add9cd2106e492c563 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 5 Dec 2018 10:17:18 -0800 Subject: Takeout console.log --- packages/instant/src/util/error_reporter.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages/instant/src/util/error_reporter.ts') diff --git a/packages/instant/src/util/error_reporter.ts b/packages/instant/src/util/error_reporter.ts index ec074c440..8d7481684 100644 --- a/packages/instant/src/util/error_reporter.ts +++ b/packages/instant/src/util/error_reporter.ts @@ -29,7 +29,6 @@ let rollbar: any; export const setupRollbar = (): any => { if (_.isUndefined(rollbar) && ROLLBAR_CLIENT_TOKEN && ROLLBAR_ENABLED) { const hostDomains = getRollbarHostDomains(); - console.log('hostDomains', hostDomains); rollbar = new Rollbar({ accessToken: ROLLBAR_CLIENT_TOKEN, captureUncaught: true, -- cgit v1.2.3