class GraphQL::Tracing::PrometheusTracing

def initialize(opts = {})

def initialize(opts = {})
  @client = opts[:client] || PrometheusExporter::Client.default
  @keys_whitelist = opts[:keys_whitelist] || DEFAULT_WHITELIST
  @collector_type = opts[:collector_type] || DEFAULT_COLLECTOR_TYPE
  super opts
end

def instrument_execution(platform_key, key, &block)

def instrument_execution(platform_key, key, &block)
  start = ::Process.clock_gettime ::Process::CLOCK_MONOTONIC
  result = block.call
  duration = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start
  observe platform_key, key, duration
  result
end

def observe(platform_key, key, duration)

def observe(platform_key, key, duration)
  @client.send_json(
    type: @collector_type,
    duration: duration,
    platform_key: platform_key,
    key: key
  )
end

def platform_authorized_key(type)

def platform_authorized_key(type)
  "#{type.graphql_name}.authorized"
end

def platform_field_key(type, field)

def platform_field_key(type, field)
  "#{type.graphql_name}.#{field.graphql_name}"
end

def platform_resolve_type_key(type)

def platform_resolve_type_key(type)
  "#{type.graphql_name}.resolve_type"
end

def platform_trace(platform_key, key, _data, &block)

def platform_trace(platform_key, key, _data, &block)
  return yield unless @keys_whitelist.include?(key)
  instrument_execution(platform_key, key, &block)
end