class OpenTelemetry::Instrumentation::GraphQL::Tracers::GraphQLTracer

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

Public Instance Methods

platform_authorized_key(type) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) { || ... } click to toggle source
# 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

Private Instance Methods

attributes_for(key, data) click to toggle source
# File lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb, line 73
def attributes_for(key, data)
  attributes = {}
  case key
  when 'execute_query'
    attributes['selected_operation_name'] = data[:query].selected_operation_name if data[:query].selected_operation_name
    attributes['selected_operation_type'] = data[:query].selected_operation.operation_type
    attributes['query_string'] = data[:query].query_string
  end
  attributes
end
config() click to toggle source
# File lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb, line 69
def config
  GraphQL::Instrumentation.instance.config
end
tracer() click to toggle source
# File lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb, line 65
def tracer
  GraphQL::Instrumentation.instance.tracer
end