Skip to content

Commit

Permalink
lib/bugsnag/middleware/rack_request: early load session for Rails 4
Browse files Browse the repository at this point in the history
Fixes #144 (Rails 4 sessions appear in custom tab)

Context: rails/rails#10813
  • Loading branch information
kyrylo committed Aug 27, 2014
1 parent ffe26f9 commit f72d846
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/bugsnag/middleware/rack_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def call(notification)
params = request.params rescue {}

session = env["rack.session"]
# Load session for Rails (for Rails 4 it's lazy loaded).
# @see https://github.com/rails/rails/issues/10813
session["session_id"]

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

# Set a sensible default for user_id
Expand All @@ -25,7 +27,6 @@ def call(notification)
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,
Expand All @@ -35,13 +36,18 @@ def call(notification)
:clientIp => request.ip
})

# Add an environment tab
notification.add_tab(:environment, env)

# Add a session tab
notification.add_tab(:session, session) if session
if session
# Rails 3
if session.is_a?(Hash)
notification.add_tab(:session, session)
else
# Rails 4
notification.add_tab(:session, session.to_hash)
end
end

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

0 comments on commit f72d846

Please sign in to comment.