class GraphQL::Tracing::DetailedTrace

DetailedTrace can make detailed profiles for a subset of production traffic. Install it in Rails with rails generate graphql:detailed_trace.

When MySchema.detailed_trace?(query) returns true, a profiler-specific trace_mode: ... will be used for the query, overriding the one in context[:trace_mode].

By default, the detailed tracer calls .inspect on application objects returned from fields. You can customize this behavior by extending DetailedTrace and overriding inspect object. You can opt out of debug annotations entirely with use ..., debug: false or for a single query with context: { detailed_trace_debug: false }.

You can store saved traces in two ways:

If you need to save traces indefinitely, you can download them from Perfetto after opening them there.

See GraphQL::Dashboard for viewing stored results.

Examples

Example: Installing with Rails

rails generate graphql:detailed_trace # optional: --redis

Example: Adding the sampler to your schema

class MySchema < GraphQL::Schema
  # Add the sampler:
  use GraphQL::Tracing::DetailedTrace, redis: Redis.new(...), limit: 100

  # And implement this hook to tell it when to take a sample:
  def self.detailed_trace?(query)
    # Could use `query.context`, `query.selected_operation_name`, `query.query_string` here
    # Could call out to Flipper, etc
    rand <= 0.000_1 # one in ten thousand
  end
end

Example: Customizing debug output in traces

class CustomDetailedTrace < GraphQL::Tracing::DetailedTrace
  def inspect_object(object)
    if object.is_a?(SomeThing)
      # handle it specially ...
    else
      super
     end
  end
end

Example: disabling debug annotations completely

use DetailedTrace, debug: false, ...

Example: disabling debug annotations for one query

MySchema.execute(query_str, context: { detailed_trace_debug: false })