diff options
| author | Robert Speicher <robert@gitlab.com> | 2016-08-24 22:42:02 +0000 |
|---|---|---|
| committer | Robert Speicher <robert@gitlab.com> | 2016-08-24 22:42:02 +0000 |
| commit | 9ea01f32fe4355179da6082742b6ad06f9603388 (patch) | |
| tree | 2d90474171f7909eb4601f610c95dd1a029c548a /app | |
| parent | f52cf56e90b2be3edb405fe588c94b637cf5088b (diff) | |
| parent | 170885edd6f3ea52792511586778e0dce8021cf7 (diff) | |
| download | gitlab-ce-9ea01f32fe4355179da6082742b6ad06f9603388.tar.gz | |
Merge branch 'add-sentry-logging-to-api' into 'master'
Add Sentry logging to API calls
## What does this MR do?
This MR adds support for Sentry logging in the API.
## Are there points in the code the reviewer needs to double check?
Since the `Grape::Middleware` doesn't have a `params` method, I had to define one using the Rack Request.
## Why was this MR needed?
We are missing a lot of useful errors in the API causing git push/pull errors
## What are the relevant issue numbers?
#21043
See merge request !5882
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/application_controller.rb | 23 | ||||
| -rw-r--r-- | app/helpers/sentry_helper.rb | 27 |
2 files changed, 28 insertions, 22 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 634d36a4467..70a2275592b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base include Gitlab::GonHelper include GitlabRoutingHelper include PageLayoutHelper + include SentryHelper include WorkhorseHelper before_action :authenticate_user_from_private_token! @@ -46,28 +47,6 @@ class ApplicationController < ActionController::Base protected - def sentry_context - if Rails.env.production? && current_application_settings.sentry_enabled - if current_user - Raven.user_context( - id: current_user.id, - email: current_user.email, - username: current_user.username, - ) - end - - Raven.tags_context(program: sentry_program_context) - end - end - - def sentry_program_context - if Sidekiq.server? - 'sidekiq' - else - 'rails' - end - end - # This filter handles both private tokens and personal access tokens def authenticate_user_from_private_token! token_string = params[:private_token].presence || request.headers['PRIVATE-TOKEN'].presence diff --git a/app/helpers/sentry_helper.rb b/app/helpers/sentry_helper.rb new file mode 100644 index 00000000000..f8cccade15b --- /dev/null +++ b/app/helpers/sentry_helper.rb @@ -0,0 +1,27 @@ +module SentryHelper + def sentry_enabled? + Rails.env.production? && current_application_settings.sentry_enabled? + end + + def sentry_context + return unless sentry_enabled? + + if current_user + Raven.user_context( + id: current_user.id, + email: current_user.email, + username: current_user.username, + ) + end + + Raven.tags_context(program: sentry_program_context) + end + + def sentry_program_context + if Sidekiq.server? + 'sidekiq' + else + 'rails' + end + end +end |
