diff options
author | Alejandro RodrÃguez <alejorro70@gmail.com> | 2017-10-02 21:52:19 -0300 |
---|---|---|
committer | Alejandro RodrÃguez <alejorro70@gmail.com> | 2017-10-05 18:31:34 -0300 |
commit | 60a35e4230404b84d4aee8015fb7821b0b194277 (patch) | |
tree | af4ae201825a61ac8284bdc7e875233c71073714 | |
parent | b40192a9464503bf4b141f8cf6133d7ba0f893fe (diff) | |
download | gitlab-ce-api-sentry-extra.tar.gz |
Send API parameters as extra data for sentry errorsapi-sentry-extra
-rw-r--r-- | config/initializers/sentry.rb | 4 | ||||
-rw-r--r-- | lib/api/helpers.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/helpers_spec.rb | 28 |
3 files changed, 31 insertions, 3 deletions
diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb index 62d0967009a..b2da3b3dc19 100644 --- a/config/initializers/sentry.rb +++ b/config/initializers/sentry.rb @@ -2,7 +2,7 @@ require 'gitlab/current_settings' -if Rails.env.production? +def configure_sentry # allow it to fail: it may do so when create_from_defaults is executed before migrations are actually done begin sentry_enabled = Gitlab::CurrentSettings.current_application_settings.sentry_enabled @@ -23,3 +23,5 @@ if Rails.env.production? end end end + +configure_sentry if Rails.env.production? diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 4964a76bef6..a87297a604c 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -287,7 +287,7 @@ module API if sentry_enabled? && report_exception?(exception) define_params_for_grape_middleware sentry_context - Raven.capture_exception(exception) + Raven.capture_exception(exception, extra: params) end # lifted from https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L60 diff --git a/spec/requests/api/helpers_spec.rb b/spec/requests/api/helpers_spec.rb index 060c8902471..862920ad7c3 100644 --- a/spec/requests/api/helpers_spec.rb +++ b/spec/requests/api/helpers_spec.rb @@ -1,4 +1,6 @@ require 'spec_helper' +require 'raven/transports/dummy' +require_relative '../../../config/initializers/sentry' describe API::Helpers do include API::APIGuard::HelperMethods @@ -476,7 +478,7 @@ describe API::Helpers do allow(exception).to receive(:backtrace).and_return(caller) expect_any_instance_of(self.class).to receive(:sentry_context) - expect(Raven).to receive(:capture_exception).with(exception) + expect(Raven).to receive(:capture_exception).with(exception, extra: {}) handle_api_exception(exception) end @@ -501,6 +503,30 @@ describe API::Helpers do expect(json_response['message']).to start_with("\nRuntimeError (Runtime Error!):") end end + + context 'extra information' do + # Sentry events are an array of the form [auth_header, data, options] + let(:event_data) { Raven.client.transport.events.first[1] } + + before do + stub_application_setting( + sentry_enabled: true, + sentry_dsn: "dummy://12345:67890@sentry.localdomain/sentry/42" + ) + configure_sentry + Raven.client.configuration.encoding = 'json' + end + + it 'sends the params, excluding confidential values' do + expect(Gitlab::Sentry).to receive(:enabled?).twice.and_return(true) + expect(ProjectsFinder).to receive(:new).and_raise('Runtime Error!') + + get api('/projects', user), password: 'dont_send_this', other_param: 'send_this' + + expect(event_data).to include('other_param=send_this') + expect(event_data).to include('password=********') + end + end end describe '.authenticate_non_get!' do |