Class: Bugsnag::Middleware::Rails3Request

Inherits:
Object
  • Object
show all
Defined in:
lib/bugsnag/middleware/rails3_request.rb

Overview

Extracts and attaches rails and rack environment data to an error report

Constant Summary collapse

SPOOF =
"[SPOOF]".freeze

Instance Method Summary collapse

Constructor Details

#initialize(bugsnag) ⇒ Rails3Request

Returns a new instance of Rails3Request.



7
8
9
# File 'lib/bugsnag/middleware/rails3_request.rb', line 7

def initialize(bugsnag)
  @bugsnag = bugsnag
end

Instance Method Details

#call(report) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bugsnag/middleware/rails3_request.rb', line 11

def call(report)
  if report.request_data[:rack_env]
    env = report.request_data[:rack_env]
    params = env["action_dispatch.request.parameters"]
    client_ip = env["action_dispatch.remote_ip"].to_s rescue SPOOF

    if params
      # Set the automatic context
      report.automatic_context = "#{params[:controller]}##{params[:action]}"

      # Augment the request tab
      report.add_tab(:request, {
        :railsAction => "#{params[:controller]}##{params[:action]}",
        :params => params
      })
    end

    # Use action_dispatch.remote_ip for IP address fields and send request id
    report.add_tab(:request, {
      :clientIp => client_ip,
      :requestId => env["action_dispatch.request_id"]
    })

    report.user["id"] = client_ip
  end

  @bugsnag.call(report)
end