2021-02-18 13:10:41 -05:00
|
|
|
import * as Sentry from '@sentry/browser';
|
2017-05-25 03:12:36 -04:00
|
|
|
import $ from 'jquery';
|
2019-05-01 04:41:51 -04:00
|
|
|
import { __ } from '~/locale';
|
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',
|
2019-05-01 04:41:51 -04:00
|
|
|
__("Can't find variable: ZiteReader"),
|
|
|
|
__('jigsaw is not defined'),
|
|
|
|
__('ComboSearch is not defined'),
|
2017-04-18 13:58:03 -04:00
|
|
|
'http://loading.retry.widdit.com/',
|
|
|
|
'atomicFindClose',
|
|
|
|
// Facebook borked
|
|
|
|
'fb_xd_fragment',
|
|
|
|
// ISP "optimizing" proxy - `Cache-Control: no-transform` seems to
|
|
|
|
// reduce this. (thanks @acdha)
|
|
|
|
'bmi_SafeAddOnload',
|
|
|
|
'EBCallBackMessageReceived',
|
|
|
|
// See http://toolbar.conduit.com/Developer/HtmlAndGadget/Methods/JSInjection.aspx
|
|
|
|
'conduitPage',
|
|
|
|
];
|
|
|
|
|
2019-11-05 16:07:46 -05:00
|
|
|
const BLACKLIST_URLS = [
|
2017-04-18 13:58:03 -04:00
|
|
|
// 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-05-29 12:41:29 -04:00
|
|
|
/127\.0\.0\.1:4001\/isrunning/i, // Cacaoweb
|
2017-04-18 13:58:03 -04:00
|
|
|
/webappstoolbarba\.texthelp\.com\//i,
|
|
|
|
/metrics\.itunes\.apple\.com\.edgesuite\.net\//i,
|
|
|
|
];
|
|
|
|
|
2019-11-05 16:07:46 -05:00
|
|
|
const SAMPLE_RATE = 0.95;
|
2017-04-18 13:58:03 -04:00
|
|
|
|
2019-11-05 16:07:46 -05:00
|
|
|
const SentryConfig = {
|
2017-04-18 13:58:03 -04:00
|
|
|
IGNORE_ERRORS,
|
2019-11-05 16:07:46 -05:00
|
|
|
BLACKLIST_URLS,
|
2017-04-18 13:58:03 -04:00
|
|
|
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();
|
2019-11-05 16:07:46 -05:00
|
|
|
this.bindSentryErrors();
|
2017-04-04 09:58:45 -04:00
|
|
|
if (this.options.currentUserId) this.setUser();
|
2017-04-13 12:17:41 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
configure() {
|
2019-11-05 16:07:46 -05:00
|
|
|
const { dsn, release, tags, whitelistUrls, environment } = this.options;
|
2021-06-28 17:10:13 -04:00
|
|
|
|
2019-11-05 16:07:46 -05:00
|
|
|
Sentry.init({
|
|
|
|
dsn,
|
|
|
|
release,
|
|
|
|
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,
|
|
|
|
});
|
2021-06-28 17:10:13 -04:00
|
|
|
|
|
|
|
Sentry.setTags(tags);
|
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() {
|
2019-11-05 16:07:46 -05:00
|
|
|
Sentry.setUser({
|
2017-04-04 09:58:45 -04:00
|
|
|
id: this.options.currentUserId,
|
|
|
|
});
|
2017-04-13 12:17:41 -04:00
|
|
|
},
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2019-11-05 16:07:46 -05:00
|
|
|
bindSentryErrors() {
|
|
|
|
$(document).on('ajaxError.sentry', this.handleSentryErrors);
|
2017-04-13 12:17:41 -04:00
|
|
|
},
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2019-11-05 16:07:46 -05:00
|
|
|
handleSentryErrors(event, req, config, err) {
|
2017-04-04 09:58:45 -04:00
|
|
|
const error = err || req.statusText;
|
2019-11-05 16:07:46 -05:00
|
|
|
const { responseText = __('Unknown response text') } = req;
|
|
|
|
const { type, url, data } = config;
|
|
|
|
const { status } = req;
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2019-11-05 16:07:46 -05:00
|
|
|
Sentry.captureMessage(error, {
|
2017-04-04 09:58:45 -04:00
|
|
|
extra: {
|
2019-11-05 16:07:46 -05:00
|
|
|
type,
|
|
|
|
url,
|
|
|
|
data,
|
|
|
|
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-14 16:09:16 -04:00
|
|
|
};
|
2017-04-04 09:58:45 -04:00
|
|
|
|
2019-11-05 16:07:46 -05:00
|
|
|
export default SentryConfig;
|