2021-04-17 20:07:23 +05:30
|
|
|
import * as Sentry from '@sentry/browser';
|
2017-09-10 17:25:29 +05:30
|
|
|
import $ from 'jquery';
|
2019-07-31 22:56:46 +05:30
|
|
|
import { __ } from '~/locale';
|
2023-01-13 00:05:48 +05:30
|
|
|
import { IGNORE_ERRORS, DENY_URLS, SAMPLE_RATE } from './constants';
|
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,
|
2023-01-13 00:05:48 +05:30
|
|
|
BLACKLIST_URLS: DENY_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;
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
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-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
Sentry.setTags(tags);
|
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;
|