Class: GovukPrometheusExporter::RailsMiddleware

Inherits:
PrometheusExporter::Middleware
  • Object
show all
Defined in:
lib/govuk_app_config/govuk_prometheus_exporter.rb

Overview

See github.com/discourse/prometheus_exporter/pull/293

RailsMiddleware can be removed and replaced with the default middleware if that PR is merged / released

Instance Method Summary collapse

Instance Method Details

#default_labels(env, _result) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/govuk_app_config/govuk_prometheus_exporter.rb', line 14

def default_labels(env, _result)
  controller_instance = env["action_controller.instance"]
  action = controller = nil
  if controller_instance
    action = controller_instance.action_name
    controller = controller_instance.controller_name
  elsif (cors = env["rack.cors"]) && cors.respond_to?(:preflight?) && cors.preflight?
    # if the Rack CORS Middleware identifies the request as a preflight request,
    # the stack doesn't get to the point where controllers/actions are defined
    action = "preflight"
    controller = "preflight"
  end
  {
    action: action || "other",
    controller: controller || "other",
  }
end