Skip to content

Ensure session counts on events do not include future events #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

## TBD

### Fixes

* Ensure session counts on events do not increment with future events by copying
the session information into each event

## 3.7.0 (2020-07-27)

### Enhancements
Expand Down
3 changes: 2 additions & 1 deletion bugsnag/sessiontracker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function
from copy import deepcopy
from uuid import uuid4
from time import strftime, gmtime
from threading import Lock, Timer
Expand Down Expand Up @@ -146,5 +147,5 @@ def __call__(self, notification):
session['events']['unhandled'] += 1
else:
session['events']['handled'] += 1
notification.session = session
notification.session = deepcopy(session)
self.bugsnag(notification)
44 changes: 44 additions & 0 deletions tests/test_sessionmiddleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import unittest

from bugsnag.sessiontracker import SessionTracker, SessionMiddleware
from bugsnag.configuration import Configuration
from bugsnag.notification import Notification


class TestSessionMiddleware(unittest.TestCase):
def setUp(self):
self.config = Configuration()
self.config.configure(api_key='fff', auto_capture_sessions=False)
self.sessiontracker = SessionTracker(self.config)
self.sessiontracker.auto_sessions = True # Stub session delivery queue

def tearDown(self):
pass

def test_increment_counts(self):
"""
Every event should keep a list of prior events which occurred in the
session
"""

def next_callable(event):
pass

middleware = SessionMiddleware(next_callable)
self.sessiontracker.start_session()

event = Notification(Exception('shucks'), self.config, None)
middleware(event)

assert event.session['events']['unhandled'] == 0
assert event.session['events']['handled'] == 1

event2 = Notification(Exception('oh no'), self.config, None)
middleware(event2)

assert event2.session['events']['unhandled'] == 0
assert event2.session['events']['handled'] == 2

# Session counts should not change for events already handled
assert event.session['events']['unhandled'] == 0
assert event.session['events']['handled'] == 1