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

Instance Method Summary collapse

Instance Method Details

#platform_authorized_key(type) ⇒ Object



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

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

  "#{type.graphql_name}.authorized"
end

#platform_field_key(type, field) ⇒ Object



45
46
47
48
49
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb', line 45

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

  "#{type.graphql_name}.#{field.graphql_name}"
end

#platform_resolve_type_key(type) ⇒ Object



57
58
59
60
61
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb', line 57

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

  "#{type.graphql_name}.resolve_type"
end

#platform_trace(platform_key, key, data) ⇒ Object



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

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|
      errors = response[:errors]&.compact&.map { |e| e.to_h }&.to_json if key == 'validate'
      unless errors.nil?
        span.add_event(
          'graphql.validation.error',
          attributes: {
            'message' => errors
          }
        )
      end
    end
  end
end