From 352812e023851db1fa20cc9a083a864b75f51189 Mon Sep 17 00:00:00 2001 From: Jimmy Bourassa Date: Sun, 17 Sep 2023 10:34:53 -0400 Subject: [PATCH] Micro optimization: build Hash w/ `{}` (#665) --- .../graphql/tracers/graphql_trace.rb | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) 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 3f470685d..881aa10ec 100644 --- a/instrumentation/graphql/lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb +++ b/instrumentation/graphql/lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb @@ -75,10 +75,11 @@ def execute_field(field:, query:, ast_node:, arguments:, object:, &block) platform_key = _otel_execute_field_key(field: field) return super unless platform_key - attributes = {} - attributes['graphql.field.parent'] = field.owner&.graphql_name - attributes['graphql.field.name'] = field.graphql_name - attributes['graphql.lazy'] = false + attributes = { + 'graphql.field.parent' => field.owner&.graphql_name, + 'graphql.field.name' => field.graphql_name, + 'graphql.lazy' => false + } tracer.in_span(platform_key, attributes: attributes, &block) end @@ -87,10 +88,11 @@ def execute_field_lazy(field:, query:, ast_node:, arguments:, object:, &block) platform_key = _otel_execute_field_key(field: field) return super unless platform_key - attributes = {} - attributes['graphql.field.parent'] = field.owner&.graphql_name - attributes['graphql.field.name'] = field.graphql_name - attributes['graphql.lazy'] = true + attributes = { + 'graphql.field.parent' => field.owner&.graphql_name, + 'graphql.field.name' => field.graphql_name, + 'graphql.lazy' => true + } tracer.in_span(platform_key, attributes: attributes, &block) end @@ -99,9 +101,10 @@ def authorized(query:, type:, object:, &block) platform_key = @_otel_authorized_key_cache[type] return super unless platform_key - attributes = {} - attributes['graphql.type.name'] = type.graphql_name - attributes['graphql.lazy'] = false + attributes = { + 'graphql.type.name' => type.graphql_name, + 'graphql.lazy' => false + } tracer.in_span(platform_key, attributes: attributes, &block) end @@ -110,9 +113,10 @@ def authorized_lazy(query:, type:, object:, &block) platform_key = @_otel_authorized_key_cache[type] return super unless platform_key - attributes = {} - attributes['graphql.type.name'] = type.graphql_name - attributes['graphql.lazy'] = true + attributes = { + 'graphql.type.name' => type.graphql_name, + 'graphql.lazy' => true + } tracer.in_span(platform_key, attributes: attributes, &block) end @@ -120,9 +124,10 @@ def authorized_lazy(query:, type:, object:, &block) def resolve_type(query:, type:, object:, &block) platform_key = @_otel_resolve_type_key_cache[type] - attributes = {} - attributes['graphql.type.name'] = type.graphql_name - attributes['graphql.lazy'] = false + attributes = { + 'graphql.type.name' => type.graphql_name, + 'graphql.lazy' => false + } tracer.in_span(platform_key, attributes: attributes, &block) end @@ -130,9 +135,10 @@ def resolve_type(query:, type:, object:, &block) def resolve_type_lazy(query:, type:, object:, &block) platform_key = @_otel_resolve_type_key_cache[type] - attributes = {} - attributes['graphql.type.name'] = type.graphql_name - attributes['graphql.lazy'] = true + attributes = { + 'graphql.type.name' => type.graphql_name, + 'graphql.lazy' => true + } tracer.in_span(platform_key, attributes: attributes, &block) end