Sha256: d206e6be66f227702522ee0f48267c6b6a7e56bb6ec7f33d83f8395ef597bc37

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 KB

Contents

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

    def call(env)
      begin
        response = @app.call(env)
      rescue Error => e
        raise # Don't capture Opbeat errors
      rescue Exception => e
        evt = Event.capture_rack_exception(e, env)
        Opbeat.send(evt)
        raise
      end

      error = env['rack.exception'] || env['sinatra.error']

      if error
        evt = Event.capture_rack_exception(error, env)
        Opbeat.send(evt) if evt
      end

      response
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
opbeat-0.9.2 lib/opbeat/rack.rb
opbeat-0.9.1 lib/opbeat/rack.rb
opbeat-0.9.0 lib/opbeat/rack.rb
opbeat-0.8.0 lib/opbeat/rack.rb
opbeat-0.7.1 lib/opbeat/rack.rb
opbeat-0.7.0 lib/opbeat/rack.rb
opbeat-0.6.1 lib/opbeat/rack.rb