From 70027f534256e06ccb7ec5a9a3c55885cb109bac Mon Sep 17 00:00:00 2001 From: Robert Mosolgo Date: Tue, 30 Jul 2024 12:57:57 -0400 Subject: [PATCH] Write a failing test --- .../graphql/tracers/graphql_trace_test.rb | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_trace_test.rb b/instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_trace_test.rb index 8e17194b6e..4fb0e9d85a 100644 --- a/instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_trace_test.rb +++ b/instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_trace_test.rb @@ -375,14 +375,26 @@ def execute_query(query:) end it 'works with other trace modules' do - custom_trace_schema = Class.new(SomeGraphQLAppSchema) - custom_trace_schema.trace_with(CustomTrace) + [GraphQL::Schema, SomeOtherGraphQLAppSchema, SomeGraphQLAppSchema].each(&:_reset_tracer_for_testing) + instrumentation.instance_variable_set(:@installed, false) + + custom_trace_schema = Class.new(GraphQL::Schema) do + query(Class.new(GraphQL::Schema::Object) do + graphql_name 'Query' + field :int, Integer, fallback_value: 5 + end) + + trace_with(CustomTrace) + end + instrumentation.install({ schemas: [custom_trace_schema] }) - res = custom_trace_schema.execute('{ vehicle { __typename } }') + res = custom_trace_schema.execute('{ int }') + assert_equal 5, res['data']['int'], 'The query ran successfully' + + assert res.context[:custom_trace_execute_query_ran], 'The custom execute_query hook ran' + assert res.query.multiplex.context[:custom_trace_execute_multiplex_ran], 'The custom execute_multiplex hook ran' - assert_equal 'Car', res['data']['vehicle']['__typename'] - assert res.context[:custom_trace_execute_query_ran] - assert res.query.multiplex.context[:custom_trace_execute_multiplex_ran] + assert spans.find { |s| s.name == 'graphql.execute_query' }, 'OpenTelementry ran' end end end