2017-09-10 17:25:29 +05:30
|
|
|
import $ from 'jquery';
|
2021-01-03 14:25:43 +05:30
|
|
|
import * as Sentry from '~/sentry/wrapper';
|
2019-07-31 22:56:46 +05:30
|
|
|
import { __ } from '~/locale';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
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',
|
2019-07-31 22:56:46 +05:30
|
|
|
__("Can't find variable: ZiteReader"),
|
|
|
|
__('jigsaw is not defined'),
|
|
|
|
__('ComboSearch is not defined'),
|
2017-08-17 22:00:37 +05:30
|
|
|
'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',
|
|
|
|
];
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
const BLACKLIST_URLS = [
|
2017-08-17 22:00:37 +05:30
|
|
|
// 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
|
2018-11-08 19:23:39 +05:30
|
|
|
/127\.0\.0\.1:4001\/isrunning/i, // Cacaoweb
|
2017-08-17 22:00:37 +05:30
|
|
|
/webappstoolbarba\.texthelp\.com\//i,
|
|
|
|
/metrics\.itunes\.apple\.com\.edgesuite\.net\//i,
|
|
|
|
];
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
const SAMPLE_RATE = 0.95;
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
const SentryConfig = {
|
2017-08-17 22:00:37 +05:30
|
|
|
IGNORE_ERRORS,
|
2019-12-26 22:10:19 +05:30
|
|
|
BLACKLIST_URLS,
|
2017-08-17 22:00:37 +05:30
|
|
|
SAMPLE_RATE,
|
|
|
|
init(options = {}) {
|
|
|
|
this.options = options;
|
|
|
|
|
|
|
|
this.configure();
|
2019-12-26 22:10:19 +05:30
|
|
|
this.bindSentryErrors();
|
2017-08-17 22:00:37 +05:30
|
|
|
if (this.options.currentUserId) this.setUser();
|
|
|
|
},
|
|
|
|
|
|
|
|
configure() {
|
2019-12-26 22:10:19 +05:30
|
|
|
const { dsn, release, tags, whitelistUrls, environment } = this.options;
|
|
|
|
Sentry.init({
|
|
|
|
dsn,
|
|
|
|
release,
|
|
|
|
tags,
|
|
|
|
whitelistUrls,
|
|
|
|
environment,
|
|
|
|
ignoreErrors: this.IGNORE_ERRORS, // TODO: Remove in favor of https://gitlab.com/gitlab-org/gitlab/issues/35144
|
|
|
|
blacklistUrls: this.BLACKLIST_URLS,
|
|
|
|
sampleRate: SAMPLE_RATE,
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
setUser() {
|
2019-12-26 22:10:19 +05:30
|
|
|
Sentry.setUser({
|
2017-08-17 22:00:37 +05:30
|
|
|
id: this.options.currentUserId,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
bindSentryErrors() {
|
|
|
|
$(document).on('ajaxError.sentry', this.handleSentryErrors);
|
2017-08-17 22:00:37 +05:30
|
|
|
},
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
handleSentryErrors(event, req, config, err) {
|
2017-08-17 22:00:37 +05:30
|
|
|
const error = err || req.statusText;
|
2019-12-26 22:10:19 +05:30
|
|
|
const { responseText = __('Unknown response text') } = req;
|
|
|
|
const { type, url, data } = config;
|
|
|
|
const { status } = req;
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
Sentry.captureMessage(error, {
|
2017-08-17 22:00:37 +05:30
|
|
|
extra: {
|
2019-12-26 22:10:19 +05:30
|
|
|
type,
|
|
|
|
url,
|
|
|
|
data,
|
|
|
|
status,
|
2017-08-17 22:00:37 +05:30
|
|
|
response: responseText,
|
|
|
|
error,
|
|
|
|
event,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
export default SentryConfig;
|