summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/sentry
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-05 21:07:46 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-05 21:07:46 +0000
commit82cef8dd1f48ffbc7aaa1ff7374cdb859137e01e (patch)
tree0ebdac2f1880dd1dd3f73a956082759314e0994f /app/assets/javascripts/sentry
parent2baa63e740214382387abe77eeea6c0b1759e621 (diff)
downloadgitlab-ce-82cef8dd1f48ffbc7aaa1ff7374cdb859137e01e.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/sentry')
-rw-r--r--app/assets/javascripts/sentry/index.js23
-rw-r--r--app/assets/javascripts/sentry/sentry_config.js104
2 files changed, 127 insertions, 0 deletions
diff --git a/app/assets/javascripts/sentry/index.js b/app/assets/javascripts/sentry/index.js
new file mode 100644
index 00000000000..06e4e0aa507
--- /dev/null
+++ b/app/assets/javascripts/sentry/index.js
@@ -0,0 +1,23 @@
+import SentryConfig from './sentry_config';
+
+const index = function index() {
+ SentryConfig.init({
+ dsn: gon.sentry_dsn,
+ currentUserId: gon.current_user_id,
+ whitelistUrls:
+ process.env.NODE_ENV === 'production'
+ ? [gon.gitlab_url]
+ : [gon.gitlab_url, 'webpack-internal://'],
+ environment: gon.sentry_environment,
+ release: gon.revision,
+ tags: {
+ revision: gon.revision,
+ },
+ });
+
+ return SentryConfig;
+};
+
+index();
+
+export default index;
diff --git a/app/assets/javascripts/sentry/sentry_config.js b/app/assets/javascripts/sentry/sentry_config.js
new file mode 100644
index 00000000000..bc3b2f16a6a
--- /dev/null
+++ b/app/assets/javascripts/sentry/sentry_config.js
@@ -0,0 +1,104 @@
+import * as Sentry from '@sentry/browser';
+import $ from 'jquery';
+import { __ } from '~/locale';
+
+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 BLACKLIST_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 = 0.95;
+
+const SentryConfig = {
+ IGNORE_ERRORS,
+ BLACKLIST_URLS,
+ SAMPLE_RATE,
+ init(options = {}) {
+ this.options = options;
+
+ this.configure();
+ this.bindSentryErrors();
+ if (this.options.currentUserId) this.setUser();
+ },
+
+ configure() {
+ 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,
+ });
+ },
+
+ setUser() {
+ Sentry.setUser({
+ id: this.options.currentUserId,
+ });
+ },
+
+ bindSentryErrors() {
+ $(document).on('ajaxError.sentry', this.handleSentryErrors);
+ },
+
+ handleSentryErrors(event, req, config, err) {
+ const error = err || req.statusText;
+ const { responseText = __('Unknown response text') } = req;
+ const { type, url, data } = config;
+ const { status } = req;
+
+ Sentry.captureMessage(error, {
+ extra: {
+ type,
+ url,
+ data,
+ status,
+ response: responseText,
+ error,
+ event,
+ },
+ });
+ },
+};
+
+export default SentryConfig;