diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/lib/gitlab/error_tracking_spec.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/lib/gitlab/error_tracking_spec.rb')
-rw-r--r-- | spec/lib/gitlab/error_tracking_spec.rb | 86 |
1 files changed, 83 insertions, 3 deletions
diff --git a/spec/lib/gitlab/error_tracking_spec.rb b/spec/lib/gitlab/error_tracking_spec.rb index c40369f5965..2cc9ff36c99 100644 --- a/spec/lib/gitlab/error_tracking_spec.rb +++ b/spec/lib/gitlab/error_tracking_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' require 'raven/transports/dummy' -describe Gitlab::ErrorTracking do +RSpec.describe Gitlab::ErrorTracking do let(:exception) { RuntimeError.new('boom') } let(:issue_url) { 'http://gitlab.com/gitlab-org/gitlab-foss/issues/1' } @@ -18,6 +18,8 @@ describe Gitlab::ErrorTracking do ] end + let(:sentry_event) { Gitlab::Json.parse(Raven.client.transport.events.last[1]) } + before do stub_sentry_settings @@ -29,6 +31,86 @@ describe Gitlab::ErrorTracking do end end + describe '.configure' do + context 'default tags from GITLAB_SENTRY_EXTRA_TAGS' do + context 'when the value is a JSON hash' do + it 'includes those tags in all events' do + stub_env('GITLAB_SENTRY_EXTRA_TAGS', { foo: 'bar', baz: 'quux' }.to_json) + + described_class.configure do |config| + config.encoding = 'json' + end + + described_class.track_exception(StandardError.new) + + expect(sentry_event['tags'].except('correlation_id', 'locale', 'program')) + .to eq('foo' => 'bar', 'baz' => 'quux') + end + end + + context 'when the value is not set' do + before do + stub_env('GITLAB_SENTRY_EXTRA_TAGS', nil) + end + + it 'does not log an error' do + expect(Gitlab::AppLogger).not_to receive(:debug) + + described_class.configure do |config| + config.encoding = 'json' + end + end + + it 'does not send any extra tags' do + described_class.configure do |config| + config.encoding = 'json' + end + + described_class.track_exception(StandardError.new) + + expect(sentry_event['tags'].keys).to contain_exactly('correlation_id', 'locale', 'program') + end + end + + context 'when the value is not a JSON hash' do + using RSpec::Parameterized::TableSyntax + + where(:env_var, :error) do + { foo: 'bar', baz: 'quux' }.inspect | 'JSON::ParserError' + [].to_json | 'NoMethodError' + [%w[foo bar]].to_json | 'NoMethodError' + %w[foo bar].to_json | 'NoMethodError' + '"string"' | 'NoMethodError' + end + + with_them do + before do + stub_env('GITLAB_SENTRY_EXTRA_TAGS', env_var) + end + + it 'does not include any extra tags' do + described_class.configure do |config| + config.encoding = 'json' + end + + described_class.track_exception(StandardError.new) + + expect(sentry_event['tags'].except('correlation_id', 'locale', 'program')) + .to be_empty + end + + it 'logs the error class' do + expect(Gitlab::AppLogger).to receive(:debug).with(a_string_matching(error)) + + described_class.configure do |config| + config.encoding = 'json' + end + end + end + end + end + end + describe '.with_context' do it 'adds the expected tags' do described_class.with_context {} @@ -202,8 +284,6 @@ describe Gitlab::ErrorTracking do described_class.track_exception(exception, extra) - sentry_event = Gitlab::Json.parse(Raven.client.transport.events.last[1]) - expect(sentry_event.dig('extra', 'sidekiq', 'args')).to eq(['[FILTERED]', 1, 2]) end end |