Commit a38e3d6c authored by Frédéric Caplette's avatar Frédéric Caplette

Merge branch 'mrincon-sentry-feature-category' into 'master'

Add "feature_category" to clientside errors in Sentry

See merge request gitlab-org/gitlab!64689
parents 49c6baee 90ef6e4e
...@@ -14,6 +14,7 @@ const index = function index() { ...@@ -14,6 +14,7 @@ const index = function index() {
release: gon.revision, release: gon.revision,
tags: { tags: {
revision: gon.revision, revision: gon.revision,
feature_category: gon.feature_category,
}, },
}); });
......
...@@ -59,16 +59,18 @@ const SentryConfig = { ...@@ -59,16 +59,18 @@ const SentryConfig = {
configure() { configure() {
const { dsn, release, tags, whitelistUrls, environment } = this.options; const { dsn, release, tags, whitelistUrls, environment } = this.options;
Sentry.init({ Sentry.init({
dsn, dsn,
release, release,
tags,
whitelistUrls, whitelistUrls,
environment, environment,
ignoreErrors: this.IGNORE_ERRORS, // TODO: Remove in favor of https://gitlab.com/gitlab-org/gitlab/issues/35144 ignoreErrors: this.IGNORE_ERRORS, // TODO: Remove in favor of https://gitlab.com/gitlab-org/gitlab/issues/35144
blacklistUrls: this.BLACKLIST_URLS, blacklistUrls: this.BLACKLIST_URLS,
sampleRate: SAMPLE_RATE, sampleRate: SAMPLE_RATE,
}); });
Sentry.setTags(tags);
}, },
setUser() { setUser() {
......
...@@ -23,6 +23,7 @@ module Gitlab ...@@ -23,6 +23,7 @@ module Gitlab
gon.gitlab_url = Gitlab.config.gitlab.url gon.gitlab_url = Gitlab.config.gitlab.url
gon.revision = Gitlab.revision gon.revision = Gitlab.revision
gon.feature_category = Gitlab::ApplicationContext.current_context_attribute(:feature_category).presence
gon.gitlab_logo = ActionController::Base.helpers.asset_path('gitlab_logo.png') gon.gitlab_logo = ActionController::Base.helpers.asset_path('gitlab_logo.png')
gon.sprite_icons = IconsHelper.sprite_icon_path gon.sprite_icons = IconsHelper.sprite_icon_path
gon.sprite_file_icons = IconsHelper.sprite_file_icons_path gon.sprite_file_icons = IconsHelper.sprite_file_icons_path
......
...@@ -7,6 +7,8 @@ describe('SentryConfig options', () => { ...@@ -7,6 +7,8 @@ describe('SentryConfig options', () => {
const gitlabUrl = 'gitlabUrl'; const gitlabUrl = 'gitlabUrl';
const environment = 'test'; const environment = 'test';
const revision = 'revision'; const revision = 'revision';
const featureCategory = 'my_feature_category';
let indexReturnValue; let indexReturnValue;
beforeEach(() => { beforeEach(() => {
...@@ -16,6 +18,7 @@ describe('SentryConfig options', () => { ...@@ -16,6 +18,7 @@ describe('SentryConfig options', () => {
current_user_id: currentUserId, current_user_id: currentUserId,
gitlab_url: gitlabUrl, gitlab_url: gitlabUrl,
revision, revision,
feature_category: featureCategory,
}; };
process.env.HEAD_COMMIT_SHA = revision; process.env.HEAD_COMMIT_SHA = revision;
...@@ -34,6 +37,7 @@ describe('SentryConfig options', () => { ...@@ -34,6 +37,7 @@ describe('SentryConfig options', () => {
release: revision, release: revision,
tags: { tags: {
revision, revision,
feature_category: featureCategory,
}, },
}); });
}); });
......
...@@ -72,11 +72,13 @@ describe('SentryConfig', () => { ...@@ -72,11 +72,13 @@ describe('SentryConfig', () => {
release: 'revision', release: 'revision',
tags: { tags: {
revision: 'revision', revision: 'revision',
feature_category: 'my_feature_category',
}, },
}; };
beforeEach(() => { beforeEach(() => {
jest.spyOn(Sentry, 'init').mockImplementation(); jest.spyOn(Sentry, 'init').mockImplementation();
jest.spyOn(Sentry, 'setTags').mockImplementation();
sentryConfig.options = options; sentryConfig.options = options;
sentryConfig.IGNORE_ERRORS = 'ignore_errors'; sentryConfig.IGNORE_ERRORS = 'ignore_errors';
...@@ -89,7 +91,6 @@ describe('SentryConfig', () => { ...@@ -89,7 +91,6 @@ describe('SentryConfig', () => {
expect(Sentry.init).toHaveBeenCalledWith({ expect(Sentry.init).toHaveBeenCalledWith({
dsn: options.dsn, dsn: options.dsn,
release: options.release, release: options.release,
tags: options.tags,
sampleRate: 0.95, sampleRate: 0.95,
whitelistUrls: options.whitelistUrls, whitelistUrls: options.whitelistUrls,
environment: 'test', environment: 'test',
...@@ -98,6 +99,10 @@ describe('SentryConfig', () => { ...@@ -98,6 +99,10 @@ describe('SentryConfig', () => {
}); });
}); });
it('should call Sentry.setTags', () => {
expect(Sentry.setTags).toHaveBeenCalledWith(options.tags);
});
it('should set environment from options', () => { it('should set environment from options', () => {
sentryConfig.options.environment = 'development'; sentryConfig.options.environment = 'development';
...@@ -106,7 +111,6 @@ describe('SentryConfig', () => { ...@@ -106,7 +111,6 @@ describe('SentryConfig', () => {
expect(Sentry.init).toHaveBeenCalledWith({ expect(Sentry.init).toHaveBeenCalledWith({
dsn: options.dsn, dsn: options.dsn,
release: options.release, release: options.release,
tags: options.tags,
sampleRate: 0.95, sampleRate: 0.95,
whitelistUrls: options.whitelistUrls, whitelistUrls: options.whitelistUrls,
environment: 'development', environment: 'development',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment