Class: ScoutApm::LayerConverters::JobConverter

Inherits:
ConverterBase show all
Defined in:
lib/scout_apm/layer_converters/job_converter.rb

Instance Attribute Summary

Attributes inherited from ConverterBase

#request, #root_layer, #walker

Instance Method Summary collapse

Methods inherited from ConverterBase

#initialize, #scope_layer

Constructor Details

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

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/scout_apm/layer_converters/job_converter.rb', line 13

def call
  return unless request.job?

  JobRecord.new(
    queue_layer.name,
    job_layer.name,
    job_layer.total_call_time,
    job_layer.total_exclusive_time,
    errors,
    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.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/scout_apm/layer_converters/job_converter.rb', line 52

def create_metrics
  metric_hash = Hash.new

  meta_options = {:scope => job_layer.legacy_metric_name}

  walker.walk do |layer|
    next if layer == job_layer
    next if layer == queue_layer

    # we don't need to use the full metric name for scoped metrics as we
    # only display metrics aggregrated by type, just use "ActiveRecord"
    # or similar.
    metric_name = layer.type

    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

  # Add the latency metric, which wasn't stored as a distinct layer
  latency = request.annotations[:queue_latency] || 0
  meta = MetricMeta.new("Latency", meta_options)
  stat = MetricStats.new
  stat.update!(latency)
  metric_hash[meta] = stat

  metric_hash
end

#errorsObject



34
35
36
37
38
39
40
# File 'lib/scout_apm/layer_converters/job_converter.rb', line 34

def errors
  if request.error?
    1
  else
    0
  end
end

#find_first_layer_of_type(layer_type) ⇒ Object



42
43
44
45
46
# File 'lib/scout_apm/layer_converters/job_converter.rb', line 42

def find_first_layer_of_type(layer_type)
  walker.walk do |layer|
    return layer if layer.type == layer_type
  end
end

#job_layerObject



30
31
32
# File 'lib/scout_apm/layer_converters/job_converter.rb', line 30

def job_layer
  @job_layer ||= find_first_layer_of_type("Job")
end

#queue_layerObject



26
27
28
# File 'lib/scout_apm/layer_converters/job_converter.rb', line 26

def queue_layer
  @queue_layer ||= find_first_layer_of_type("Queue")
end