Commit 3520563f authored by Quang-Minh Nguyen's avatar Quang-Minh Nguyen

Fix incompatibilities after gem upgrade

Issue https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/849
parent fa3e6a81
# frozen_string_literal: true # frozen_string_literal: true
require 'fast_spec_helper' require 'spec_helper'
require 'rspec-parameterized' require 'rspec-parameterized'
RSpec.describe Gitlab::ErrorTracking::ContextPayloadGenerator do RSpec.describe Gitlab::ErrorTracking::ContextPayloadGenerator do
......
...@@ -27,9 +27,9 @@ RSpec.describe Gitlab::ErrorTracking::LogFormatter do ...@@ -27,9 +27,9 @@ RSpec.describe Gitlab::ErrorTracking::LogFormatter do
end end
before do before do
Raven.context.user[:user_flag] = 'flag' Sentry.set_user(user_flag: 'flag')
Raven.context.tags[:shard] = 'catchall' Sentry.set_tags(shard: 'catchall')
Raven.context.extra[:some_info] = 'info' Sentry.set_extras(some_info: 'info')
allow(exception).to receive(:backtrace).and_return( allow(exception).to receive(:backtrace).and_return(
[ [
...@@ -40,7 +40,7 @@ RSpec.describe Gitlab::ErrorTracking::LogFormatter do ...@@ -40,7 +40,7 @@ RSpec.describe Gitlab::ErrorTracking::LogFormatter do
end end
after do after do
::Raven::Context.clear! ::Sentry.get_current_scope.clear
end end
it 'appends error-related log fields and filters sensitive Sidekiq arguments' do it 'appends error-related log fields and filters sensitive Sidekiq arguments' do
......
...@@ -4,18 +4,14 @@ require 'spec_helper' ...@@ -4,18 +4,14 @@ require 'spec_helper'
RSpec.describe Gitlab::ErrorTracking::Processor::ContextPayloadProcessor do RSpec.describe Gitlab::ErrorTracking::Processor::ContextPayloadProcessor do
describe '.call' do describe '.call' do
let(:required_options) do let(:exception) { StandardError.new('Test exception') }
{ let(:event) { Sentry.get_current_client.event_from_exception(exception) }
configuration: Raven.configuration,
context: Raven.context,
breadcrumbs: Raven.breadcrumbs
}
end
let(:event) { Raven::Event.new(required_options.merge(payload)) }
let(:result_hash) { described_class.call(event).to_hash } let(:result_hash) { described_class.call(event).to_hash }
before do before do
Sentry.get_current_scope.update_from_options(**payload)
Sentry.get_current_scope.apply_to_event(event)
allow_next_instance_of(Gitlab::ErrorTracking::ContextPayloadGenerator) do |generator| allow_next_instance_of(Gitlab::ErrorTracking::ContextPayloadGenerator) do |generator|
allow(generator).to receive(:generate).and_return( allow(generator).to receive(:generate).and_return(
user: { username: 'root' }, user: { username: 'root' },
...@@ -25,6 +21,10 @@ RSpec.describe Gitlab::ErrorTracking::Processor::ContextPayloadProcessor do ...@@ -25,6 +21,10 @@ RSpec.describe Gitlab::ErrorTracking::Processor::ContextPayloadProcessor do
end end
end end
after do
Sentry.get_current_scope.clear
end
let(:payload) do let(:payload) do
{ {
user: { ip_address: '127.0.0.1' }, user: { ip_address: '127.0.0.1' },
......
...@@ -4,16 +4,17 @@ require 'spec_helper' ...@@ -4,16 +4,17 @@ require 'spec_helper'
RSpec.describe Gitlab::ErrorTracking::Processor::GrpcErrorProcessor do RSpec.describe Gitlab::ErrorTracking::Processor::GrpcErrorProcessor do
describe '.call' do describe '.call' do
let(:required_options) do let(:event) { Sentry.get_current_client.event_from_exception(exception) }
{ let(:result_hash) { described_class.call(event).to_hash }
configuration: Raven.configuration,
context: Raven.context, before do
breadcrumbs: Raven.breadcrumbs Sentry.get_current_scope.update_from_options(**data)
} Sentry.get_current_scope.apply_to_event(event)
end end
let(:event) { Raven::Event.from_exception(exception, required_options.merge(data)) } after do
let(:result_hash) { described_class.call(event).to_hash } Sentry.get_current_scope.clear
end
context 'when there is no GRPC exception' do context 'when there is no GRPC exception' do
let(:exception) { RuntimeError.new } let(:exception) { RuntimeError.new }
...@@ -56,7 +57,7 @@ RSpec.describe Gitlab::ErrorTracking::Processor::GrpcErrorProcessor do ...@@ -56,7 +57,7 @@ RSpec.describe Gitlab::ErrorTracking::Processor::GrpcErrorProcessor do
end end
it 'removes the debug error string and stores it as an extra field' do it 'removes the debug error string and stores it as an extra field' do
expect(result_hash).not_to include(:fingerprint) expect(result_hash[:fingerprint]).to be_empty
expect(result_hash[:exception][:values].first) expect(result_hash[:exception][:values].first)
.to include(type: 'GRPC::DeadlineExceeded', value: '4:Deadline Exceeded.') .to include(type: 'GRPC::DeadlineExceeded', value: '4:Deadline Exceeded.')
......
...@@ -95,16 +95,18 @@ RSpec.describe Gitlab::ErrorTracking::Processor::SidekiqProcessor do ...@@ -95,16 +95,18 @@ RSpec.describe Gitlab::ErrorTracking::Processor::SidekiqProcessor do
end end
describe '.call' do describe '.call' do
let(:required_options) do let(:exception) { StandardError.new('Test exception') }
{ let(:event) { Sentry.get_current_client.event_from_exception(exception) }
configuration: Raven.configuration, let(:result_hash) { described_class.call(event).to_hash }
context: Raven.context,
breadcrumbs: Raven.breadcrumbs before do
} Sentry.get_current_scope.update_from_options(**wrapped_value)
Sentry.get_current_scope.apply_to_event(event)
end end
let(:event) { Raven::Event.new(required_options.merge(wrapped_value)) } after do
let(:result_hash) { described_class.call(event).to_hash } Sentry.get_current_scope.clear
end
context 'when there is Sidekiq data' do context 'when there is Sidekiq data' do
let(:wrapped_value) { { extra: { sidekiq: value } } } let(:wrapped_value) { { extra: { sidekiq: value } } }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
require 'raven/transports/dummy' require 'sentry/transport/dummy_transport'
RSpec.describe Gitlab::ErrorTracking do RSpec.describe Gitlab::ErrorTracking do
let(:exception) { RuntimeError.new('boom') } let(:exception) { RuntimeError.new('boom') }
...@@ -43,7 +43,7 @@ RSpec.describe Gitlab::ErrorTracking do ...@@ -43,7 +43,7 @@ RSpec.describe Gitlab::ErrorTracking do
} }
end end
let(:sentry_event) { Gitlab::Json.parse(Raven.client.transport.events.last[1]) } let(:sentry_event) { Sentry.get_current_client.transport.events.last }
before do before do
stub_sentry_settings stub_sentry_settings
...@@ -53,7 +53,7 @@ RSpec.describe Gitlab::ErrorTracking do ...@@ -53,7 +53,7 @@ RSpec.describe Gitlab::ErrorTracking do
allow(I18n).to receive(:locale).and_return('en') allow(I18n).to receive(:locale).and_return('en')
described_class.configure do |config| described_class.configure do |config|
config.encoding = 'json' config.transport.transport_class = Sentry::DummyTransport
end end
end end
...@@ -63,6 +63,10 @@ RSpec.describe Gitlab::ErrorTracking do ...@@ -63,6 +63,10 @@ RSpec.describe Gitlab::ErrorTracking do
end end
end end
after do
::Sentry.get_current_scope.clear
end
describe '.track_and_raise_for_dev_exception' do describe '.track_and_raise_for_dev_exception' do
context 'when exceptions for dev should be raised' do context 'when exceptions for dev should be raised' do
before do before do
...@@ -70,7 +74,7 @@ RSpec.describe Gitlab::ErrorTracking do ...@@ -70,7 +74,7 @@ RSpec.describe Gitlab::ErrorTracking do
end end
it 'raises the exception' do it 'raises the exception' do
expect(Raven).to receive(:capture_exception).with(exception, sentry_payload) expect(Sentry).to receive(:capture_exception).with(exception, sentry_payload)
expect do expect do
described_class.track_and_raise_for_dev_exception( described_class.track_and_raise_for_dev_exception(
...@@ -88,7 +92,7 @@ RSpec.describe Gitlab::ErrorTracking do ...@@ -88,7 +92,7 @@ RSpec.describe Gitlab::ErrorTracking do
end end
it 'logs the exception with all attributes passed' do it 'logs the exception with all attributes passed' do
expect(Raven).to receive(:capture_exception).with(exception, sentry_payload) expect(Sentry).to receive(:capture_exception).with(exception, sentry_payload)
described_class.track_and_raise_for_dev_exception( described_class.track_and_raise_for_dev_exception(
exception, exception,
...@@ -111,7 +115,7 @@ RSpec.describe Gitlab::ErrorTracking do ...@@ -111,7 +115,7 @@ RSpec.describe Gitlab::ErrorTracking do
describe '.track_and_raise_exception' do describe '.track_and_raise_exception' do
it 'always raises the exception' do it 'always raises the exception' do
expect(Raven).to receive(:capture_exception).with(exception, sentry_payload) expect(Sentry).to receive(:capture_exception).with(exception, sentry_payload)
expect do expect do
described_class.track_and_raise_for_dev_exception( described_class.track_and_raise_for_dev_exception(
...@@ -139,14 +143,14 @@ RSpec.describe Gitlab::ErrorTracking do ...@@ -139,14 +143,14 @@ RSpec.describe Gitlab::ErrorTracking do
subject(:track_exception) { described_class.track_exception(exception, extra) } subject(:track_exception) { described_class.track_exception(exception, extra) }
before do before do
allow(Raven).to receive(:capture_exception).and_call_original allow(Sentry).to receive(:capture_exception).and_call_original
allow(Gitlab::ErrorTracking::Logger).to receive(:error) allow(Gitlab::ErrorTracking::Logger).to receive(:error)
end end
it 'calls Raven.capture_exception' do it 'calls Sentry.capture_exception' do
track_exception track_exception
expect(Raven).to have_received(:capture_exception).with( expect(Sentry).to have_received(:capture_exception).with(
exception, exception,
sentry_payload sentry_payload
) )
...@@ -172,25 +176,31 @@ RSpec.describe Gitlab::ErrorTracking do ...@@ -172,25 +176,31 @@ RSpec.describe Gitlab::ErrorTracking do
context 'the exception implements :sentry_extra_data' do context 'the exception implements :sentry_extra_data' do
let(:extra_info) { { event: 'explosion', size: :massive } } let(:extra_info) { { event: 'explosion', size: :massive } }
let(:exception) { double(message: 'bang!', sentry_extra_data: extra_info, backtrace: caller, cause: nil) }
before do
allow(exception).to receive(:sentry_extra_data).and_return(extra_info)
end
it 'includes the extra data from the exception in the tracking information' do it 'includes the extra data from the exception in the tracking information' do
track_exception track_exception
expect(Raven).to have_received(:capture_exception).with( expect(Sentry).to have_received(:capture_exception).with(
exception, a_hash_including(extra: a_hash_including(extra_info)) exception, a_hash_including(extra: a_hash_including(extra_info))
) )
end end
end end
context 'the exception implements :sentry_extra_data, which returns nil' do context 'the exception implements :sentry_extra_data, which returns nil' do
let(:exception) { double(message: 'bang!', sentry_extra_data: nil, backtrace: caller, cause: nil) }
let(:extra) { { issue_url: issue_url } } let(:extra) { { issue_url: issue_url } }
before do
allow(exception).to receive(:sentry_extra_data).and_return(nil)
end
it 'just includes the other extra info' do it 'just includes the other extra info' do
track_exception track_exception
expect(Raven).to have_received(:capture_exception).with( expect(Sentry).to have_received(:capture_exception).with(
exception, a_hash_including(extra: a_hash_including(extra)) exception, a_hash_including(extra: a_hash_including(extra))
) )
end end
...@@ -202,7 +212,7 @@ RSpec.describe Gitlab::ErrorTracking do ...@@ -202,7 +212,7 @@ RSpec.describe Gitlab::ErrorTracking do
it 'injects the normalized sql query into extra' do it 'injects the normalized sql query into extra' do
track_exception track_exception
expect(sentry_event.dig('extra', 'sql')).to eq('SELECT "users".* FROM "users" WHERE "users"."id" = $2 AND "users"."foo" = $1') expect(sentry_event.extra[:sql]).to eq('SELECT "users".* FROM "users" WHERE "users"."id" = $2 AND "users"."foo" = $1')
end end
end end
...@@ -212,7 +222,7 @@ RSpec.describe Gitlab::ErrorTracking do ...@@ -212,7 +222,7 @@ RSpec.describe Gitlab::ErrorTracking do
track_exception track_exception
expect(sentry_event.dig('extra', 'sql')).to eq('SELECT "users".* FROM "users" WHERE "users"."id" = $2 AND "users"."foo" = $1') expect(sentry_event.extra[:sql]).to eq('SELECT "users".* FROM "users" WHERE "users"."id" = $2 AND "users"."foo" = $1')
end end
end end
end end
...@@ -221,27 +231,27 @@ RSpec.describe Gitlab::ErrorTracking do ...@@ -221,27 +231,27 @@ RSpec.describe Gitlab::ErrorTracking do
subject(:track_exception) { described_class.track_exception(exception, extra) } subject(:track_exception) { described_class.track_exception(exception, extra) }
before do before do
allow(Raven).to receive(:capture_exception).and_call_original allow(Sentry).to receive(:capture_exception).and_call_original
allow(Gitlab::ErrorTracking::Logger).to receive(:error) allow(Gitlab::ErrorTracking::Logger).to receive(:error)
end end
context 'custom GitLab context when using Raven.capture_exception directly' do context 'custom GitLab context when using Sentry.capture_exception directly' do
subject(:raven_capture_exception) { Raven.capture_exception(exception) } subject(:track_exception) { Sentry.capture_exception(exception) }
it 'merges a default set of tags into the existing tags' do it 'merges a default set of tags into the existing tags' do
allow(Raven.context).to receive(:tags).and_return(foo: 'bar') Sentry.set_tags(foo: 'bar')
raven_capture_exception track_exception
expect(sentry_event['tags']).to include('correlation_id', 'feature_category', 'foo', 'locale', 'program') expect(sentry_event.tags).to include(:correlation_id, :feature_category, :foo, :locale, :program)
end end
it 'merges the current user information into the existing user information' do it 'merges the current user information into the existing user information' do
Raven.user_context(id: -1) Sentry.set_user(id: -1)
raven_capture_exception track_exception
expect(sentry_event['user']).to eq('id' => -1, 'username' => user.username) expect(sentry_event.user).to eq(id: -1, username: user.username)
end end
end end
...@@ -265,7 +275,7 @@ RSpec.describe Gitlab::ErrorTracking do ...@@ -265,7 +275,7 @@ RSpec.describe Gitlab::ErrorTracking do
it 'does not filter parameters when sending to Sentry' do it 'does not filter parameters when sending to Sentry' do
track_exception track_exception
expect(sentry_event.dig('extra', 'sidekiq', 'args')).to eq([1, { 'id' => 2, 'name' => 'hello' }, 'some-value', 'another-value']) expect(sentry_event.extra[:sidekiq]['args']).to eq([1, { 'id' => 2, 'name' => 'hello' }, 'some-value', 'another-value'])
end end
end end
...@@ -275,7 +285,7 @@ RSpec.describe Gitlab::ErrorTracking do ...@@ -275,7 +285,7 @@ RSpec.describe Gitlab::ErrorTracking do
it 'filters sensitive arguments before sending and logging' do it 'filters sensitive arguments before sending and logging' do
track_exception track_exception
expect(sentry_event.dig('extra', 'sidekiq', 'args')).to eq(['[FILTERED]', 1, 2]) expect(sentry_event.extra[:sidekiq]['args']).to eq(['[FILTERED]', 1, 2])
expect(Gitlab::ErrorTracking::Logger).to have_received(:error).with( expect(Gitlab::ErrorTracking::Logger).to have_received(:error).with(
hash_including( hash_including(
'extra.sidekiq' => { 'extra.sidekiq' => {
...@@ -295,8 +305,8 @@ RSpec.describe Gitlab::ErrorTracking do ...@@ -295,8 +305,8 @@ RSpec.describe Gitlab::ErrorTracking do
it 'sets the GRPC debug error string in the Sentry event and adds a custom fingerprint' do it 'sets the GRPC debug error string in the Sentry event and adds a custom fingerprint' do
track_exception track_exception
expect(sentry_event.dig('extra', 'grpc_debug_error_string')).to eq('{"hello":1}') expect(sentry_event.extra[:grpc_debug_error_string]).to eq('{"hello":1}')
expect(sentry_event['fingerprint']).to eq(['GRPC::DeadlineExceeded', '4:unknown cause.']) expect(sentry_event.fingerprint).to eq(['GRPC::DeadlineExceeded', '4:unknown cause.'])
end end
end end
...@@ -306,8 +316,8 @@ RSpec.describe Gitlab::ErrorTracking do ...@@ -306,8 +316,8 @@ RSpec.describe Gitlab::ErrorTracking do
it 'does not do any processing on the event' do it 'does not do any processing on the event' do
track_exception track_exception
expect(sentry_event['extra']).not_to include('grpc_debug_error_string') expect(sentry_event.extra).not_to include(:grpc_debug_error_string)
expect(sentry_event['fingerprint']).to eq(['GRPC::DeadlineExceeded', '4:unknown cause']) expect(sentry_event.fingerprint).to eq(['GRPC::DeadlineExceeded', '4:unknown cause'])
end end
end end
end end
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
require 'raven/transports/dummy' require 'sentry/transport/dummy_transport'
require_relative '../../../config/initializers/sentry' require_relative '../../../config/initializers/sentry'
RSpec.describe API::Helpers do RSpec.describe API::Helpers do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment