How to use the bugsnag.utils.ThreadLocals.get_instance function in bugsnag

To help you get started, we’ve selected a few bugsnag examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bugsnag / bugsnag-python / tests / test_sessiontracker.py View on Github external
def test_session_tracker_sessions_are_unique(self):
        tracker = SessionTracker(self.config)
        tracker.auto_sessions = True
        locs = ThreadLocals.get_instance()
        tracker.start_session()
        session_one = locs.get_item('bugsnag-session').copy()
        tracker.start_session()
        session_two = locs.get_item('bugsnag-session').copy()
        self.assertNotEqual(session_one['id'], session_two['id'])
github bugsnag / bugsnag-python / tests / test_utils.py View on Github external
def test_thread_locals(self):
        key = "TEST_THREAD_LOCALS"
        val = {"Test": "Thread", "Locals": "Here"}
        locs = ThreadLocals.get_instance()
        self.assertFalse(locs.has_item(key))
        locs.set_item(key, val)
        self.assertTrue(locs.has_item(key))
        item = locs.get_item(key)
        self.assertEqual(item, val)
        locs.del_item(key)
        self.assertFalse(locs.has_item(key))
        item = locs.get_item(key, "default")
        self.assertEqual(item, "default")
github bugsnag / bugsnag-python / tests / test_sessiontracker.py View on Github external
def test_session_tracker_stores_session_in_threadlocals(self):
        locs = ThreadLocals.get_instance()
        tracker = SessionTracker(self.config)
        tracker.auto_sessions = True
        tracker.start_session()
        session = locs.get_item('bugsnag-session')
        self.assertTrue('id' in session)
        self.assertTrue('startedAt' in session)
        self.assertTrue('events' in session)
        self.assertTrue('handled' in session['events'])
        self.assertTrue('unhandled' in session['events'])
        self.assertEqual(session['events']['handled'], 0)
        self.assertEqual(session['events']['unhandled'], 0)
github bugsnag / bugsnag-python / bugsnag / sessiontracker.py View on Github external
def start_session(self):
        if not self.auto_sessions and self.config.auto_capture_sessions:
            self.auto_sessions = True
            self.__start_delivery()
        start_time = strftime('%Y-%m-%dT%H:%M:00', gmtime())
        new_session = {
            'id': uuid4().hex,
            'startedAt': start_time,
            'events': {
                'handled': 0,
                'unhandled': 0
            }
        }
        tls = ThreadLocals.get_instance()
        tls.set_item("bugsnag-session", new_session)
        self.__queue_session(start_time)
github bugsnag / bugsnag-python / bugsnag / sessiontracker.py View on Github external
def __call__(self, notification):
        tls = ThreadLocals.get_instance()
        session = tls.get_item('bugsnag-session', {}).copy()
        if session:
            if notification.unhandled:
                session['events']['unhandled'] += 1
            else:
                session['events']['handled'] += 1
            notification.session = session
        self.bugsnag(notification)
github bugsnag / bugsnag-python / bugsnag / configuration.py View on Github external
def get_instance(cls):  # type: () -> RequestConfiguration
        """
        Get this thread's instance of the RequestConfiguration.
        """
        tls = ThreadLocals.get_instance()
        instance = tls.get_item("bugsnag", None)
        if not instance:
            instance = RequestConfiguration()
            tls.set_item("bugsnag", instance)

        return instance
github bugsnag / bugsnag-python / bugsnag / configuration.py View on Github external
def clear(cls):
        """
        Clear this thread's instance of the RequestConfiguration.
        """
        tls = ThreadLocals.get_instance()
        if tls.has_item("bugsnag"):
            tls.del_item("bugsnag")