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>?}
authorized { context: GraphQL::Query::Context, type: Class, object: Object, path: Array<String, Integer> }
authorized_lazy { context: GraphQL::Query::Context, type: Class, object: Object, path: Array<String, Integer> }
resolve_type { context: GraphQL::Query::Context, type: Class, object: Object, path: Array<String, Integer> }
resolve_type_lazy { context: GraphQL::Query::Context, type: Class, object: Object, 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

query.trace("my_custom_event", { ... }) do
  # do stuff ...
end

Adding a tracer to a schema

class MySchema < GraphQL::Schema
  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)>)


92
93
94
95
96
97
# File 'lib/graphql/tracing.rb', line 92

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: [...] }



105
106
107
# File 'lib/graphql/tracing.rb', line 105

def tracers
  @tracers ||= []
end

.uninstall(tracer) ⇒ Object

Deprecated.

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



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

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