Commit f2982a31 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'graphql_logs' into 'master'

Put GraphQL operation name into logs

See merge request gitlab-org/gitlab!41905
parents 601327a1 7498a293
......@@ -107,4 +107,12 @@ class GraphqlController < ApplicationController
render json: error, status: status
end
def append_info_to_payload(payload)
super
# Merging to :metadata will ensure these are logged as top level keys
payload[:metadata] ||= {}
payload[:metadata].merge!(graphql: { operation_name: params[:operationName] })
end
end
......@@ -123,7 +123,7 @@ class SearchController < ApplicationController
super
# Merging to :metadata will ensure these are logged as top level keys
payload[:metadata] || {}
payload[:metadata] ||= {}
payload[:metadata]['meta.search.group_id'] = params[:group_id]
payload[:metadata]['meta.search.project_id'] = params[:project_id]
payload[:metadata]['meta.search.search'] = params[:search]
......
......@@ -147,4 +147,22 @@ RSpec.describe GraphqlController do
end
end
end
describe '#append_info_to_payload' do
let(:graphql_query) { graphql_query_for('project', { 'fullPath' => 'foo' }, %w(id name)) }
let(:log_payload) { {} }
before do
allow(controller).to receive(:append_info_to_payload).and_wrap_original do |method, *|
method.call(log_payload)
end
end
it 'appends metadata for logging' do
post :execute, params: { query: graphql_query, operationName: 'Foo' }
expect(controller).to have_received(:append_info_to_payload)
expect(log_payload.dig(:metadata, :graphql, :operation_name)).to eq('Foo')
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