class ScoutApm::LayerConverters::RequestQueueTimeConverter

Constants

HEADERS

Public Instance Methods

headers() click to toggle source
# File lib/scout_apm/layer_converters/request_queue_time_converter.rb, line 7
def headers
  request.headers
end
record!() click to toggle source
# File lib/scout_apm/layer_converters/request_queue_time_converter.rb, line 11
def record!
  return unless request.web?

  return unless context.config.value('record_queue_time')

  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)
  metrics = { meta => stat }
  
  @store.track!(metrics)
  metrics  # this result must be returned so it can be accessed by transaction callback extensions
end

Private Instance Methods

locate_timestamp() click to toggle source

Looks through the possible headers with this data, and extracts the raw value of the header Returns nil if not found

# File lib/scout_apm/layer_converters/request_queue_time_converter.rb, line 44
def locate_timestamp
  return nil unless headers

  header = HEADERS.find { |candidate| headers[candidate] }
  if header
    data = headers[header]
    data.to_s.gsub(/(t=|\.)/, '')
  else
    nil
  end
end
parse(time_string) click to toggle source

Returns a timestamp in fractional seconds since epoch

# File lib/scout_apm/layer_converters/request_queue_time_converter.rb, line 57
def parse(time_string)
  Time.at("#{time_string[0,10]}.#{time_string[10,13]}".to_f)
end