Class: Rollbar::Middleware::Rack

Inherits:
Object
  • Object
show all
Includes:
ExceptionReporter, RequestDataExtractor
Defined in:
lib/rollbar/middleware/rack.rb,
lib/rollbar/middleware/rack/builder.rb,
lib/rollbar/middleware/rack/test_session.rb

Direct Known Subclasses

Sinatra

Defined Under Namespace

Modules: Builder, TestSession

Constant Summary

Constants included from RequestDataExtractor

RequestDataExtractor::ALLOWED_BODY_PARSEABLE_METHODS, RequestDataExtractor::ALLOWED_HEADERS_REGEX

Instance Method Summary collapse

Methods included from RequestDataExtractor

#extract_person_data_from_controller, #extract_request_data_from_rack, #scrub_params, #scrub_url

Methods included from ExceptionReporter

#capture_uncaught?, #exception_data, #log_exception_message, #report_exception_to_rollbar

Constructor Details

#initialize(app) ⇒ Rack

Returns a new instance of Rack.



11
12
13
# File 'lib/rollbar/middleware/rack.rb', line 11

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rollbar/middleware/rack.rb', line 15

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

#fetch_scope(env) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/rollbar/middleware/rack.rb', line 33

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

#framework_error(env) ⇒ Object



47
48
49
# File 'lib/rollbar/middleware/rack.rb', line 47

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

#person_data_proc(env) ⇒ Object



43
44
45
# File 'lib/rollbar/middleware/rack.rb', line 43

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