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 collapse

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

Instance Method Summary collapse

Methods inherited from PlatformTracing

#trace, 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_authorized_key(type) ⇒ Object



39
40
41
# File 'lib/graphql/tracing/prometheus_tracing.rb', line 39

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

#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_resolve_type_key(type) ⇒ Object



43
44
45
# File 'lib/graphql/tracing/prometheus_tracing.rb', line 43

def platform_resolve_type_key(type)
  "#{type.graphql_name}.resolve_type"
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