class Raven::Rack

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.

Public Class Methods

capture_exception(exception, env, options = {})
Alias for: capture_type
capture_message(exception, env, options = {})
Alias for: capture_type
capture_type(exception, env, options = {}) click to toggle source
# File lib/raven/integrations/rack.rb, line 24
def self.capture_type(exception, env, options = {})
  if env['raven.requested_at']
    options[:time_spent] = Time.now - env['raven.requested_at']
  end
  Raven.capture_type(exception, options) do |evt|
    evt.interface :http do |int|
      int.from_rack(env)
    end
  end
end
new(app) click to toggle source
# File lib/raven/integrations/rack.rb, line 39
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/raven/integrations/rack.rb, line 43
def call(env)
  # store the current environment in our local context for arbitrary
  # callers
  env['raven.requested_at'] = Time.now
  Raven.rack_context(env)
  Raven.context.transaction.push(env["PATH_INFO"]) if env["PATH_INFO"]

  begin
    response = @app.call(env)
  rescue Error
    raise # Don't capture Raven errors
  rescue Exception => e
    Raven::Rack.capture_exception(e, env)
    raise
  end

  error = env['rack.exception'] || env['sinatra.error']
  Raven::Rack.capture_exception(error, env) if error

  response
ensure
  Context.clear!
  BreadcrumbBuffer.clear!
end