diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-04-13 19:32:54 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-04-17 12:39:23 +0300 |
commit | 5f7f5eda925801cdc3b0932a3485a00d967c916c (patch) | |
tree | 99b002aff3e5a98110571d950f0569fee164269a /spec/lib | |
parent | a56611e3892b9039f6a8196c37d8b70a3c86c68b (diff) |
Method to track recoverable exceptions in sentry
This adds a method to track errors that can be recovered from in
sentry.
It is useful when debugging performance issues, or exceptions that are
hard to reproduce.
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/diff/highlight_spec.rb | 9 | ||||
-rw-r--r-- | spec/lib/gitlab/sentry_spec.rb | 44 |
2 files changed, 47 insertions, 6 deletions
diff --git a/spec/lib/gitlab/diff/highlight_spec.rb b/spec/lib/gitlab/diff/highlight_spec.rb index 73d60c021c8..7c9e8c8d04e 100644 --- a/spec/lib/gitlab/diff/highlight_spec.rb +++ b/spec/lib/gitlab/diff/highlight_spec.rb @@ -79,6 +79,8 @@ describe Gitlab::Diff::Highlight do end it 'keeps the original rich line' do + allow(Gitlab::Sentry).to receive(:track_exception) + code = %q{+ raise RuntimeError, "System commands must be given as an array of strings"} expect(subject[5].text).to eq(code) @@ -86,12 +88,9 @@ describe Gitlab::Diff::Highlight do end it 'reports to Sentry if configured' do - allow(Gitlab::Sentry).to receive(:enabled?).and_return(true) - - expect(Gitlab::Sentry).to receive(:context) - expect(Raven).to receive(:capture_exception) + expect(Gitlab::Sentry).to receive(:track_exception).and_call_original - subject + expect { subject }. to raise_exception(RangeError) end end end diff --git a/spec/lib/gitlab/sentry_spec.rb b/spec/lib/gitlab/sentry_spec.rb index 8c211d1c63f..499757da061 100644 --- a/spec/lib/gitlab/sentry_spec.rb +++ b/spec/lib/gitlab/sentry_spec.rb @@ -7,7 +7,49 @@ describe Gitlab::Sentry do described_class.context(nil) - expect(Raven.tags_context[:locale]).to eq(I18n.locale.to_s) + expect(Raven.tags_context[:locale].to_s).to eq(I18n.locale.to_s) + end + end + + describe '.track_exception' do + let(:exception) { RuntimeError.new('boom') } + + before do + allow(described_class).to receive(:enabled?).and_return(true) + end + + it 'raises the exception if it should' do + expect(described_class).to receive(:should_raise?).and_return(true) + expect { described_class.track_exception(exception) } + .to raise_error(RuntimeError) + end + + context 'when exceptions should not be raised' do + before do + allow(described_class).to receive(:should_raise?).and_return(false) + end + + it 'logs the exception with all attributes passed' do + expected_extras = { + some_other_info: 'info', + issue_url: 'http://gitlab.com/gitlab-org/gitlab-ce/issues/1' + } + + expect(Raven).to receive(:capture_exception) + .with(exception, extra: a_hash_including(expected_extras)) + + described_class.track_exception( + exception, + issue_url: 'http://gitlab.com/gitlab-org/gitlab-ce/issues/1', + extra: { some_other_info: 'info' } + ) + end + + it 'sets the context' do + expect(described_class).to receive(:context) + + described_class.track_exception(exception) + end end end end |