Class: Bugsnag::SessionTracker
- Inherits:
-
Object
- Object
- Bugsnag::SessionTracker
- Defined in:
- lib/bugsnag/session_tracker.rb
Constant Summary collapse
- THREAD_SESSION =
"bugsnag_session"
- SESSION_PAYLOAD_VERSION =
"1.0"
- MUTEX =
Mutex.new
Instance Attribute Summary collapse
-
#session_counts ⇒ Object
readonly
Returns the value of attribute session_counts.
Class Method Summary collapse
-
.get_current_session ⇒ Object
Returns the session information for this thread.
-
.set_current_session(session) ⇒ Object
Sets the session information for this thread.
Instance Method Summary collapse
-
#initialize ⇒ SessionTracker
constructor
Initializes the session tracker.
-
#send_sessions ⇒ Object
Delivers the current session_counts lists to the session endpoint.
-
#start_session ⇒ Object
(also: #create_session)
Starts a new session, storing it on the current thread.
Constructor Details
#initialize ⇒ SessionTracker
Initializes the session tracker.
29 30 31 |
# File 'lib/bugsnag/session_tracker.rb', line 29 def initialize @session_counts = Concurrent::Hash.new(0) end |
Instance Attribute Details
#session_counts ⇒ Object (readonly)
Returns the value of attribute session_counts.
13 14 15 |
# File 'lib/bugsnag/session_tracker.rb', line 13 def session_counts @session_counts end |
Class Method Details
.get_current_session ⇒ Object
Returns the session information for this thread.
23 24 25 |
# File 'lib/bugsnag/session_tracker.rb', line 23 def self.get_current_session Thread.current[THREAD_SESSION] end |
.set_current_session(session) ⇒ Object
Sets the session information for this thread.
17 18 19 |
# File 'lib/bugsnag/session_tracker.rb', line 17 def self.set_current_session(session) Thread.current[THREAD_SESSION] = session end |
Instance Method Details
#send_sessions ⇒ Object
Delivers the current session_counts lists to the session endpoint.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/bugsnag/session_tracker.rb', line 57 def send_sessions sessions = [] counts = @session_counts @session_counts = Concurrent::Hash.new(0) counts.each do |min, count| sessions << { :startedAt => min, :sessionsStarted => count } end deliver(sessions) end |
#start_session ⇒ Object Also known as: create_session
Starts a new session, storing it on the current thread.
This allows Bugsnag to track error rates for a release.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bugsnag/session_tracker.rb', line 37 def start_session return unless Bugsnag.configuration.enable_sessions start_delivery_thread start_time = Time.now().utc().strftime('%Y-%m-%dT%H:%M:00') new_session = { :id => SecureRandom.uuid, :startedAt => start_time, :events => { :handled => 0, :unhandled => 0 } } SessionTracker.set_current_session(new_session) add_session(start_time) end |