Class: GraphQL::Tracing::PrometheusTracing

Inherits:
PlatformTracing show all
Defined in:
lib/graphql/tracing/prometheus_tracing.rb,
lib/graphql/tracing/prometheus_tracing/graphql_collector.rb

Defined Under Namespace

Classes: GraphQLCollector

Constant Summary

DEFAULT_WHITELIST =
['execute_field', 'execute_field_lazy'].freeze
DEFAULT_COLLECTOR_TYPE =
'graphql'.freeze

Instance Method Summary collapse

Methods inherited from PlatformTracing

#instrument, #trace, #trace_field, use

Constructor Details

#initialize(opts = {}) ⇒ PrometheusTracing

Returns a new instance of PrometheusTracing



22
23
24
25
26
27
28
# File 'lib/graphql/tracing/prometheus_tracing.rb', line 22

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

Instance Method Details

#platform_field_key(type, field) ⇒ Object



35
36
37
# File 'lib/graphql/tracing/prometheus_tracing.rb', line 35

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

#platform_trace(platform_key, key, data, &block) ⇒ Object



30
31
32
33
# File 'lib/graphql/tracing/prometheus_tracing.rb', line 30

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