77
88module GraphQL
99 module Tracing
10- # `DetailedTrace` can make detailed profiles for a subset of production traffic.
10+ # `DetailedTrace` can make detailed profiles for a subset of production traffic. Install it in Rails with `rails generate graphql:detailed_trace`.
1111 #
1212 # When `MySchema.detailed_trace?(query)` returns `true`, a profiler-specific `trace_mode: ...` will be used for the query,
1313 # overriding the one in `context[:trace_mode]`.
@@ -16,10 +16,19 @@ module Tracing
1616 # this behavior by extending {DetailedTrace} and overriding {#inspect_object}. You can opt out of debug annotations
1717 # entirely with `use ..., debug: false` or for a single query with `context: { detailed_trace_debug: false }`.
1818 #
19- # __Redis__: The sampler stores its results in a provided Redis database. Depending on your needs,
20- # You can configure this database to retain all data (persistent) or to expire data according to your rules.
19+ # You can store saved traces in two ways:
20+ #
21+ # - __ActiveRecord__: With `rails generate graphql:detailed_trace`, a new migration will be added to your app.
22+ # That table will be used to store trace data.
23+ #
24+ # - __Redis__: Pass `redis: ...` to save trace data to a Redis database. Depending on your needs,
25+ # you can configure this database to retain all data (persistent) or to expire data according to your rules.
26+ #
2127 # If you need to save traces indefinitely, you can download them from Perfetto after opening them there.
2228 #
29+ # @example Installing with Rails
30+ # rails generate graphql:detailed_trace # optional: --redis
31+ #
2332 # @example Adding the sampler to your schema
2433 # class MySchema < GraphQL::Schema
2534 # # Add the sampler:
@@ -56,13 +65,14 @@ class DetailedTrace
5665 # @param redis [Redis] If provided, profiles will be stored in Redis for later review
5766 # @param limit [Integer] A maximum number of profiles to store
5867 # @param debug [Boolean] if `false`, it won't create `debug` annotations in Perfetto traces (reduces overhead)
59- def self . use ( schema , trace_mode : :profile_sample , memory : false , debug : debug? , redis : nil , limit : nil )
68+ # @param model_class [Class<ActiveRecord::Base>] Overrides {ActiveRecordBackend::GraphqlDetailedTrace} if present
69+ def self . use ( schema , trace_mode : :profile_sample , memory : false , debug : debug? , redis : nil , limit : nil , model_class : nil )
6070 storage = if redis
6171 RedisBackend . new ( redis : redis , limit : limit )
6272 elsif memory
6373 MemoryBackend . new ( limit : limit )
6474 elsif defined? ( ActiveRecord )
65- ActiveRecordBackend . new ( limit : limit )
75+ ActiveRecordBackend . new ( limit : limit , model_class : model_class )
6676 else
6777 raise ArgumentError , "To store traces, install ActiveRecord or provide `redis: ...`"
6878 end
0 commit comments