module GraphQL::Tracing::PerfettoTrace

This produces a trace file for inspecting in the Perfetto Trace Viewer.

To get the file, call write on the trace.

Use “trace modes” to configure this to run on command or on a sample of traffic.

Examples

Example: Writing trace output

result = MySchema.execute(...)
result.query.trace.write(file: "tmp/trace.dump")

Example: Running this instrumenter when trace: true is present in the request

class MySchema < GraphQL::Schema
  # Only run this tracer when `context[:trace_mode]` is `:trace`
  trace_with GraphQL::Tracing::Perfetto, mode: :trace
end

# In graphql_controller.rb:

context[:trace_mode] = params[:trace] ? :trace : nil
result = MySchema.execute(query_str, context: context, variables: variables, ...)
if context[:trace_mode] == :trace
  result.trace.write(file: ...)
end