Sha256: 5755a1b88e3bc6d9d7b500daa92fe574a62d432c05f7506a15161eb03dc317ad

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

module Airbrake
  # Middleware for Rack applications. Any errors raised by the upstream
  # application will be delivered to Airbrake and re-raised.
  #
  # Synopsis:
  #
  #   require 'rack'
  #   require 'airbrake'
  #
  #   Airbrake.configure do |config|
  #     config.api_key = 'my_api_key'
  #   end
  #
  #   app = Rack::Builder.app do
  #     run lambda { |env| raise "Rack down" }
  #   end
  #
  #   use Airbrake::Rack
  #   run app
  #
  # Use a standard Airbrake.configure call to configure your api key.
  class Rack
    def initialize(app)
      @app = app
    end

    def ignored_user_agent?(env)
      true if Airbrake.
        configuration.
        ignore_user_agent.
        flatten.
        any? { |ua| ua === env['HTTP_USER_AGENT'] }
    end

    def notify_airbrake(exception,env)
      Airbrake.notify_or_ignore(exception,:rack_env => env) unless ignored_user_agent?(env)
    end

    def call(env)
      begin
        response = @app.call(env)
      rescue Exception => raised
        env['airbrake.error_id'] = notify_airbrake(raised,env)
        raise
      end

      if env['rack.exception']
        env['airbrake.error_id'] = notify_airbrake(env['rack.exception'],env)
      end

      response
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
airbrake-3.1.6 lib/airbrake/rack.rb
airbrake-3.1.5 lib/airbrake/rack.rb
airbrake-3.1.4 lib/airbrake/rack.rb
airbrake-3.1.3 lib/airbrake/rack.rb