class Instana::Instrumentation::GraphqlTracing

Public Instance Methods

platform_authorized_key(type) click to toggle source
# File lib/instana/instrumentation/graphql.rb, line 52
def platform_authorized_key(type)
  "#{type.graphql_name}.authorized.graphql"
end
platform_field_key(type, field) click to toggle source
# File lib/instana/instrumentation/graphql.rb, line 48
def platform_field_key(type, field)
  "#{type.graphql_name}.#{field.graphql_name}"
end
platform_resolve_type_key(type) click to toggle source
# File lib/instana/instrumentation/graphql.rb, line 56
def platform_resolve_type_key(type)
  "#{type.graphql_name}.resolve_type.graphql"
end
platform_trace(platform_key, key, data) { || ... } click to toggle source
# File lib/instana/instrumentation/graphql.rb, line 18
def platform_trace(platform_key, key, data)
  return yield unless key == 'execute_query'
  operation = data[:query].selected_operation

  arguments = []
  fields = []

  operation.selections.each do |field|
    arguments.concat(walk_fields(field, :arguments))
    fields.concat(walk_fields(field, :selections))
  end

  payload = {
    operationName: data[:query].operation_name || 'anonymous',
    operationType: operation.operation_type,
    arguments: grouped_fields(arguments),
    fields: grouped_fields(fields),
  }

  begin
    ::Instana.tracer.log_entry(:'graphql.server')
    yield
  rescue Exception => e
    ::Instana.tracer.log_error(e)
    raise e
  ensure
    ::Instana.tracer.log_exit(:'graphql.server', {graphql: payload})
  end
end

Private Instance Methods

grouped_fields(fields) click to toggle source
# File lib/instana/instrumentation/graphql.rb, line 70
def grouped_fields(fields)
  fields
    .group_by { |p| p[:object] }
    .map { |name, p| [name, p.map { |f| f[:field] }] }
    .to_h
end
walk_fields(parent, method) click to toggle source
# File lib/instana/instrumentation/graphql.rb, line 62
def walk_fields(parent, method)
  return [] unless parent.respond_to?(method)

  parent.send(method).map do |field|
    [{object: parent.name, field: field.name}] + walk_fields(field, method)
  end.flatten
end