class GDS::Metrics::Middleware

Attributes

wrapped_app[RW]

Public Class Methods

new(app) click to toggle source
# File lib/gds_metrics/middleware.rb, line 6
def initialize(app)
  self.wrapped_app = Rack::Builder.app do
    use GDS::Metrics::Gzip
    use GDS::Metrics::Auth

    if defined?(Rails)
      rails_label_builder = proc do |env|
        {
          method: env['REQUEST_METHOD'].downcase,
          host:   env['HTTP_HOST'].to_s,
          controller:   GDS::Metrics::PathConverter.convert_rails_path_to_route(env['PATH_INFO'].to_s),
        }
      end
      use Prometheus::Client::Rack::Collector, registry: Proxy.new, &rails_label_builder
    else
      use Prometheus::Client::Rack::Collector, registry: Proxy.new
    end

    use Prometheus::Client::Rack::Exporter

    run app
  end
end

Public Instance Methods

call(env) click to toggle source
# File lib/gds_metrics/middleware.rb, line 30
def call(env)
  wrapped_app.call(env)
end