Class: ScoutApm::LayerMetricConverter

Inherits:
LayerConverterBase show all
Defined in:
lib/scout_apm/layer_converter.rb

Overview

Take a TrackedRequest and turn it into a hash of:

MetricMeta => MetricStats

This will do some merging of metrics as duplicate calls are seen.

Instance Attribute Summary

Attributes inherited from LayerConverterBase

#request, #root_layer, #walker

Instance Method Summary collapse

Methods inherited from LayerConverterBase

#initialize, #scope_layer

Constructor Details

This class inherits a constructor from ScoutApm::LayerConverterBase

Instance Method Details

#callObject



33
34
35
36
37
38
39
40
41
# File 'lib/scout_apm/layer_converter.rb', line 33

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.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/scout_apm/layer_converter.rb', line 47

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