Skip to content

Commit

Permalink
fix: Add graphql variables to the trace results
Browse files Browse the repository at this point in the history
* fix: Add graphql variables to the trace results

* fix: add tests
  • Loading branch information
jdehaan committed Feb 5, 2024
1 parent 02deb7c commit f26eeb1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def execute_query(query:, &block)
attributes['graphql.operation.name'] = query.selected_operation_name if query.selected_operation_name
attributes['graphql.operation.type'] = query.selected_operation.operation_type
attributes['graphql.document'] = query.query_string
attributes['graphql.variables'] = query.variables.to_h.to_json if query.variables.length.positive?

tracer.in_span('graphql.execute_query', attributes: attributes, &block)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ def attributes_for(key, data)
attributes['graphql.type.name'] = data[:type]&.graphql_name
attributes['graphql.lazy'] = key == 'resolve_type_lazy'
when 'execute_query'
attributes['graphql.operation.name'] = data[:query].selected_operation_name if data[:query].selected_operation_name
attributes['graphql.operation.type'] = data[:query].selected_operation.operation_type
attributes['graphql.document'] = data[:query].query_string
query = data[:query]
attributes['graphql.operation.name'] = query.selected_operation_name if query.selected_operation_name
attributes['graphql.operation.type'] = query.selected_operation.operation_type
attributes['graphql.document'] = query.query_string
attributes['graphql.variables'] = query.variables.to_h.to_json if query.variables.length.positive?
end
attributes
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
_(result.to_h['data']).must_equal(expected_result)
end

it 'graphql.execute_query holds the variable contents' do
SomeGraphQLAppSchema.execute(query_string, variables: { id: 1 })

span = spans.find { |s| s.name == 'graphql.execute_query' }
_(span).wont_be_nil
_(span.attributes['graphql.variables']).must_equal('{"id":1}')
end

it 'includes operation attributes for execute_query' do
expected_attributes = {
'graphql.operation.name' => 'SimpleQuery',
Expand Down

0 comments on commit f26eeb1

Please sign in to comment.