Class: OpenTelemetry::Instrumentation::GraphQL::Tracers::GraphQLTracer

Inherits:
GraphQL::Tracing::PlatformTracing
  • Object
show all
Defined in:
lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb

Overview

GraphQLTracer contains the OpenTelemetry tracer implementation compatible with the GraphQL tracer API

Constant Summary collapse

DEFAULT_HASH =
{}.freeze

Instance Method Summary collapse

Instance Method Details

#platform_authorized_key(type) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb', line 60

def platform_authorized_key(type)
  return unless config[:enable_platform_authorized]

  if config[:legacy_platform_span_names]
    "#{type.graphql_name}.authorized"
  else
    'graphql.authorized'
  end
end

#platform_field_key(type, field) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb', line 50

def platform_field_key(type, field)
  return unless config[:enable_platform_field]

  if config[:legacy_platform_span_names]
    "#{type.graphql_name}.#{field.graphql_name}"
  else
    'graphql.execute_field'
  end
end

#platform_resolve_type_key(type) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb', line 70

def platform_resolve_type_key(type)
  return unless config[:enable_platform_resolve_type]

  if config[:legacy_platform_span_names]
    "#{type.graphql_name}.resolve_type"
  else
    'graphql.resolve_type'
  end
end

#platform_trace(platform_key, key, data) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb', line 29

def platform_trace(platform_key, key, data)
  return yield if platform_key.nil?

  tracer.in_span(platform_key, attributes: attributes_for(key, data)) do |span|
    yield.tap do |response|
      next unless key == 'validate'

      errors = response[:errors]&.compact&.map(&:to_h) || []

      unless errors.empty?
        span.add_event(
          'graphql.validation.error',
          attributes: {
            'exception.message' => errors.to_json
          }
        )
      end
    end
  end
end