diff options
author | Stan Hu <stanhu@gmail.com> | 2018-12-07 18:29:00 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-12-07 18:29:00 +0300 |
commit | e17ccef5cadd7b8962a10bb43b1332658a54bd96 (patch) | |
tree | 05288b33ef4b4965e38a12c629041a4a6ad9d619 /spec/requests | |
parent | cda291f0c35d3724d2df916fcd95e00e84f469cf (diff) | |
parent | eb33ca49b8a402b347592c6cf982fb7619218370 (diff) |
Merge branch 'store-correlation-logs' into 'master'
Log and pass correlation-id between Unicorn, Sidekiq and Gitaly
See merge request gitlab-org/gitlab-ce!22844
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/helpers_spec.rb | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/spec/requests/api/helpers_spec.rb b/spec/requests/api/helpers_spec.rb index 2c40e266f5f..f7916441313 100644 --- a/spec/requests/api/helpers_spec.rb +++ b/spec/requests/api/helpers_spec.rb @@ -5,7 +5,6 @@ require_relative '../../../config/initializers/sentry' describe API::Helpers do include API::APIGuard::HelperMethods include described_class - include SentryHelper include TermsHelper let(:user) { create(:user) } @@ -224,8 +223,15 @@ describe API::Helpers do describe '.handle_api_exception' do before do - allow_any_instance_of(self.class).to receive(:sentry_enabled?).and_return(true) allow_any_instance_of(self.class).to receive(:rack_response) + allow(Gitlab::Sentry).to receive(:enabled?).and_return(true) + + stub_application_setting( + sentry_enabled: true, + sentry_dsn: "dummy://12345:67890@sentry.localdomain/sentry/42" + ) + configure_sentry + Raven.client.configuration.encoding = 'json' end it 'does not report a MethodNotAllowed exception to Sentry' do @@ -241,10 +247,13 @@ describe API::Helpers do exception = RuntimeError.new('test error') 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, extra: {}) + expect(Raven).to receive(:capture_exception).with(exception, tags: { + correlation_id: 'new-correlation-id' + }, extra: {}) - handle_api_exception(exception) + Gitlab::CorrelationId.use_id('new-correlation-id') do + handle_api_exception(exception) + end end context 'with a personal access token given' do @@ -255,7 +264,6 @@ describe API::Helpers do # We need to stub at a lower level than #sentry_enabled? otherwise # Sentry is not enabled when the request below is made, and the test # would pass even without the fix - expect(Gitlab::Sentry).to receive(:enabled?).twice.and_return(true) expect(ProjectsFinder).to receive(:new).and_raise('Runtime Error!') get api('/projects', personal_access_token: token) @@ -272,17 +280,7 @@ describe API::Helpers 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' |