Module: GraphQL::Metrics::Instrumentation

Defined in:
lib/graphql/metrics/instrumentation.rb

Instance Method Summary collapse

Instance Method Details

#execute_multiplex(multiplex:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/graphql/metrics/instrumentation.rb', line 12

def execute_multiplex(multiplex:)
  return super if multiplex.context[GraphQL::Metrics::SKIP_GRAPHQL_METRICS_ANALYSIS]

  result = nil

  multiplex.queries.each do |query|
    ns = query.context.namespace(CONTEXT_NAMESPACE)
    ns[GraphQL::Metrics::TIMINGS_CAPTURE_ENABLED] = @capture_field_timings
    ns[GraphQL::Metrics::INLINE_FIELD_TIMINGS] = Hash.new { |h, k| h[k] = [] }
    ns[GraphQL::Metrics::LAZY_FIELD_TIMINGS] = Hash.new { |h, k| h[k] = [] }
  end

  begin
    result = super
  ensure
    multiplex.queries.each do |query|
      handle_query(query) if query.valid?
    end
  end

  result
end

#initialize(capture_field_timings: true, **_options) ⇒ Object



6
7
8
9
10
# File 'lib/graphql/metrics/instrumentation.rb', line 6

def initialize(capture_field_timings: true, **_options)
  @capture_field_timings = capture_field_timings

  super
end