class Timber::Integrations::Rack::SessionContext
A Rack
middleware that is responsible for adding the Session context {Timber::Contexts::Session}.
Public Instance Methods
call(env)
click to toggle source
# File lib/timber-rack/session_context.rb, line 11 def call(env) id = get_session_id(env) if id context = Contexts::Session.new(id: id) CurrentContext.with(context) do @app.call(env) end else @app.call(env) end end
Private Instance Methods
get_session_id(env)
click to toggle source
# File lib/timber-rack/session_context.rb, line 24 def get_session_id(env) if session = env['rack.session'] if session.respond_to?(:id) Timber::Config.instance.debug { "Rack env session detected, using id attribute" } session.id elsif session.respond_to?(:[]) Timber::Config.instance.debug { "Rack env session detected, using the session_id key" } session["session_id"] else Timber::Config.instance.debug { "Rack env session detected but could not extract id" } nil end else Timber::Config.instance.debug { "No session data could be detected, skipping" } nil end rescue Exception => e nil end