class ZuoraConnect::PageRequest

Object of this class is passed to the ActiveSupport::Notification hook

def call(name, started, finished, unique_id, payload)

This method is triggered when a non error page is loaded (not 404)
def call(name, started, finished, unique_id, payload)
  # If the url contains any css or JavaScript files then do not collect metrics for them
  return nil if ["css", "assets", "jpg", "png", "jpeg", "ico"].any? { |word| payload[:path].include?(word) }
  # Getting the endpoint and the content_type
  content_hash = {:html => "text/html", :js => "application/javascript", :json => "application/json", :csv => "text/csv"}
  content_type = content_hash.key?(payload[:format]) ? content_hash[payload[:format]] : payload[:format]
  content_type = content_type.to_s.gsub('text/javascript', 'application/javascript')
  # payloads with 500 requests do not have status as it is not set by the controller
  # https://github.com/rails/rails/issues/33335
  #status_code = payload[:status] ? payload[:status] : payload[:exception_object].present? ? 500 : ""
  if payload[:exception].present? 
    status_code, exception = [500, payload[:exception].first]
  else
    status_code, exception = [payload[:status], nil]
  end
  tags = {method: payload[:method], status: status_code, error_type: exception, content_type: content_type, controller: payload[:controller], action: payload[:action]}.compact
  values = {view_time: payload[:view_runtime], db_time: payload[:db_runtime], response_time: ((finished-started)*1000)}.compact
  values = values.map{ |k,v| [k,v.round(2)]}.to_h
  ZuoraConnect::AppInstanceBase.write_to_telegraf(direction: :inbound, tags: tags, values: values)
end