⚠ Experimental ⚠

This feature may get big changes in future releases. Check the changelog for update notes.

Tracing

GraphQL::Tracing provides a .trace hook to observe events from the GraphQL runtime.

A tracer must implement .trace, for example:

class MyCustomTracer
  def self.trace(key, data)
    # do stuff with key & data
    yield
  end
end

.trace is called with:

To run a tracer for every query, add it to the schema with tracer:

# Run `MyCustomTracer` for all queries
MySchema = GraphQL::Schema.define do
  tracer(MyCustomTracer)
end

Or, to run a tracer for one query only, add it to context: as tracers: [...], for example:

# Run `MyCustomTracer` for this query
MySchema.execute(..., context: { tracers: [MyCustomTracer]})

For a full list of events, see the GraphQL::Tracing API docs.

ActiveSupport::Notifications

You can emit events to ActiveSupport::Notifications with an experimental tracer, ActiveSupportNotificationsTracing.

To enable it, install the tracer:

# Send execution events to ActiveSupport::Notifications
MySchema = GraphQL::Schema.define do
  tracer GraphQL::Tracing::ActiveSupportNotificationsTracing
end

Monitoring

Several monitoring platforms are supported out-of-the box by GraphQL-Ruby (see platforms below).

Leaf fields are not monitored (to avoid high cardinality in the metrics service).

Implementations are based on Tracing::PlatformTracing.

Appsignal

To add AppSignal instrumentation:

MySchema = GraphQL::Schema.define do
  use(GraphQL::Tracing::AppsignalTracing)
end

New Relic

To add New Relic instrumentation:

MySchema = GraphQL::Schema.define do
  use(GraphQL::Tracing::NewRelicTracing)
end

Scout

To add Scout APM instrumentation:

MySchema = GraphQL::Schema.define do
  use(GraphQL::Tracing::ScoutTracing)
end

Skylight

To add Skylight instrumentation:

MySchema = GraphQL::Schema.define do
  use(GraphQL::Tracing::SkylightTracing)
end