Method: GraphQL::Schema.new_trace

Defined in:
lib/graphql/schema.rb

.new_trace(mode: nil, **options) ⇒ Tracing::Trace

Create a trace instance which will include the trace modules specified for the optional mode.

If no mode: is given, then default_trace_mode will be used.

If this schema is using Tracing::DetailedTrace and detailed_trace? returns true, then DetailedTrace's mode will override the passed-in mode.

Parameters:

  • mode (Symbol) (defaults to: nil)

    Trace modules for this trade mode will be included

  • options (Hash)

    Keywords that will be passed to the tracing class during #initialize

Returns:



1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
# File 'lib/graphql/schema.rb', line 1482

def new_trace(mode: nil, **options)
  should_sample = if detailed_trace
    if (query = options[:query])
      detailed_trace?(query)
    elsif (multiplex = options[:multiplex])
      if multiplex.queries.length == 1
        detailed_trace?(multiplex.queries.first)
      else
        detailed_trace?(multiplex)
      end
    end
  else
    false
  end

  if should_sample
    mode = detailed_trace.trace_mode
  else
    target = options[:query] || options[:multiplex]
    mode ||= target && target.context[:trace_mode]
  end

  trace_mode = mode || default_trace_mode
  base_trace_options = trace_options_for(trace_mode)
  trace_options = base_trace_options.merge(options)
  trace_class_for_mode = trace_class_for(trace_mode, build: true)
  trace_class_for_mode.new(**trace_options)
end