class Middleware::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 ZuoraConnect.configuration.enable_inbound_metrics_flag == true
    # If the url contains any css or JavaScript files then do not collect metrics for them
    block_words = ["css", "assets", "jpg", "png", "jpeg", "ico"]
    if block_words.any? { |word| payload[:path].include?(word) }
      return nil
    end
    # Getting the endpoint and the content_type
    content_hash = {:html => "text/html", :js => "application/javascript", :json => "application/json"}
    content_hash.key?(payload[:format]) ? content_type = content_hash[payload[:format]] : content_type = payload[:format]
    request_path = "#{payload[:controller]}##{payload[:action]}"
    response_time = finished-started
    # 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 : ""
    # Write to telegraf
    ZuoraConnect::AppInstanceBase.write_to_telegraf("endpoint_name": request_path, "method_name": payload[:method], "status_code": status_code, "response_time": response_time, "db_runtime": payload[:db_runtime].to_f, "view_runtime": payload[:view_runtime], "content_type": content_type, "direction": "inbound")
  end
end