Class: Raven::Rack
- Inherits:
-
Object
- Object
- Raven::Rack
- Defined in:
- lib/raven/rack.rb
Overview
Middleware for Rack applications. Any errors raised by the upstream application will be delivered to Sentry and re-raised.
Synopsis:
require 'rack'
require 'raven'
Raven.configure do |config|
config.server = 'http://my_dsn'
end
app = Rack::Builder.app do
use Raven::Rack
run lambda { |env| raise "Rack down" }
end
Use a standard Raven.configure call to configure your server credentials.
Class Method Summary collapse
- .capture_exception(exception, env, options = {}) ⇒ Object
- .capture_message(message, env, options = {}) ⇒ Object
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Rack
constructor
A new instance of Rack.
Constructor Details
#initialize(app) ⇒ Rack
Returns a new instance of Rack.
37 38 39 |
# File 'lib/raven/rack.rb', line 37 def initialize(app) @app = app end |
Class Method Details
.capture_exception(exception, env, options = {}) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/raven/rack.rb', line 21 def self.capture_exception(exception, env, = {}) Raven.capture_exception(exception, ) do |evt| evt.interface :http do |int| int.from_rack(env) end end end |
.capture_message(message, env, options = {}) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/raven/rack.rb', line 29 def self.(, env, = {}) Raven.(, ) do |evt| evt.interface :http do |int| int.from_rack(env) end end end |
Instance Method Details
#call(env) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/raven/rack.rb', line 41 def call(env) begin response = @app.call(env) rescue Error => e raise # Don't capture Raven errors rescue Exception => e Raven::Rack.capture_exception(e, env) raise ensure Context.clear! end error = env['rack.exception'] || env['sinatra.error'] if error Raven::Rack.capture_exception(error, env) end response end |