Class: ScoutApm::LayerConverters::RequestQueueTimeConverter

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

Constant Summary collapse

HEADERS =
%w(X-Queue-Start X-Request-Start X-QUEUE-START X-REQUEST-START x-queue-start x-request-start)

Instance Attribute Summary

Attributes inherited from ConverterBase

#request, #root_layer, #walker

Instance Method Summary collapse

Methods inherited from ConverterBase

#find_first_layer_of_type, #scope_layer

Constructor Details

#initialize(request) ⇒ RequestQueueTimeConverter

Headers is a hash of request headers. In Rails, request.headers would be appropriate



8
9
10
11
# File 'lib/scout_apm/layer_converters/request_queue_time_converter.rb', line 8

def initialize(request)
  super(request)
  @headers = request.headers
end

Instance Method Details

#callObject



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

def call
  return {} unless headers

  raw_start = locate_timestamp
  return {} unless raw_start

  parsed_start = parse(raw_start)
  return {} unless parsed_start

  request_start = root_layer.start_time
  queue_time = (request_start - parsed_start).to_f

  # If we end up with a negative value, just bail out and don't report anything
  return {} if queue_time < 0

  meta = MetricMeta.new("QueueTime/Request", {:scope => scope_layer.legacy_metric_name})
  stat = MetricStats.new(true)
  stat.update!(queue_time)

  { meta => stat }
end