Commit 89a56d76 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'improve-graphql-error-logging' into 'master'

Add exception details to GraphQL request logs

See merge request gitlab-org/gitlab!76547
parents dc1b3423 7b9f2754
...@@ -50,6 +50,8 @@ class GraphqlController < ApplicationController ...@@ -50,6 +50,8 @@ class GraphqlController < ApplicationController
end end
rescue_from StandardError do |exception| rescue_from StandardError do |exception|
@exception_object = exception
log_exception(exception) log_exception(exception)
if Rails.env.test? || Rails.env.development? if Rails.env.test? || Rails.env.development?
...@@ -197,7 +199,9 @@ class GraphqlController < ApplicationController ...@@ -197,7 +199,9 @@ class GraphqlController < ApplicationController
# Merging to :metadata will ensure these are logged as top level keys # Merging to :metadata will ensure these are logged as top level keys
payload[:metadata] ||= {} payload[:metadata] ||= {}
payload[:metadata].merge!(graphql: logs) payload[:metadata][:graphql] = logs
payload[:exception_object] = @exception_object if @exception_object
end end
def logs def logs
......
...@@ -262,5 +262,16 @@ RSpec.describe GraphqlController do ...@@ -262,5 +262,16 @@ RSpec.describe GraphqlController do
expect(controller).to have_received(:append_info_to_payload) expect(controller).to have_received(:append_info_to_payload)
expect(log_payload.dig(:metadata, :graphql)).to match_array(expected_logs) expect(log_payload.dig(:metadata, :graphql)).to match_array(expected_logs)
end end
it 'appends the exception in case of errors' do
exception = StandardError.new('boom')
expect(controller).to receive(:execute).and_raise(exception)
post :execute, params: { _json: graphql_queries }
expect(controller).to have_received(:append_info_to_payload)
expect(log_payload.dig(:exception_object)).to eq(exception)
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