From 0e258c524074e2389727deb7320b5300f81a94be Mon Sep 17 00:00:00 2001 From: Duc Nghiem-Xuan Date: Fri, 24 Oct 2025 13:41:56 +0900 Subject: [PATCH 1/2] fix: does not trace resolve type unless enable Currently, a span with "empty" name is generated --- .../graphql/tracers/graphql_trace.rb | 4 ++++ .../graphql/tracers/graphql_trace_test.rb | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/instrumentation/graphql/lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb b/instrumentation/graphql/lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb index 7ba3356b1c..f366879261 100644 --- a/instrumentation/graphql/lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb +++ b/instrumentation/graphql/lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb @@ -148,12 +148,16 @@ def authorized_lazy(query:, type:, object:, &) def resolve_type(query:, type:, object:, &) platform_key = @_otel_resolve_type_key_cache[type] + return super unless platform_key + attributes = @_otel_type_attrs_cache[type] tracer.in_span(platform_key, attributes: attributes) { super } end def resolve_type_lazy(query:, type:, object:, &) platform_key = @_otel_resolve_type_key_cache[type] + return super unless platform_key + attributes = @_otel_lazy_type_attrs_cache[type] tracer.in_span(platform_key, attributes: attributes) { super } end 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 7e031854d6..a0cfc37a24 100644 --- a/instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_trace_test.rb +++ b/instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_trace_test.rb @@ -221,6 +221,29 @@ end end + describe 'when platform_resolve_type is disabled' do + let(:config) { { enable_platform_resolve_type: false } } + + it 'does not trace .resolve_type' do + skip unless supports_authorized_and_resolved_types? + SomeGraphQLAppSchema.execute('{ vehicle { __typename } }') + + parent = spans.find { |s| s.name == 'graphql.execute_query' } + span = spans.find { |s| s.parent_span_id == parent.span_id } + _(span).must_be_nil + end + + + it 'does not traces .resolve_type_lazy' do + skip unless supports_authorized_and_resolved_types? + SomeGraphQLAppSchema.execute('{ vehicle { __typename } }', context: { lazy_type_resolve: true }) + + parent = spans.find { |s| s.name == 'graphql.execute_query_lazy' } + span = spans.find { |s| s.parent_span_id == parent.span_id } + _(span).must_be_nil + end + end + describe 'when platform_resolve_type is enabled with legacy naming' do let(:config) { { enable_platform_resolve_type: true, legacy_platform_span_names: true } } From e3763d2e425360a38546ea870d93da88801b38bc Mon Sep 17 00:00:00 2001 From: Duc Nghiem-Xuan Date: Sat, 25 Oct 2025 07:45:23 +0900 Subject: [PATCH 2/2] chore: address robocop check --- .../test/instrumentation/graphql/tracers/graphql_trace_test.rb | 1 - 1 file changed, 1 deletion(-) 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 a0cfc37a24..651bcf3e60 100644 --- a/instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_trace_test.rb +++ b/instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_trace_test.rb @@ -233,7 +233,6 @@ _(span).must_be_nil end - it 'does not traces .resolve_type_lazy' do skip unless supports_authorized_and_resolved_types? SomeGraphQLAppSchema.execute('{ vehicle { __typename } }', context: { lazy_type_resolve: true })