2017-07-20 02:53:57 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Sentry do
|
|
|
|
describe '.context' do
|
2019-05-10 17:12:33 -04:00
|
|
|
it 'adds the expected tags' do
|
2017-07-20 02:53:57 -04:00
|
|
|
expect(described_class).to receive(:enabled?).and_return(true)
|
2019-05-10 17:12:33 -04:00
|
|
|
allow(Labkit::Correlation::CorrelationId).to receive(:current_id).and_return('cid')
|
2017-07-20 02:53:57 -04:00
|
|
|
|
|
|
|
described_class.context(nil)
|
|
|
|
|
2018-04-13 12:32:54 -04:00
|
|
|
expect(Raven.tags_context[:locale].to_s).to eq(I18n.locale.to_s)
|
2019-05-10 17:12:33 -04:00
|
|
|
expect(Raven.tags_context[Labkit::Correlation::CorrelationId::LOG_KEY.to_sym].to_s)
|
|
|
|
.to eq('cid')
|
2018-04-13 12:32:54 -04:00
|
|
|
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
|
2018-12-05 15:54:40 -05:00
|
|
|
expect(described_class).to receive(:should_raise_for_dev?).and_return(true)
|
2018-04-13 12:32:54 -04:00
|
|
|
expect { described_class.track_exception(exception) }
|
|
|
|
.to raise_error(RuntimeError)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when exceptions should not be raised' do
|
|
|
|
before do
|
2018-12-05 15:54:40 -05:00
|
|
|
allow(described_class).to receive(:should_raise_for_dev?).and_return(false)
|
2019-02-18 15:57:22 -05:00
|
|
|
allow(Labkit::Correlation::CorrelationId).to receive(:current_id).and_return('cid')
|
2018-04-13 12:32:54 -04:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
|
2018-12-05 15:54:40 -05:00
|
|
|
expected_tags = {
|
|
|
|
correlation_id: 'cid'
|
|
|
|
}
|
|
|
|
|
2018-04-13 12:32:54 -04:00
|
|
|
expect(Raven).to receive(:capture_exception)
|
2018-12-05 15:54:40 -05:00
|
|
|
.with(exception,
|
|
|
|
tags: a_hash_including(expected_tags),
|
|
|
|
extra: a_hash_including(expected_extras))
|
2018-04-13 12:32:54 -04:00
|
|
|
|
|
|
|
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
|
2017-07-20 02:53:57 -04:00
|
|
|
end
|
|
|
|
end
|
2018-11-14 06:10:36 -05:00
|
|
|
|
|
|
|
context '.track_acceptable_exception' do
|
|
|
|
let(:exception) { RuntimeError.new('boom') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:enabled?).and_return(true)
|
2019-02-18 15:57:22 -05:00
|
|
|
allow(Labkit::Correlation::CorrelationId).to receive(:current_id).and_return('cid')
|
2018-11-14 06:10:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls Raven.capture_exception' do
|
|
|
|
expected_extras = {
|
|
|
|
some_other_info: 'info',
|
|
|
|
issue_url: 'http://gitlab.com/gitlab-org/gitlab-ce/issues/1'
|
|
|
|
}
|
|
|
|
|
2018-12-05 15:54:40 -05:00
|
|
|
expected_tags = {
|
|
|
|
correlation_id: 'cid'
|
|
|
|
}
|
|
|
|
|
2018-11-14 06:10:36 -05:00
|
|
|
expect(Raven).to receive(:capture_exception)
|
2018-12-05 15:54:40 -05:00
|
|
|
.with(exception,
|
|
|
|
tags: a_hash_including(expected_tags),
|
|
|
|
extra: a_hash_including(expected_extras))
|
2018-11-14 06:10:36 -05:00
|
|
|
|
|
|
|
described_class.track_acceptable_exception(
|
|
|
|
exception,
|
|
|
|
issue_url: 'http://gitlab.com/gitlab-org/gitlab-ce/issues/1',
|
|
|
|
extra: { some_other_info: 'info' }
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2017-07-20 02:53:57 -04:00
|
|
|
end
|