Skip to content

Commit 0e258c5

Browse files
committed
fix: does not trace resolve type unless enable
Currently, a span with "empty" name is generated
1 parent 44337aa commit 0e258c5

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

instrumentation/graphql/lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,16 @@ def authorized_lazy(query:, type:, object:, &)
148148

149149
def resolve_type(query:, type:, object:, &)
150150
platform_key = @_otel_resolve_type_key_cache[type]
151+
return super unless platform_key
152+
151153
attributes = @_otel_type_attrs_cache[type]
152154
tracer.in_span(platform_key, attributes: attributes) { super }
153155
end
154156

155157
def resolve_type_lazy(query:, type:, object:, &)
156158
platform_key = @_otel_resolve_type_key_cache[type]
159+
return super unless platform_key
160+
157161
attributes = @_otel_lazy_type_attrs_cache[type]
158162
tracer.in_span(platform_key, attributes: attributes) { super }
159163
end

instrumentation/graphql/test/instrumentation/graphql/tracers/graphql_trace_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,29 @@
221221
end
222222
end
223223

224+
describe 'when platform_resolve_type is disabled' do
225+
let(:config) { { enable_platform_resolve_type: false } }
226+
227+
it 'does not trace .resolve_type' do
228+
skip unless supports_authorized_and_resolved_types?
229+
SomeGraphQLAppSchema.execute('{ vehicle { __typename } }')
230+
231+
parent = spans.find { |s| s.name == 'graphql.execute_query' }
232+
span = spans.find { |s| s.parent_span_id == parent.span_id }
233+
_(span).must_be_nil
234+
end
235+
236+
237+
it 'does not traces .resolve_type_lazy' do
238+
skip unless supports_authorized_and_resolved_types?
239+
SomeGraphQLAppSchema.execute('{ vehicle { __typename } }', context: { lazy_type_resolve: true })
240+
241+
parent = spans.find { |s| s.name == 'graphql.execute_query_lazy' }
242+
span = spans.find { |s| s.parent_span_id == parent.span_id }
243+
_(span).must_be_nil
244+
end
245+
end
246+
224247
describe 'when platform_resolve_type is enabled with legacy naming' do
225248
let(:config) { { enable_platform_resolve_type: true, legacy_platform_span_names: true } }
226249

0 commit comments

Comments
 (0)