Skip to content

Commit f4df012

Browse files
authored
fix: does not trace resolve type unless enable (#1759)
1 parent 0fe8d81 commit f4df012

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,28 @@
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+
it 'does not traces .resolve_type_lazy' do
237+
skip unless supports_authorized_and_resolved_types?
238+
SomeGraphQLAppSchema.execute('{ vehicle { __typename } }', context: { lazy_type_resolve: true })
239+
240+
parent = spans.find { |s| s.name == 'graphql.execute_query_lazy' }
241+
span = spans.find { |s| s.parent_span_id == parent.span_id }
242+
_(span).must_be_nil
243+
end
244+
end
245+
224246
describe 'when platform_resolve_type is enabled with legacy naming' do
225247
let(:config) { { enable_platform_resolve_type: true, legacy_platform_span_names: true } }
226248

0 commit comments

Comments
 (0)