Class: ReportsMash::Rack::Hooks

Inherits:
Object
  • Object
show all
Defined in:
lib/reportsmash/rack/hooks.rb

Overview

This middleware is used by the agent internally, and is usually injected automatically into the middleware chain. If automatic injection is not working, you may manually use it in your middleware chain instead.

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Hooks.



11
12
13
# File 'lib/reportsmash/rack/hooks.rb', line 11

def initialize(app, options = {})
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

method required by Rack interface

status, headers, response


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/reportsmash/rack/hooks.rb', line 19

def call(env)
  ReportsMash::Engine::ThreadState.clear
  ReportsMash::Engine.engine.transaction_start(env)
  start_time = Time.now
  begin
  	result = @app.call(env)
    stop_time = Time.now
    ReportsMash::Engine.engine.transaction_end(start_time, stop_time, nil, result, env)
  rescue => e
    stop_time = Time.now
    ReportsMash::Engine.engine.transaction_end(start_time, stop_time, e, nil, env)
    raise(e)
  end
  result
end