Commit deee5630 authored by Terri Chu's avatar Terri Chu

Merge branch 'fix-api-client-id-logging-on-error' into 'master'

Fix API client_id logging on error

See merge request gitlab-org/gitlab!73264
parents 5c9fefb0 cb171149
...@@ -488,7 +488,7 @@ module API ...@@ -488,7 +488,7 @@ module API
def handle_api_exception(exception) def handle_api_exception(exception)
if report_exception?(exception) if report_exception?(exception)
define_params_for_grape_middleware define_params_for_grape_middleware
Gitlab::ApplicationContext.push(user: current_user) Gitlab::ApplicationContext.push(user: current_user, remote_ip: request.ip)
Gitlab::ErrorTracking.track_exception(exception) Gitlab::ErrorTracking.track_exception(exception)
end end
......
...@@ -200,6 +200,28 @@ RSpec.describe API::API do ...@@ -200,6 +200,28 @@ RSpec.describe API::API do
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
context 'when there is an unhandled exception for an anonymous request' do
it 'logs all application context fields and the route' do
expect(described_class::LOG_FORMATTER).to receive(:call) do |_severity, _datetime, _, data|
expect(data.stringify_keys)
.to include('correlation_id' => an_instance_of(String),
'meta.caller_id' => 'GET /api/:version/broadcast_messages',
'meta.remote_ip' => an_instance_of(String),
'meta.client_id' => a_string_matching(%r{\Aip/.+}),
'meta.feature_category' => 'navigation',
'route' => '/api/:version/broadcast_messages')
expect(data.stringify_keys).not_to include('meta.project', 'meta.root_namespace', 'meta.user')
end
expect(BroadcastMessage).to receive(:all).and_raise('An error!')
get(api('/broadcast_messages'))
expect(response).to have_gitlab_http_status(:internal_server_error)
end
end
end end
describe 'Marginalia comments' do describe 'Marginalia comments' 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