Class: Authify::API::Middleware::Metrics

Inherits:
Object
  • Object
show all
Defined in:
lib/authify/api/middleware/metrics.rb

Overview

A middleware for analytics of rack requests

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Metrics

Returns a new instance of Metrics.



6
7
8
9
10
# File 'lib/authify/api/middleware/metrics.rb', line 6

def initialize(app)
  @app     = app
  @metrics = Authify::API::Metrics.instance
  @key     = 'rack.action.response'
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/authify/api/middleware/metrics.rb', line 12

def call(env)
  status, header, body = @metrics.time(construct_metric_key('time', env)) do
    @app.call env
  end

  @metrics.increment construct_metric_key('count', env)
  @metrics.increment 'rack.request.count'

  [status, header, body]
end