Capturing sessions

BugSnag tracks the number of “sessions” that happen within your application. This allows you to compare stability scores between releases and helps you to understand the quality of your releases.

Automatic tracking

BugSnag does not track sessions automatically in Sidekiq applications.

Manual session handling

You can manage the session lifecycle using the start_session, pause_session and resume_session methods on the Bugsnag client.

You should call these methods at the appropriate time in your application’s lifecycle when you wish to have an active session. Any errors which occur in your application outside of a session will still be reported to BugSnag but will not count towards your application’s stability score.

start_session

Starts a new session to which subsequent handled and unhandled events will be attributed to.

Bugsnag.start_session

If there is already an active session, it will be replaced with a new one. Use resume_session if you only want to start a session when one doesn’t already exist.

pause_session

Prevents further events being attributed to the current session until the session is resumed or a new session is started.

Bugsnag.pause_session

This can be advantageous if, for example, you do not wish the stability score to include crashes in a background service.

resume_session

Resumes tracking events against the current session, if it was previously paused. If there is was no previous session, a new session is started. This method returns true if there was a session to resume and returns false if a new session was created or the current session was not paused.

if Bugsnag.resume_session
  # a paused session has been resumed
else
  # a new session was created or the current session was not paused
end

The current session

Information about the current session is available on the SessionTracker:

current_session = Bugsnag::SessionTracker.get_current_session

if current_session.nil?
  # no session has been started
else
  puts current_session
end

The current session is a Hash containing the following data:

key type description
:id String A UUID for the session
:startedAt String The time that the session was started
:paused? Boolean Whether the session is currently paused
:events Hash A hash containing the number of handled and unhandled events attributed to this session. These are stored under the :handled and :unhandled keys