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



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

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.



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 48

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

    meta_options.merge!(:desc => layer.desc) if layer.desc

    meta = MetricMeta.new(layer.legacy_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