diff --git a/instrumentation/graphql/lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb b/instrumentation/graphql/lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb index 9bbb50c8f..45d9c7b5d 100644 --- a/instrumentation/graphql/lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb +++ b/instrumentation/graphql/lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb @@ -89,44 +89,44 @@ def attributes_for(key, data) case key when 'execute_field' field_attr_cache = data[:query].context.namespace(:otel_attrs)[:execute_field_attrs] ||= attr_cache do |field| - { - 'graphql.field.parent' => field.owner.graphql_name || "", # nil values are not permitted - 'graphql.field.name' => (field.graphql_name if field.graphql_name), - 'graphql.lazy' => false - }.freeze + attrs = {} + attrs['graphql.field.parent'] = field.owner.graphql_name if field.owner.graphql_name + attrs['graphql.field.name'] = field.graphql_name if field.graphql_name + attrs['graphql.lazy'] = false + attrs.freeze end field_attr_cache[data[:field]] when 'execute_field_lazy' lazy_field_attr_cache = data[:query].context.namespace(:otel_attrs)[:execute_field_lazy_attrs] ||= attr_cache do |field| - { - 'graphql.field.parent' => (field.owner.graphql_name if field.owner.graphql_name), - 'graphql.field.name' => (field.graphql_name if field.graphql_name), - 'graphql.lazy' => true - }.freeze + attrs = {} + attrs['graphql.field.parent'] = field.owner.graphql_name if field.owner.graphql_name + attrs['graphql.field.name'] = field.graphql_name if field.graphql_name + attrs['graphql.lazy'] = true + attrs.freeze end lazy_field_attr_cache[data[:field]] when 'authorized', 'resolve_type' type_attrs_cache = data[:context].namespace(:otel_attrs)[:type_attrs] ||= attr_cache do |type| - { - 'graphql.type.name' => (type.graphql_name if type.graphql_name), - 'graphql.lazy' => false - }.freeze + attrs = {} + attrs['graphql.type.name'] = type.graphql_name if type.graphql_name + attrs['graphql.lazy'] = false + attrs.freeze end type_attrs_cache[data[:type]] when 'authorized_lazy', 'resolve_type_lazy' type_lazy_attrs_cache = data[:context].namespace(:otel_attrs)[:type_lazy_attrs] ||= attr_cache do |type| - { - 'graphql.type.name' => (type.graphql_name if type.graphql_name), - 'graphql.lazy' => true - }.freeze + attrs = {} + attrs['graphql.type.name'] = type.graphql_name if type.graphql_name + attrs['graphql.lazy'] = true + attrs.freeze end type_lazy_attrs_cache[data[:type]] when 'execute_query' - { - 'graphql.document' => (data[:query].query_string if data[:query].query_string), - 'graphql.operation.type' => (data[:query].selected_operation.operation_type if data[:query].selected_operation && data[:query].selected_operation.operation_type), - 'graphql.operation.name' => data[:query].selected_operation_name || "", # nil values are not permitted - }.freeze + attrs = {} + attrs['graphql.document'] = data[:query].query_string if data[:query].query_string + attrs['graphql.operation.type'] = data[:query].selected_operation.operation_type if data[:query].selected_operation && data[:query].selected_operation.operation_type + attrs['graphql.operation.name'] = data[:query].selected_operation_name || "anonymous" + attrs.freeze else {} end