Commit 29c51742 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'feat/sentry-environment' into 'master'

feat: add option to define the Sentry Environment

See merge request gitlab-org/gitlab-ce!27091
parents 93a332a6 aebb2f70
...@@ -4,8 +4,11 @@ const index = function index() { ...@@ -4,8 +4,11 @@ const index = function index() {
RavenConfig.init({ RavenConfig.init({
sentryDsn: gon.sentry_dsn, sentryDsn: gon.sentry_dsn,
currentUserId: gon.current_user_id, currentUserId: gon.current_user_id,
whitelistUrls: [gon.gitlab_url], whitelistUrls:
isProduction: process.env.NODE_ENV, process.env.NODE_ENV === 'production'
? [gon.gitlab_url]
: [gon.gitlab_url, 'webpack-internal://'],
environment: gon.sentry_environment,
release: gon.revision, release: gon.revision,
tags: { tags: {
revision: gon.revision, revision: gon.revision,
......
...@@ -61,7 +61,7 @@ const RavenConfig = { ...@@ -61,7 +61,7 @@ const RavenConfig = {
release: this.options.release, release: this.options.release,
tags: this.options.tags, tags: this.options.tags,
whitelistUrls: this.options.whitelistUrls, whitelistUrls: this.options.whitelistUrls,
environment: this.options.isProduction ? 'production' : 'development', environment: this.options.environment,
ignoreErrors: this.IGNORE_ERRORS, ignoreErrors: this.IGNORE_ERRORS,
ignoreUrls: this.IGNORE_URLS, ignoreUrls: this.IGNORE_URLS,
shouldSendCallback: this.shouldSendSample.bind(this), shouldSendCallback: this.shouldSendSample.bind(this),
......
...@@ -183,6 +183,22 @@ module ApplicationSettingImplementation ...@@ -183,6 +183,22 @@ module ApplicationSettingImplementation
clientside_sentry_dsn.strip! if clientside_sentry_dsn.present? clientside_sentry_dsn.strip! if clientside_sentry_dsn.present?
end end
def sentry_enabled
Gitlab.config.sentry.enabled || read_attribute(:sentry_enabled)
end
def sentry_dsn
Gitlab.config.sentry.dsn || read_attribute(:sentry_dsn)
end
def clientside_sentry_enabled
Gitlab.config.sentry.enabled || read_attribute(:clientside_sentry_enabled)
end
def clientside_sentry_dsn
Gitlab.config.sentry.dsn || read_attribute(:clientside_sentry_dsn)
end
def performance_bar_allowed_group def performance_bar_allowed_group
Group.find_by_id(performance_bar_allowed_group_id) Group.find_by_id(performance_bar_allowed_group_id)
end end
......
= form_for @application_setting, url: admin_application_settings_path(anchor: 'js-logging-settings'), html: { class: 'fieldset-form' } do |f| = form_for @application_setting, url: admin_application_settings_path(anchor: 'js-logging-settings'), html: { class: 'fieldset-form' } do |f|
= form_errors(@application_setting) = form_errors(@application_setting)
%p
%strong
NOTE:
These settings will be removed from the UI in a GitLab 12.0 release and made available within gitlab.yml.
The specific client side DSN setting is already handled as a component from a Sentry perspective anb will be removed.
In addition, you will be able to define a Sentry Environment to differentiate between multiple deployments. For example, development, staging, and production.
%fieldset %fieldset
.form-group .form-group
.form-check .form-check
......
---
title: Allow Sentry configuration to be passed on gitlab.yml
merge_request: 27091
author: Roger Meier
type: added
...@@ -315,6 +315,13 @@ production: &base ...@@ -315,6 +315,13 @@ production: &base
# path: shared/registry # path: shared/registry
# issuer: gitlab-issuer # issuer: gitlab-issuer
## Error Reporting and Logging with Sentry
sentry:
# enabled: false
# dsn: https://<key>@sentry.io/<project>
# environment: 'production' # e.g. development, staging, production
# #
# 2. GitLab CI settings # 2. GitLab CI settings
# ========================== # ==========================
......
...@@ -217,6 +217,14 @@ Settings.registry['issuer'] ||= nil ...@@ -217,6 +217,14 @@ Settings.registry['issuer'] ||= nil
Settings.registry['host_port'] ||= [Settings.registry['host'], Settings.registry['port']].compact.join(':') Settings.registry['host_port'] ||= [Settings.registry['host'], Settings.registry['port']].compact.join(':')
Settings.registry['path'] = Settings.absolute(Settings.registry['path'] || File.join(Settings.shared['path'], 'registry')) Settings.registry['path'] = Settings.absolute(Settings.registry['path'] || File.join(Settings.shared['path'], 'registry'))
#
# Error Reporting and Logging with Sentry
#
Settings['sentry'] ||= Settingslogic.new({})
Settings.sentry['enabled'] ||= false
Settings.sentry['dsn'] ||= nil
Settings.sentry['environment'] ||= nil
# #
# Pages # Pages
# #
......
...@@ -14,6 +14,7 @@ def configure_sentry ...@@ -14,6 +14,7 @@ def configure_sentry
Raven.configure do |config| Raven.configure do |config|
config.dsn = Gitlab::CurrentSettings.current_application_settings.sentry_dsn config.dsn = Gitlab::CurrentSettings.current_application_settings.sentry_dsn
config.release = Gitlab.revision config.release = Gitlab.revision
config.current_environment = Gitlab.config.sentry.environment.presence
# Sanitize fields based on those sanitized from Rails. # Sanitize fields based on those sanitized from Rails.
config.sanitize_fields = Rails.application.config.filter_parameters.map(&:to_s) config.sanitize_fields = Rails.application.config.filter_parameters.map(&:to_s)
......
...@@ -15,7 +15,12 @@ module Gitlab ...@@ -15,7 +15,12 @@ module Gitlab
gon.relative_url_root = Gitlab.config.gitlab.relative_url_root gon.relative_url_root = Gitlab.config.gitlab.relative_url_root
gon.shortcuts_path = Gitlab::Routing.url_helpers.help_page_path('shortcuts') gon.shortcuts_path = Gitlab::Routing.url_helpers.help_page_path('shortcuts')
gon.user_color_scheme = Gitlab::ColorSchemes.for_user(current_user).css_class gon.user_color_scheme = Gitlab::ColorSchemes.for_user(current_user).css_class
gon.sentry_dsn = Gitlab::CurrentSettings.clientside_sentry_dsn if Gitlab::CurrentSettings.clientside_sentry_enabled
if Gitlab::CurrentSettings.clientside_sentry_enabled
gon.sentry_dsn = Gitlab::CurrentSettings.clientside_sentry_dsn
gon.sentry_environment = Gitlab.config.sentry.environment
end
gon.gitlab_url = Gitlab.config.gitlab.url gon.gitlab_url = Gitlab.config.gitlab.url
gon.revision = Gitlab.revision gon.revision = Gitlab.revision
gon.gitlab_logo = ActionController::Base.helpers.asset_path('gitlab_logo.png') gon.gitlab_logo = ActionController::Base.helpers.asset_path('gitlab_logo.png')
......
...@@ -5,19 +5,19 @@ describe('RavenConfig options', () => { ...@@ -5,19 +5,19 @@ describe('RavenConfig options', () => {
const sentryDsn = 'sentryDsn'; const sentryDsn = 'sentryDsn';
const currentUserId = 'currentUserId'; const currentUserId = 'currentUserId';
const gitlabUrl = 'gitlabUrl'; const gitlabUrl = 'gitlabUrl';
const isProduction = 'isProduction'; const environment = 'test';
const revision = 'revision'; const revision = 'revision';
let indexReturnValue; let indexReturnValue;
beforeEach(() => { beforeEach(() => {
window.gon = { window.gon = {
sentry_dsn: sentryDsn, sentry_dsn: sentryDsn,
sentry_environment: environment,
current_user_id: currentUserId, current_user_id: currentUserId,
gitlab_url: gitlabUrl, gitlab_url: gitlabUrl,
revision, revision,
}; };
process.env.NODE_ENV = isProduction;
process.env.HEAD_COMMIT_SHA = revision; process.env.HEAD_COMMIT_SHA = revision;
spyOn(RavenConfig, 'init'); spyOn(RavenConfig, 'init');
...@@ -25,12 +25,12 @@ describe('RavenConfig options', () => { ...@@ -25,12 +25,12 @@ describe('RavenConfig options', () => {
indexReturnValue = index(); indexReturnValue = index();
}); });
it('should init with .sentryDsn, .currentUserId, .whitelistUrls and .isProduction', () => { it('should init with .sentryDsn, .currentUserId, .whitelistUrls and environment', () => {
expect(RavenConfig.init).toHaveBeenCalledWith({ expect(RavenConfig.init).toHaveBeenCalledWith({
sentryDsn, sentryDsn,
currentUserId, currentUserId,
whitelistUrls: [gitlabUrl], whitelistUrls: [gitlabUrl, 'webpack-internal://'],
isProduction, environment,
release: revision, release: revision,
tags: { tags: {
revision, revision,
......
...@@ -69,8 +69,8 @@ describe('RavenConfig', () => { ...@@ -69,8 +69,8 @@ describe('RavenConfig', () => {
let ravenConfig; let ravenConfig;
const options = { const options = {
sentryDsn: '//sentryDsn', sentryDsn: '//sentryDsn',
whitelistUrls: ['//gitlabUrl'], whitelistUrls: ['//gitlabUrl', 'webpack-internal://'],
isProduction: true, environment: 'test',
release: 'revision', release: 'revision',
tags: { tags: {
revision: 'revision', revision: 'revision',
...@@ -95,7 +95,7 @@ describe('RavenConfig', () => { ...@@ -95,7 +95,7 @@ describe('RavenConfig', () => {
release: options.release, release: options.release,
tags: options.tags, tags: options.tags,
whitelistUrls: options.whitelistUrls, whitelistUrls: options.whitelistUrls,
environment: 'production', environment: 'test',
ignoreErrors: ravenConfig.IGNORE_ERRORS, ignoreErrors: ravenConfig.IGNORE_ERRORS,
ignoreUrls: ravenConfig.IGNORE_URLS, ignoreUrls: ravenConfig.IGNORE_URLS,
shouldSendCallback: jasmine.any(Function), shouldSendCallback: jasmine.any(Function),
...@@ -106,8 +106,8 @@ describe('RavenConfig', () => { ...@@ -106,8 +106,8 @@ describe('RavenConfig', () => {
expect(raven.install).toHaveBeenCalled(); expect(raven.install).toHaveBeenCalled();
}); });
it('should set .environment to development if isProduction is false', () => { it('should set environment from options', () => {
ravenConfig.options.isProduction = false; ravenConfig.options.environment = 'development';
RavenConfig.configure.call(ravenConfig); RavenConfig.configure.call(ravenConfig);
......
...@@ -249,4 +249,41 @@ RSpec.shared_examples 'application settings examples' do ...@@ -249,4 +249,41 @@ RSpec.shared_examples 'application settings examples' do
expect(setting.password_authentication_enabled_for_web?).to be_falsey expect(setting.password_authentication_enabled_for_web?).to be_falsey
end end
describe 'sentry settings' do
context 'when the sentry settings are not set in gitlab.yml' do
it 'fallbacks to the settings in the database' do
setting.sentry_enabled = true
setting.sentry_dsn = 'https://b44a0828b72421a6d8e99efd68d44fa8@example.com/40'
setting.clientside_sentry_enabled = true
setting.clientside_sentry_dsn = 'https://b44a0828b72421a6d8e99efd68d44fa8@example.com/41'
allow(Gitlab.config.sentry).to receive(:enabled).and_return(false)
allow(Gitlab.config.sentry).to receive(:dsn).and_return(nil)
expect(setting.sentry_enabled).to eq true
expect(setting.sentry_dsn).to eq 'https://b44a0828b72421a6d8e99efd68d44fa8@example.com/40'
expect(setting.clientside_sentry_enabled).to eq true
expect(setting.clientside_sentry_dsn). to eq 'https://b44a0828b72421a6d8e99efd68d44fa8@example.com/41'
end
end
context 'when the sentry settings are set in gitlab.yml' do
it 'does not fallback to the settings in the database' do
setting.sentry_enabled = false
setting.sentry_dsn = 'https://b44a0828b72421a6d8e99efd68d44fa8@example.com/40'
setting.clientside_sentry_enabled = false
setting.clientside_sentry_dsn = 'https://b44a0828b72421a6d8e99efd68d44fa8@example.com/41'
allow(Gitlab.config.sentry).to receive(:enabled).and_return(true)
allow(Gitlab.config.sentry).to receive(:dsn).and_return('https://b44a0828b72421a6d8e99efd68d44fa8@example.com/42')
expect(setting).not_to receive(:read_attribute)
expect(setting.sentry_enabled).to eq true
expect(setting.sentry_dsn).to eq 'https://b44a0828b72421a6d8e99efd68d44fa8@example.com/42'
expect(setting.clientside_sentry_enabled).to eq true
expect(setting.clientside_sentry_dsn). to eq 'https://b44a0828b72421a6d8e99efd68d44fa8@example.com/42'
end
end
end
end end
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