Class: GraphQL::Tracing::PrometheusTracing

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

Constant Summary collapse

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

Backwards-compat:

PrometheusTrace::GraphQLCollector

Instance Method Summary collapse

Methods inherited from PlatformTracing

#trace, use

Constructor Details

#initialize(opts = {}) ⇒ PrometheusTracing

Returns a new instance of PrometheusTracing.



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

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



41
42
43
# File 'lib/graphql/tracing/prometheus_tracing.rb', line 41

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

#platform_field_key(type, field) ⇒ Object



37
38
39
# File 'lib/graphql/tracing/prometheus_tracing.rb', line 37

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

#platform_resolve_type_key(type) ⇒ Object



45
46
47
# File 'lib/graphql/tracing/prometheus_tracing.rb', line 45

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

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



32
33
34
35
# File 'lib/graphql/tracing/prometheus_tracing.rb', line 32

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