Class: Bugsnag::Middleware::Rails3Request

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

Instance Method Summary collapse

Constructor Details

#initialize(bugsnag) ⇒ Rails3Request

Returns a new instance of Rails3Request.



3
4
5
# File 'lib/bugsnag/middleware/rails3_request.rb', line 3

def initialize(bugsnag)
  @bugsnag = bugsnag
end

Instance Method Details

#call(notification) ⇒ Object



7
8
9
10
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
39
40
# File 'lib/bugsnag/middleware/rails3_request.rb', line 7

def call(notification)
  if notification.request_data[:rack_env]
    env = notification.request_data[:rack_env]
    params = env["action_dispatch.request.parameters"]

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

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

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

    notification.user_id = env["action_dispatch.remote_ip"]

    # Add the rails version
    if notification.configuration.send_environment
      notification.add_tab(:environment, {
        :railsVersion => Rails::VERSION::STRING
      })
    end
  end

  @bugsnag.call(notification)
end