Commit b9590f39 authored by Mehmet Emin INAC's avatar Mehmet Emin INAC

Send SQL queries to Sentry for ActiveRecord::StatementInvalid errors

parent 0043e4dc
...@@ -123,6 +123,7 @@ module Gitlab ...@@ -123,6 +123,7 @@ module Gitlab
end end
extra = sanitize_request_parameters(extra) extra = sanitize_request_parameters(extra)
inject_sql_query_into_extra(exception, extra)
if sentry && Raven.configuration.server if sentry && Raven.configuration.server
Raven.capture_exception(exception, tags: default_tags, extra: extra) Raven.capture_exception(exception, tags: default_tags, extra: extra)
...@@ -149,6 +150,12 @@ module Gitlab ...@@ -149,6 +150,12 @@ module Gitlab
filter.filter(parameters) filter.filter(parameters)
end end
def inject_sql_query_into_extra(exception, extra)
return unless exception.is_a?(ActiveRecord::StatementInvalid)
extra[:sql] = exception.sql
end
def sentry_dsn def sentry_dsn
return unless Rails.env.production? || Rails.env.development? return unless Rails.env.production? || Rails.env.development?
return unless Gitlab.config.sentry.enabled return unless Gitlab.config.sentry.enabled
......
...@@ -287,5 +287,20 @@ RSpec.describe Gitlab::ErrorTracking do ...@@ -287,5 +287,20 @@ RSpec.describe Gitlab::ErrorTracking do
expect(sentry_event.dig('extra', 'sidekiq', 'args')).to eq(['[FILTERED]', 1, 2]) expect(sentry_event.dig('extra', 'sidekiq', 'args')).to eq(['[FILTERED]', 1, 2])
end end
end end
context 'when the error is kind of an `ActiveRecord::StatementInvalid`' do
let(:exception) { ActiveRecord::StatementInvalid.new(sql: :foo) }
before do
allow(Raven).to receive(:capture_exception)
end
it 'injects the sql query into extra' do
described_class.track_exception(exception)
expect(Raven).to have_received(:capture_exception)
.with(exception, a_hash_including(extra: a_hash_including(sql: :foo)))
end
end
end end
end end
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