Class: Metrics::Integration::Rack::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-metrics/integration/rack_middleware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Middleware

Returns a new instance of Middleware.



20
21
22
23
24
# File 'lib/ruby-metrics/integration/rack_middleware.rb', line 20

def initialize(app, options ={})
  @app      = app
  @options  = {:show => "/stats"}.merge(options)
  @agent    = @options.delete(:agent) || Agent.new
end

Instance Attribute Details

#agentObject

Returns the value of attribute agent.



18
19
20
# File 'lib/ruby-metrics/integration/rack_middleware.rb', line 18

def agent
  @agent
end

#appObject

Returns the value of attribute app.



18
19
20
# File 'lib/ruby-metrics/integration/rack_middleware.rb', line 18

def app
  @app
end

#optionsObject

Returns the value of attribute options.



18
19
20
# File 'lib/ruby-metrics/integration/rack_middleware.rb', line 18

def options
  @options
end

Instance Method Details

#call(env) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby-metrics/integration/rack_middleware.rb', line 26

def call(env)
  return show(env) if show?(env)
  
  env['metrics.agent'] = @agent
  
  status, headers, body = time_request { @app.call(env) }

  incr_status_code_counter(status / 100)

  [status, headers, body]
rescue Exception
  # TODO: add "last_uncaught_exception" with string of error
  incr_uncaught_exceptions
  raise
end