Module: GraphQL::Tracing

Defined in:
lib/graphql/tracing.rb,
lib/graphql/tracing/scout_tracing.rb,
lib/graphql/tracing/data_dog_tracing.rb,
lib/graphql/tracing/platform_tracing.rb,
lib/graphql/tracing/skylight_tracing.rb,
lib/graphql/tracing/appsignal_tracing.rb,
lib/graphql/tracing/new_relic_tracing.rb,
lib/graphql/tracing/prometheus_tracing.rb,
lib/graphql/tracing/active_support_notifications_tracing.rb,
lib/graphql/tracing/prometheus_tracing/graphql_collector.rb

Overview

Library entry point for performance metric reporting.

Warning: Installing/uninstalling tracers is not thread-safe. Do it during application boot only.

Events:

Key Metadata
lex { query_string: String }
parse { query_string: String }
validate { query: GraphQL::Query, validate: Boolean }
analyze_multiplex { multiplex: GraphQL::Execution::Multiplex }
analyze_query { query: GraphQL::Query }
execute_multiplex { multiplex: GraphQL::Execution::Multiplex }
execute_query { query: GraphQL::Query }
execute_query_lazy { query: GraphQL::Query?, multiplex: GraphQL::Execution::Multiplex? }
execute_field { context: GraphQL::Query::Context::FieldResolutionContext?, owner: Class?, field: GraphQL::Schema::Field?, query: GraphQL::Query?, path: Array<String, Integer>?}
execute_field_lazy { context: GraphQL::Query::Context::FieldResolutionContext?, owner: Class?, field: GraphQL::Schema::Field?, query: GraphqL::Query?, path: Array<String, Integer>?}

Note that execute_field and execute_field_lazy receive different data in different settings:

  • When using Execution::Interpreter, they receive {field:, path:, query:}
  • Otherwise, they receive {context: ...}

Examples:

Sending custom events

GraphQL::Tracing.trace("my_custom_event", { ... }) do
  # do stuff ...
end

Adding a tracer to a schema

MySchema = GraphQL::Schema.define do
  tracer MyTracer # <= responds to .trace(key, data, &block)
end

Adding a tracer to a single query

MySchema.execute(query_str, context: { backtrace: true })

Defined Under Namespace

Modules: ActiveSupportNotificationsTracing, NullTracer, Traceable Classes: AppsignalTracing, DataDogTracing, NewRelicTracing, PlatformTracing, PrometheusTracing, ScoutTracing, SkylightTracing

Class Method Summary collapse

Class Method Details

.install(tracer) ⇒ void

Deprecated.

See Schema.tracer or use context: { tracers: [...] }

This method returns an undefined value.

Install a tracer to receive events.

Parameters:

  • tracer (<#trace(key, metadata)>)


88
89
90
91
92
93
# File 'lib/graphql/tracing.rb', line 88

def install(tracer)
  warn("GraphQL::Tracing.install is deprecated, add it to the schema with `tracer(my_tracer)` instead.")
  if !tracers.include?(tracer)
    @tracers << tracer
  end
end

.tracersObject

Deprecated.

See Schema.tracer or use context: { tracers: [...] }



101
102
103
# File 'lib/graphql/tracing.rb', line 101

def tracers
  @tracers ||= []
end

.uninstall(tracer) ⇒ Object

Deprecated.

See Schema.tracer or use context: { tracers: [...] }



96
97
98
# File 'lib/graphql/tracing.rb', line 96

def uninstall(tracer)
  @tracers.delete(tracer)
end