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

#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
# File 'lib/rollbar/middleware/rack.rb', line 15

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

#fetch_scope(env) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/rollbar/middleware/rack.rb', line 30

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

#framework_error(env) ⇒ Object



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

def framework_error(env)
  nil
end

#person_data_proc(env) ⇒ Object



40
41
42
# File 'lib/rollbar/middleware/rack.rb', line 40

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