Class: Hubble::Rescuer

Inherits:
Object
  • Object
show all
Defined in:
lib/hubble/middleware.rb

Overview

Rack middleware that rescues exceptions raised from the downstream app and reports to Hubble::Client. The exception is reraised after being sent to hubble so upstream middleware can still display an error page or whathaveyou.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, other = {}) ⇒ Rescuer

Returns a new instance of Rescuer.



7
8
9
10
# File 'lib/hubble/middleware.rb', line 7

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

Class Method Details

.report(boom, env, other = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hubble/middleware.rb', line 21

def self.report(boom, env, other={})
  request = Rack::Request.new(env)
  Hubble::Client.report(boom, other.merge({
    :method       => request.request_method,
    :user_agent   => env['HTTP_USER_AGENT'],
    :params       => (request.params.inspect rescue nil),
    :session      => (request.session.inspect rescue nil),
    :referrer     => request.referrer,
    :remote_ip    => request.ip,
    :url          => request.url
  }))
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/hubble/middleware.rb', line 12

def call(env)
  start = Time.now
  @app.call(env)
rescue Object => boom
  elapsed = Time.now - start
  self.class.report(boom, env, @other.merge(:time => elapsed.to_s))
  raise
end