lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb in opentelemetry-instrumentation-graphql-0.26.2 vs lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb in opentelemetry-instrumentation-graphql-0.26.3
- old
+ new
@@ -27,15 +27,18 @@
def platform_trace(platform_key, key, data) # rubocop:disable Metrics/CyclomaticComplexity
return yield if platform_key.nil?
tracer.in_span(platform_key, attributes: attributes_for(key, data)) do |span|
yield.tap do |response|
- errors = response[:errors]&.compact&.map(&:to_h)&.to_json if key == 'validate'
- unless errors.nil?
+ next unless key == 'validate'
+
+ errors = response[:errors]&.compact&.map(&:to_h) || []
+
+ unless errors.empty?
span.add_event(
'graphql.validation.error',
attributes: {
- 'message' => errors
+ 'exception.message' => errors.to_json
}
)
end
end
end