Commit 770fd9e1 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'json-extra-raw-response' into 'master'

Serialize json.extra.raw_response to avoid field explosion in logs

See merge request gitlab-org/gitlab!32859
parents 5bb8a4b5 181354e0
...@@ -43,7 +43,7 @@ module Gitlab ...@@ -43,7 +43,7 @@ module Gitlab
def store_pull_request_error(pull_request, ex) def store_pull_request_error(pull_request, ex)
backtrace = Gitlab::BacktraceCleaner.clean_backtrace(ex.backtrace) backtrace = Gitlab::BacktraceCleaner.clean_backtrace(ex.backtrace)
error = { type: :pull_request, iid: pull_request.iid, errors: ex.message, trace: backtrace, raw_response: pull_request.raw } error = { type: :pull_request, iid: pull_request.iid, errors: ex.message, trace: backtrace, raw_response: pull_request.raw&.to_json }
Gitlab::ErrorTracking.log_exception(ex, error) Gitlab::ErrorTracking.log_exception(ex, error)
......
...@@ -190,11 +190,14 @@ describe Gitlab::BitbucketImport::Importer do ...@@ -190,11 +190,14 @@ describe Gitlab::BitbucketImport::Importer do
context 'when importing a pull request throws an exception' do context 'when importing a pull request throws an exception' do
before do before do
allow(pull_request).to receive(:raw).and_return('hello world') allow(pull_request).to receive(:raw).and_return({ error: "broken" })
allow(subject.client).to receive(:pull_request_comments).and_raise(Gitlab::HTTP::Error) allow(subject.client).to receive(:pull_request_comments).and_raise(Gitlab::HTTP::Error)
end end
it 'logs an error without the backtrace' do it 'logs an error without the backtrace' do
expect(Gitlab::ErrorTracking).to receive(:log_exception)
.with(instance_of(Gitlab::HTTP::Error), hash_including(raw_response: '{"error":"broken"}'))
subject.execute subject.execute
expect(subject.errors.count).to eq(1) expect(subject.errors.count).to eq(1)
......
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