Sha256: bef2a8d3b43d4eb812f490905615dc555ab0543f18dd8e150c381d4adb1e0827

Contents?: true

Size: 1.47 KB

Versions: 27

Compression:

Stored size: 1.47 KB

Contents

module Bugsnag::Middleware
  class RackRequest
    def initialize(bugsnag)
      @bugsnag = bugsnag
    end
      
    def call(notification)
      if notification.request_data[:rack_env]
        env = notification.request_data[:rack_env]

        request = ::Rack::Request.new(env)
        params = request.params
        session = env["rack.session"]

        # Set the context
        notification.context = "#{request.request_method} #{request.path}"

        # Set a sensible default for user_id
        notification.user_id = request.ip

        # Build the clean url (hide the port if it is obvious)
        url = "#{request.scheme}://#{request.host}"
        url << ":#{request.port}" unless [80, 443].include?(request.port)
        url << Bugsnag::Helpers.cleanup_url(request.fullpath, notification.configuration.params_filters)

        # Add a request tab
        notification.add_tab(:request, {
          :url => url,
          :httpMethod => request.request_method,
          :params => params.to_hash,
          :userAgent => request.user_agent,
          :referer => request.referer,
          :clientIp => request.ip
        })
          
        # Add an environment tab
        notification.add_tab(:environment, env)

        # Add a session tab
        notification.add_tab(:session, session) if session

        # Add a cookies tab
        cookies = request.cookies
        notification.add_tab(:cookies, cookies) if cookies
      end

      @bugsnag.call(notification)
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
bugsnag-2.2.0 lib/bugsnag/middleware/rack_request.rb
bugsnag-2.1.0 lib/bugsnag/middleware/rack_request.rb
bugsnag-2.0.3 lib/bugsnag/middleware/rack_request.rb
bugsnag-2.0.2 lib/bugsnag/middleware/rack_request.rb
bugsnag-2.0.1 lib/bugsnag/middleware/rack_request.rb
bugsnag-2.0.0 lib/bugsnag/middleware/rack_request.rb
bugsnag-1.8.8 lib/bugsnag/middleware/rack_request.rb
bugsnag-1.8.7 lib/bugsnag/middleware/rack_request.rb
bugsnag-1.8.6 lib/bugsnag/middleware/rack_request.rb
bugsnag-1.8.5 lib/bugsnag/middleware/rack_request.rb
bugsnag-1.8.4 lib/bugsnag/middleware/rack_request.rb
bugsnag-1.8.3 lib/bugsnag/middleware/rack_request.rb
bugsnag-1.8.2 lib/bugsnag/middleware/rack_request.rb
bugsnag-1.8.1 lib/bugsnag/middleware/rack_request.rb
bugsnag-1.8.0 lib/bugsnag/middleware/rack_request.rb
bugsnag-1.7.0 lib/bugsnag/middleware/rack_request.rb
bugsnag-1.6.5 lib/bugsnag/middleware/rack_request.rb
bugsnag-1.6.4 lib/bugsnag/middleware/rack_request.rb
bugsnag-1.6.3 lib/bugsnag/middleware/rack_request.rb
bugsnag-1.6.2 lib/bugsnag/middleware/rack_request.rb