class Rollbar::Middleware::Rails::RollbarMiddleware

Public Class Methods

new(app) click to toggle source
# File lib/rollbar/middleware/rails/rollbar.rb, line 11
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/rollbar/middleware/rails/rollbar.rb, line 15
def call(env)
  self.request_data = nil

  Rollbar.reset_notifier!

  env['rollbar.scope'] = scope = fetch_scope(env)

  Rollbar.scoped(scope) do
    begin
      Rollbar.notifier.enable_locals
      response = @app.call(env)

      if (framework_exception = env['action_dispatch.exception'])
        report_exception_to_rollbar(env, framework_exception)
      end

      response
    rescue Exception => e # rubocop:disable Lint/RescueException
      report_exception_to_rollbar(env, e)
      raise
    ensure
      Rollbar.notifier.disable_locals
    end
  end
end
context(request_data) click to toggle source
# File lib/rollbar/middleware/rails/rollbar.rb, line 79
def context(request_data)
  route_params = request_data[:params]

  # make sure route is a hash built by RequestDataExtractor
  return unless route_params.is_a?(Hash) && !route_params.empty?

  "#{route_params[:controller]}##{route_params[:action]}"
end
extract_request_data(env) click to toggle source
# File lib/rollbar/middleware/rails/rollbar.rb, line 60
def extract_request_data(env)
  extract_request_data_from_rack(env)
end
fetch_scope(env) click to toggle source
# File lib/rollbar/middleware/rails/rollbar.rb, line 41
def fetch_scope(env)
  # Scope a new notifier with request data and a Proc for person data
  # for any reports that happen while a controller is handling a request

  {
    :request => proc { request_data(env) },
    :person => person_data_proc(env),
    :context => proc { context(request_data(env)) }
  }
end
person_data_proc(env) click to toggle source
# File lib/rollbar/middleware/rails/rollbar.rb, line 64
def person_data_proc(env)
  block = proc { extract_person_data_from_controller(env) }
  unless defined?(ActiveRecord::Base) && ActiveRecord::Base.connected?
    return block
  end

  proc do
    begin
      ActiveRecord::Base.connection_pool.with_connection(&block)
    rescue ActiveRecord::ConnectionTimeoutError
      {}
    end
  end
end
request_data(env) click to toggle source
# File lib/rollbar/middleware/rails/rollbar.rb, line 52
def request_data(env)
  Thread.current[:'_rollbar.rails.request_data'] ||= extract_request_data(env)
end
request_data=(value) click to toggle source
# File lib/rollbar/middleware/rails/rollbar.rb, line 56
def request_data=(value)
  Thread.current[:'_rollbar.rails.request_data'] = value
end