Sha256: 689e060572dae607181d483f3dd85681682adcdfce0f74759c10ade03e044b90

Contents?: true

Size: 991 Bytes

Versions: 13

Compression:

Stored size: 991 Bytes

Contents

require 'rollbar'
require 'rollbar/exception_reporter'
require 'rollbar/request_data_extractor'

module Rollbar
  module Middleware
    class Sinatra
      include ::Rollbar::ExceptionReporter
      include RequestDataExtractor

      def initialize(app)
        @app = app
      end

      def call(env)
        Rollbar.reset_notifier!

        Rollbar.scoped(fetch_scope(env)) do
          begin
            response = @app.call(env)
            report_exception_to_rollbar(env, framework_error(env)) if framework_error(env)
            response
          rescue Exception => e
            report_exception_to_rollbar(env, e)
            raise
          end
        end
      end

      def fetch_scope(env)
        request_data = extract_request_data_from_rack(env)
        { :request => request_data }
      rescue Exception => e
        report_exception_to_rollbar(env, e)
        raise
      end

      def framework_error(env)
        env['sinatra.error']
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rollbar-1.2.12 lib/rollbar/middleware/sinatra.rb
rollbar-1.2.11 lib/rollbar/middleware/sinatra.rb
rollbar-1.2.10 lib/rollbar/middleware/sinatra.rb
rollbar-1.2.9 lib/rollbar/middleware/sinatra.rb
rollbar-1.2.8 lib/rollbar/middleware/sinatra.rb
rollbar-1.2.7 lib/rollbar/middleware/sinatra.rb
rollbar-1.2.6 lib/rollbar/middleware/sinatra.rb
rollbar-1.2.5 lib/rollbar/middleware/sinatra.rb
rollbar-1.2.4 lib/rollbar/middleware/sinatra.rb
rollbar-1.2.3 lib/rollbar/middleware/sinatra.rb
rollbar-1.2.2 lib/rollbar/middleware/sinatra.rb
rollbar-1.2.1 lib/rollbar/middleware/sinatra.rb
rollbar-1.2.0 lib/rollbar/middleware/sinatra.rb