2017-04-04 09:58:45 -04:00
|
|
|
import Raven from 'raven-js';
|
2017-05-25 03:12:36 -04:00
|
|
|
import $ from 'jquery';
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-18 13:58:03 -04:00
|
|
|
const IGNORE_ERRORS = [
|
|
|
|
// Random plugins/extensions
|
|
|
|
'top.GLOBALS',
|
|
|
|
// See: http://blog.errorception.com/2012/03/tale-of-unfindable-js-error. html
|
|
|
|
'originalCreateNotification',
|
|
|
|
'canvas.contentDocument',
|
|
|
|
'MyApp_RemoveAllHighlights',
|
|
|
|
'http://tt.epicplay.com',
|
|
|
|
'Can\'t find variable: ZiteReader',
|
|
|
|
'jigsaw is not defined',
|
|
|
|
'ComboSearch is not defined',
|
|
|
|
'http://loading.retry.widdit.com/',
|
|
|
|
'atomicFindClose',
|
|
|
|
// Facebook borked
|
|
|
|
'fb_xd_fragment',
|
|
|
|
// ISP "optimizing" proxy - `Cache-Control: no-transform` seems to
|
|
|
|
// reduce this. (thanks @acdha)
|
|
|
|
// See http://stackoverflow.com/questions/4113268
|
|
|
|
'bmi_SafeAddOnload',
|
|
|
|
'EBCallBackMessageReceived',
|
|
|
|
// See http://toolbar.conduit.com/Developer/HtmlAndGadget/Methods/JSInjection.aspx
|
|
|
|
'conduitPage',
|
|
|
|
];
|
|
|
|
|
|
|
|
const IGNORE_URLS = [
|
|
|
|
// Facebook flakiness
|
|
|
|
/graph\.facebook\.com/i,
|
|
|
|
// Facebook blocked
|
|
|
|
/connect\.facebook\.net\/en_US\/all\.js/i,
|
|
|
|
// Woopra flakiness
|
|
|
|
/eatdifferent\.com\.woopra-ns\.com/i,
|
|
|
|
/static\.woopra\.com\/js\/woopra\.js/i,
|
|
|
|
// Chrome extensions
|
|
|
|
/extensions\//i,
|
|
|
|
/^chrome:\/\//i,
|
|
|
|
// Other plugins
|
|
|
|
/127\.0\.0\.1:4001\/isrunning/i, // Cacaoweb
|
|
|
|
/webappstoolbarba\.texthelp\.com\//i,
|
|
|
|
/metrics\.itunes\.apple\.com\.edgesuite\.net\//i,
|
|
|
|
];
|
|
|
|
|
|
|
|
const SAMPLE_RATE = 95;
|
|
|
|
|
2017-04-13 12:17:41 -04:00
|
|
|
const RavenConfig = {
|
2017-04-18 13:58:03 -04:00
|
|
|
IGNORE_ERRORS,
|
|
|
|
IGNORE_URLS,
|
|
|
|
SAMPLE_RATE,
|
2017-04-13 12:17:41 -04:00
|
|
|
init(options = {}) {
|
2017-04-04 09:58:45 -04:00
|
|
|
this.options = options;
|
|
|
|
|
|
|
|
this.configure();
|
|
|
|
this.bindRavenErrors();
|
|
|
|
if (this.options.currentUserId) this.setUser();
|
2017-04-13 12:17:41 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
configure() {
|
2017-04-04 09:58:45 -04:00
|
|
|
Raven.config(this.options.sentryDsn, {
|
2017-05-19 16:13:57 -04:00
|
|
|
release: this.options.release,
|
|
|
|
tags: this.options.tags,
|
2017-04-04 09:58:45 -04:00
|
|
|
whitelistUrls: this.options.whitelistUrls,
|
|
|
|
environment: this.options.isProduction ? 'production' : 'development',
|
2017-04-18 13:58:03 -04:00
|
|
|
ignoreErrors: this.IGNORE_ERRORS,
|
|
|
|
ignoreUrls: this.IGNORE_URLS,
|
2017-04-28 11:01:22 -04:00
|
|
|
shouldSendCallback: this.shouldSendSample.bind(this),
|
2017-04-04 09:58:45 -04:00
|
|
|
}).install();
|
2017-04-13 12:17:41 -04:00
|
|
|
},
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-13 12:17:41 -04:00
|
|
|
setUser() {
|
2017-04-04 09:58:45 -04:00
|
|
|
Raven.setUserContext({
|
|
|
|
id: this.options.currentUserId,
|
|
|
|
});
|
2017-04-13 12:17:41 -04:00
|
|
|
},
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-13 12:17:41 -04:00
|
|
|
bindRavenErrors() {
|
2017-05-25 03:12:36 -04:00
|
|
|
$(document).on('ajaxError.raven', this.handleRavenErrors);
|
2017-04-13 12:17:41 -04:00
|
|
|
},
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2017-04-13 12:17:41 -04:00
|
|
|
handleRavenErrors(event, req, config, err) {
|
2017-04-04 09:58:45 -04:00
|
|
|
const error = err || req.statusText;
|
2017-04-15 07:29:46 -04:00
|
|
|
const responseText = req.responseText || 'Unknown response text';
|
2017-04-04 09:58:45 -04:00
|
|
|
|
|
|
|
Raven.captureMessage(error, {
|
|
|
|
extra: {
|
|
|
|
type: config.type,
|
|
|
|
url: config.url,
|
|
|
|
data: config.data,
|
|
|
|
status: req.status,
|
2017-05-03 09:47:21 -04:00
|
|
|
response: responseText,
|
2017-04-04 09:58:45 -04:00
|
|
|
error,
|
|
|
|
event,
|
|
|
|
},
|
|
|
|
});
|
2017-04-13 12:17:41 -04:00
|
|
|
},
|
2017-04-18 13:58:03 -04:00
|
|
|
|
|
|
|
shouldSendSample() {
|
|
|
|
return Math.random() * 100 <= this.SAMPLE_RATE;
|
|
|
|
},
|
2017-04-14 16:09:16 -04:00
|
|
|
};
|
2017-04-04 09:58:45 -04:00
|
|
|
|
|
|
|
export default RavenConfig;
|