Sha256: 4c36498f79ea0b1a75badebab56f021275469b7c38d251f8d4b28fd8812c78c5

Contents?: true

Size: 1.28 KB

Versions: 11

Compression:

Stored size: 1.28 KB

Contents

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

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

      def initialize(app)
        @app = app
      end

      def call(env)
        Rollbar.reset_notifier!

        Rollbar.scoped(fetch_scope(env)) do
          begin
            Rollbar.notifier.enable_locals
            response = @app.call(env)
            report_exception_to_rollbar(env, framework_error(env)) if framework_error(env)
            response
          rescue Exception => e # rubocop:disable Lint/RescueException
            report_exception_to_rollbar(env, e)
            raise
          ensure
            Rollbar.notifier.disable_locals
          end
        end
      end

      def fetch_scope(env)
        {
          :request => proc { extract_request_data_from_rack(env) },
          :person => person_data_proc(env)
        }
      rescue Exception => e # rubocop:disable Lint/RescueException
        report_exception_to_rollbar(env, e)
        raise
      end

      def person_data_proc(env)
        proc { extract_person_data_from_controller(env) }
      end

      def framework_error(env)
        env['rack.exception']
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rollbar-3.6.0 lib/rollbar/middleware/rack.rb
rollbar-3.5.2 lib/rollbar/middleware/rack.rb
rollbar-3.5.1 lib/rollbar/middleware/rack.rb
rollbar-3.5.0 lib/rollbar/middleware/rack.rb
rollbar-3.4.2 lib/rollbar/middleware/rack.rb
rollbar-3.4.1 lib/rollbar/middleware/rack.rb
rollbar-3.4.0 lib/rollbar/middleware/rack.rb
rollbar-3.3.3 lib/rollbar/middleware/rack.rb
rollbar-3.3.2 lib/rollbar/middleware/rack.rb
rollbar-3.3.1 lib/rollbar/middleware/rack.rb
rollbar-3.3.0 lib/rollbar/middleware/rack.rb