diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /app/assets/javascripts/sentry | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'app/assets/javascripts/sentry')
-rw-r--r-- | app/assets/javascripts/sentry/constants.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/sentry/index.js | 16 | ||||
-rw-r--r-- | app/assets/javascripts/sentry/legacy_index.js | 34 | ||||
-rw-r--r-- | app/assets/javascripts/sentry/legacy_sentry_config.js | 64 | ||||
-rw-r--r-- | app/assets/javascripts/sentry/sentry_browser_wrapper.js | 27 | ||||
-rw-r--r-- | app/assets/javascripts/sentry/sentry_config.js | 39 |
6 files changed, 143 insertions, 38 deletions
diff --git a/app/assets/javascripts/sentry/constants.js b/app/assets/javascripts/sentry/constants.js index fd96da5faf6..5531c4f56db 100644 --- a/app/assets/javascripts/sentry/constants.js +++ b/app/assets/javascripts/sentry/constants.js @@ -1,5 +1,6 @@ import { __ } from '~/locale'; +// TODO: Remove in favor of https://gitlab.com/gitlab-org/gitlab/issues/35144 export const IGNORE_ERRORS = [ // Random plugins/extensions 'top.GLOBALS', diff --git a/app/assets/javascripts/sentry/index.js b/app/assets/javascripts/sentry/index.js index 176745b4177..5539a061726 100644 --- a/app/assets/javascripts/sentry/index.js +++ b/app/assets/javascripts/sentry/index.js @@ -1,26 +1,34 @@ import '../webpack'; +import * as Sentry from 'sentrybrowser7'; import SentryConfig from './sentry_config'; const index = function index() { + // Configuration for newer versions of Sentry SDK (v7) SentryConfig.init({ dsn: gon.sentry_dsn, + environment: gon.sentry_environment, currentUserId: gon.current_user_id, - whitelistUrls: + allowUrls: process.env.NODE_ENV === 'production' ? [gon.gitlab_url] : [gon.gitlab_url, 'webpack-internal://'], - environment: gon.sentry_environment, release: gon.revision, tags: { revision: gon.revision, feature_category: gon.feature_category, }, }); - - return SentryConfig; }; index(); +// The _Sentry object is globally exported so it can be used by +// ./sentry_browser_wrapper.js +// This hack allows us to load a single version of `@sentry/browser` +// in the browser, see app/views/layouts/_head.html.haml to find how it is imported. + +// eslint-disable-next-line no-underscore-dangle +window._Sentry = Sentry; + export default index; diff --git a/app/assets/javascripts/sentry/legacy_index.js b/app/assets/javascripts/sentry/legacy_index.js new file mode 100644 index 00000000000..604b982e128 --- /dev/null +++ b/app/assets/javascripts/sentry/legacy_index.js @@ -0,0 +1,34 @@ +import '../webpack'; + +import * as Sentry5 from 'sentrybrowser5'; +import LegacySentryConfig from './legacy_sentry_config'; + +const index = function index() { + // Configuration for legacy versions of Sentry SDK (v5) + LegacySentryConfig.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, + feature_category: gon.feature_category, + }, + }); +}; + +index(); + +// The _Sentry object is globally exported so it can be used by +// ./sentry_browser_wrapper.js +// This hack allows us to load a single version of `@sentry/browser` +// in the browser, see app/views/layouts/_head.html.haml to find how it is imported. + +// eslint-disable-next-line no-underscore-dangle +window._Sentry = Sentry5; + +export default index; diff --git a/app/assets/javascripts/sentry/legacy_sentry_config.js b/app/assets/javascripts/sentry/legacy_sentry_config.js new file mode 100644 index 00000000000..50a943886db --- /dev/null +++ b/app/assets/javascripts/sentry/legacy_sentry_config.js @@ -0,0 +1,64 @@ +import * as Sentry5 from 'sentrybrowser5'; +import $ from 'jquery'; +import { __ } from '~/locale'; +import { IGNORE_ERRORS, DENY_URLS, SAMPLE_RATE } from './constants'; + +const SentryConfig = { + IGNORE_ERRORS, + BLACKLIST_URLS: DENY_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; + + Sentry5.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, + }); + + Sentry5.setTags(tags); + }, + + setUser() { + Sentry5.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; + + Sentry5.captureMessage(error, { + extra: { + type, + url, + data, + status, + response: responseText, + error, + event, + }, + }); + }, +}; + +export default SentryConfig; diff --git a/app/assets/javascripts/sentry/sentry_browser_wrapper.js b/app/assets/javascripts/sentry/sentry_browser_wrapper.js new file mode 100644 index 00000000000..0382827f82c --- /dev/null +++ b/app/assets/javascripts/sentry/sentry_browser_wrapper.js @@ -0,0 +1,27 @@ +// The _Sentry object is globally exported so it can be used here +// This hack allows us to load a single version of `@sentry/browser` +// in the browser (or none). See app/views/layouts/_head.html.haml +// to find how it is imported. + +// This module wraps methods used by our production code. +// Each export is names as we cannot export the entire namespace from *. +export const captureException = (...args) => { + // eslint-disable-next-line no-underscore-dangle + const Sentry = window._Sentry; + + Sentry?.captureException(...args); +}; + +export const captureMessage = (...args) => { + // eslint-disable-next-line no-underscore-dangle + const Sentry = window._Sentry; + + Sentry?.captureMessage(...args); +}; + +export const withScope = (...args) => { + // eslint-disable-next-line no-underscore-dangle + const Sentry = window._Sentry; + + Sentry?.withScope(...args); +}; diff --git a/app/assets/javascripts/sentry/sentry_config.js b/app/assets/javascripts/sentry/sentry_config.js index 4c5b8dbad5a..ed8a55b7d44 100644 --- a/app/assets/javascripts/sentry/sentry_config.js +++ b/app/assets/javascripts/sentry/sentry_config.js @@ -1,30 +1,24 @@ -import * as Sentry from '@sentry/browser'; -import $ from 'jquery'; -import { __ } from '~/locale'; +import * as Sentry from 'sentrybrowser7'; import { IGNORE_ERRORS, DENY_URLS, SAMPLE_RATE } from './constants'; const SentryConfig = { - IGNORE_ERRORS, - BLACKLIST_URLS: DENY_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; + const { dsn, release, tags, allowUrls, environment } = this.options; Sentry.init({ dsn, release, - whitelistUrls, + allowUrls, environment, - ignoreErrors: this.IGNORE_ERRORS, // TODO: Remove in favor of https://gitlab.com/gitlab-org/gitlab/issues/35144 - blacklistUrls: this.BLACKLIST_URLS, + ignoreErrors: IGNORE_ERRORS, + denyUrls: DENY_URLS, sampleRate: SAMPLE_RATE, }); @@ -36,29 +30,6 @@ const SentryConfig = { 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; |