Module: GraphQL::Tracing::PrometheusTrace

Includes:
PlatformTrace
Defined in:
lib/graphql/tracing/prometheus_trace.rb,
lib/graphql/tracing/prometheus_trace/graphql_collector.rb

Overview

A tracer for reporting GraphQL-Ruby times to Prometheus.

The PrometheusExporter server must be run with a custom type collector that extends GraphQL::Tracing::PrometheusTracing::GraphQLCollector.

Examples:

Adding this trace to your schema

require 'prometheus_exporter/client'

class MySchema < GraphQL::Schema
  trace_with GraphQL::Tracing::PrometheusTrace
end

Running a custom type collector

# lib/graphql_collector.rb
if defined?(PrometheusExporter::Server)
  require 'graphql/tracing'

  class GraphQLCollector < GraphQL::Tracing::PrometheusTrace::GraphQLCollector
  end
end

 # Then run:
 # bundle exec prometheus_exporter -a lib/graphql_collector.rb

Defined Under Namespace

Classes: GraphQLCollector

Instance Method Summary collapse

Instance Method Details

#initialize(client: PrometheusExporter::Client.default, keys_whitelist: ["execute_field", "execute_field_lazy"], collector_type: "graphql", **rest) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/graphql/tracing/prometheus_trace.rb', line 35

def initialize(client: PrometheusExporter::Client.default, keys_whitelist: ["execute_field", "execute_field_lazy"], collector_type: "graphql", **rest)
  @client = client
  @keys_whitelist = keys_whitelist
  @collector_type = collector_type

  super(**rest)
end

#platform_authorized(platform_key, &block) ⇒ Object



68
69
70
# File 'lib/graphql/tracing/prometheus_trace.rb', line 68

def platform_authorized(platform_key, &block)
  instrument_prometheus_execution(platform_key, "authorized", &block)
end

#platform_authorized_key(type) ⇒ Object



88
89
90
# File 'lib/graphql/tracing/prometheus_trace.rb', line 88

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

#platform_authorized_lazy(platform_key, &block) ⇒ Object



72
73
74
# File 'lib/graphql/tracing/prometheus_trace.rb', line 72

def platform_authorized_lazy(platform_key, &block)
  instrument_prometheus_execution(platform_key, "authorized_lazy", &block)
end

#platform_execute_field(platform_key, &block) ⇒ Object



60
61
62
# File 'lib/graphql/tracing/prometheus_trace.rb', line 60

def platform_execute_field(platform_key, &block)
  instrument_prometheus_execution(platform_key, "execute_field", &block)
end

#platform_execute_field_lazy(platform_key, &block) ⇒ Object



64
65
66
# File 'lib/graphql/tracing/prometheus_trace.rb', line 64

def platform_execute_field_lazy(platform_key, &block)
  instrument_prometheus_execution(platform_key, "execute_field_lazy", &block)
end

#platform_field_key(field) ⇒ Object



84
85
86
# File 'lib/graphql/tracing/prometheus_trace.rb', line 84

def platform_field_key(field)
  field.path
end

#platform_resolve_type(platform_key, &block) ⇒ Object



76
77
78
# File 'lib/graphql/tracing/prometheus_trace.rb', line 76

def platform_resolve_type(platform_key, &block)
  instrument_prometheus_execution(platform_key, "resolve_type", &block)
end

#platform_resolve_type_key(type) ⇒ Object



92
93
94
# File 'lib/graphql/tracing/prometheus_trace.rb', line 92

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

#platform_resolve_type_lazy(platform_key, &block) ⇒ Object



80
81
82
# File 'lib/graphql/tracing/prometheus_trace.rb', line 80

def platform_resolve_type_lazy(platform_key, &block)
  instrument_prometheus_execution(platform_key, "resolve_type_lazy", &block)
end