Class: ScoutApm::LayerConverters::MetricConverter

Inherits:
ConverterBase
  • Object
show all
Defined in:
lib/scout_apm/layer_converters/metric_converter.rb

Instance Attribute Summary

Attributes inherited from ConverterBase

#request, #root_layer, #walker

Instance Method Summary collapse

Methods inherited from ConverterBase

#find_first_layer_of_type, #initialize, #scope_layer

Constructor Details

This class inherits a constructor from ScoutApm::LayerConverters::ConverterBase

Instance Method Details

#callObject



7
8
9
10
11
12
13
14
15
# File 'lib/scout_apm/layer_converters/metric_converter.rb', line 7

def call
  scope = scope_layer

  # TODO: Track requests that never reach a Controller (for example, when
  # Middleware decides to return rather than passing onward)
  return {} unless scope

  create_metrics
end

#create_metricsObject

Full metrics from this request. These get aggregated in Store for the overview metrics, or stored permanently in a SlowTransaction Some merging of metrics will happen here, so if a request calls the same ActiveRecord or View repeatedly, it’ll get merged.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/scout_apm/layer_converters/metric_converter.rb', line 21

def create_metrics
  metric_hash = Hash.new

  walker.walk do |layer|
    meta_options = if layer == scope_layer # We don't scope the controller under itself
                    {}
                  else
                    {:scope => scope_layer.legacy_metric_name}
                  end

    # we don't need to use the full metric name for scoped metrics as we only display metrics aggregrated
    # by type.
    metric_name = meta_options.has_key?(:scope) ? layer.type : layer.legacy_metric_name

    meta = MetricMeta.new(metric_name, meta_options)
    metric_hash[meta] ||= MetricStats.new( meta_options.has_key?(:scope) )

    stat = metric_hash[meta]
    stat.update!(layer.total_call_time, layer.total_exclusive_time)
  end
  metric_hash
end