Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/error_tracking_spec.rb')
-rw-r--r--spec/lib/gitlab/error_tracking_spec.rb86
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