summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2016-01-20 19:00:35 +0000
committerRobert Speicher <robert@gitlab.com>2016-01-20 19:00:35 +0000
commite3c43ca7d0c6353709456af05d0d65a2fa05b3d0 (patch)
tree6129b087f49d642999afdc818e43f64d01d03ca1
parent67bd2ed3a2d1d58cc54dc2def1409f185fa01529 (diff)
parent7838c957c23a36fb64125a1baf14454b735e9561 (diff)
downloadgitlab-ce-e3c43ca7d0c6353709456af05d0d65a2fa05b3d0.tar.gz
Merge branch 'sentry-integration' into 'master'
Add sentry integration Sentry is an event logging platform primarily focused on capturing and aggregating exceptions. With this MR it will be possible to log and track exceptions from GitLab to Sentry. https://gitlab.com/gitlab-com/operations/issues/39 See merge request !2485
-rw-r--r--Gemfile3
-rw-r--r--Gemfile.lock3
-rw-r--r--app/controllers/admin/application_settings_controller.rb2
-rw-r--r--app/controllers/application_controller.rb11
-rw-r--r--app/models/application_setting.rb6
-rw-r--r--app/views/admin/application_settings/_form.html.haml21
-rw-r--r--config/initializers/sentry.rb19
-rw-r--r--db/migrate/20160118155830_add_sentry_to_application_settings.rb8
-rw-r--r--db/schema.rb2
-rw-r--r--spec/models/application_setting_spec.rb2
10 files changed, 76 insertions, 1 deletions
diff --git a/Gemfile b/Gemfile
index 1c586adbfb5..746d8e5d6de 100644
--- a/Gemfile
+++ b/Gemfile
@@ -293,6 +293,9 @@ end
group :production do
gem "gitlab_meta", '7.0'
+
+ # Sentry integration
+ gem 'sentry-raven'
end
gem "newrelic_rpm", '~> 3.9.4.245'
diff --git a/Gemfile.lock b/Gemfile.lock
index acd7978c345..5e0718af70f 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -725,6 +725,8 @@ GEM
activesupport (>= 3.1, < 4.3)
select2-rails (3.5.9.3)
thor (~> 0.14)
+ sentry-raven (0.15.3)
+ faraday (>= 0.7.6)
settingslogic (2.0.9)
sexp_processor (4.6.0)
sham_rack (1.3.6)
@@ -1008,6 +1010,7 @@ DEPENDENCIES
sdoc (~> 0.3.20)
seed-fu (~> 2.3.5)
select2-rails (~> 3.5.9)
+ sentry-raven
settingslogic (~> 2.0.9)
sham_rack
shoulda-matchers (~> 2.8.0)
diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb
index 91f7d78bd73..9943745208e 100644
--- a/app/controllers/admin/application_settings_controller.rb
+++ b/app/controllers/admin/application_settings_controller.rb
@@ -77,6 +77,8 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
:recaptcha_enabled,
:recaptcha_site_key,
:recaptcha_private_key,
+ :sentry_enabled,
+ :sentry_dsn,
restricted_visibility_levels: [],
import_sources: []
)
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index bf99b2e777d..633c3f55614 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -15,6 +15,7 @@ class ApplicationController < ActionController::Base
before_action :check_password_expiration
before_action :check_2fa_requirement
before_action :ldap_security_check
+ before_action :sentry_user_context
before_action :default_headers
before_action :add_gon_variables
before_action :configure_permitted_parameters, if: :devise_controller?
@@ -41,6 +42,16 @@ class ApplicationController < ActionController::Base
protected
+ def sentry_user_context
+ if Rails.env.production? && current_application_settings.sentry_enabled && current_user
+ Raven.user_context(
+ id: current_user.id,
+ email: current_user.email,
+ username: current_user.username,
+ )
+ end
+ end
+
# From https://github.com/plataformatec/devise/wiki/How-To:-Simple-Token-Authentication-Example
# https://gist.github.com/josevalim/fb706b1e933ef01e4fb6
def authenticate_user_from_token!
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb
index 6c6c2468374..59563b8823c 100644
--- a/app/models/application_setting.rb
+++ b/app/models/application_setting.rb
@@ -41,6 +41,8 @@
# recaptcha_site_key :string
# recaptcha_private_key :string
# metrics_port :integer default(8089)
+# sentry_enabled :boolean default(FALSE)
+# sentry_dsn :string
#
class ApplicationSetting < ActiveRecord::Base
@@ -82,6 +84,10 @@ class ApplicationSetting < ActiveRecord::Base
presence: true,
if: :recaptcha_enabled
+ validates :sentry_dsn,
+ presence: true,
+ if: :sentry_enabled
+
validates_each :restricted_visibility_levels do |record, attr, value|
unless value.nil?
value.each do |level|
diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml
index 83f6814d822..35e4dd761ab 100644
--- a/app/views/admin/application_settings/_form.html.haml
+++ b/app/views/admin/application_settings/_form.html.haml
@@ -226,11 +226,30 @@
= f.text_field :recaptcha_site_key, class: 'form-control'
.help-block
Generate site and private keys here:
- %a{ href: 'http://www.google.com/recaptcha', target: 'blank'} http://www.google.com/recaptcha
+ %a{ href: 'http://www.google.com/recaptcha', target: '_blank'} http://www.google.com/recaptcha
.form-group
= f.label :recaptcha_private_key, 'reCAPTCHA Private Key', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :recaptcha_private_key, class: 'form-control'
+ %fieldset
+ %legend Error Reporting and Logging
+ %p
+ These settings require a restart to take effect.
+ .form-group
+ .col-sm-offset-2.col-sm-10
+ .checkbox
+ = f.label :sentry_enabled do
+ = f.check_box :sentry_enabled
+ Enable Sentry
+ .help-block
+ Sentry is an error reporting and logging tool which is currently not shipped with GitLab, get it here:
+ %a{ href: 'https://getsentry.com', target: '_blank' } https://getsentry.com
+
+ .form-group
+ = f.label :sentry_dsn, 'Sentry DSN', class: 'control-label col-sm-2'
+ .col-sm-10
+ = f.text_field :sentry_dsn, class: 'form-control'
+
.form-actions
= f.submit 'Save', class: 'btn btn-primary'
diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb
new file mode 100644
index 00000000000..d0630b9fa07
--- /dev/null
+++ b/config/initializers/sentry.rb
@@ -0,0 +1,19 @@
+# Be sure to restart your server when you modify this file.
+
+require 'gitlab/current_settings'
+include Gitlab::CurrentSettings
+
+if Rails.env.production?
+ # allow it to fail: it may do so when create_from_defaults is executed before migrations are actually done
+ begin
+ sentry_enabled = current_application_settings.sentry_enabled
+ rescue
+ sentry_enabled = false
+ end
+
+ if sentry_enabled
+ Raven.configure do |config|
+ config.dsn = current_application_settings.sentry_dsn
+ end
+ end
+end
diff --git a/db/migrate/20160118155830_add_sentry_to_application_settings.rb b/db/migrate/20160118155830_add_sentry_to_application_settings.rb
new file mode 100644
index 00000000000..fa7ff9d9228
--- /dev/null
+++ b/db/migrate/20160118155830_add_sentry_to_application_settings.rb
@@ -0,0 +1,8 @@
+class AddSentryToApplicationSettings < ActiveRecord::Migration
+ def change
+ change_table :application_settings do |t|
+ t.boolean :sentry_enabled, default: false
+ t.string :sentry_dsn
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index dc7cb9f667f..8e9501e4827 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -62,6 +62,8 @@ ActiveRecord::Schema.define(version: 20160119145451) do
t.string "recaptcha_private_key"
t.integer "metrics_port", default: 8089
t.integer "metrics_sample_interval", default: 15
+ t.boolean "sentry_enabled", default: false
+ t.string "sentry_dsn"
end
create_table "audit_events", force: :cascade do |t|
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb
index 91b250265e6..f4c58882757 100644
--- a/spec/models/application_setting_spec.rb
+++ b/spec/models/application_setting_spec.rb
@@ -41,6 +41,8 @@
# recaptcha_site_key :string
# recaptcha_private_key :string
# metrics_port :integer default(8089)
+# sentry_enabled :boolean default(FALSE)
+# sentry_dsn :string
#
require 'spec_helper'