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 = Event(Exception('shucks'), self.config, None) middleware(event) assert event.session['events']['unhandled'] == 0 assert event.session['events']['handled'] == 1 event2 = Event(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
def __call__(self, event: Event): session = _session_info.get() if session: if event.unhandled: session['events']['unhandled'] += 1 else: session['events']['handled'] += 1 event.session = deepcopy(session) self.bugsnag(event)
def notify(self, exception: BaseException, asynchronous=None, **options): """ Notify bugsnag of an exception. >>> client.notify(Exception('Example')) # doctest: +SKIP """ event = Event(exception, self.configuration, RequestConfiguration.get_instance(), **options) self.deliver(event, asynchronous=asynchronous)
def notify_exc_info(self, exc_type, exc_value, traceback, asynchronous=None, **options): """ Notify bugsnag of an exception via exc_info. >>> client.notify_exc_info(*sys.exc_info()) # doctest: +SKIP """ exception = exc_value options['traceback'] = traceback event = Event(exception, self.configuration, RequestConfiguration.get_instance(), **options) self.deliver(event, asynchronous=asynchronous)
def test_path_supports_ascii_characters(self): import bugsnag.wsgi.middleware environ = self.environ.copy() environ['PATH_INFO'] = '/hello/world' bugsnag.configure_request(wsgi_environ=environ) config = Configuration() event = Event(Exception("oops"), config, RequestConfiguration.get_instance()) bugsnag.wsgi.middleware.add_wsgi_request_data_to_notification(event) self.assertEqual('http://localhost/hello/world', event.metadata['request']['url'])
def test_path_supports_non_ascii_characters(self): import bugsnag.wsgi.middleware environ = self.environ.copy() environ['PATH_INFO'] = '/ôßłガ' config = Configuration() event = Event(Exception("oops"), config, RequestConfiguration.get_instance()) bugsnag.configure_request(wsgi_environ=environ) bugsnag.wsgi.middleware.add_wsgi_request_data_to_notification(event) # You can validate this by using "encodeURIComponent" in a browser. self.assertEqual('http://localhost/%C3%B4%C3%9F%C5%82%E3%82%AC', event.metadata['request']['url'])
def test_wrongly_encoded_url_should_not_raise(self): import bugsnag.wsgi.middleware environ = self.environ.copy() environ['PATH_INFO'] = '/%83' bugsnag.configure_request(wsgi_environ=environ) config = Configuration() event = Event(Exception("oops"), config, RequestConfiguration.get_instance()) bugsnag.wsgi.middleware.add_wsgi_request_data_to_notification(event) # We have to use "urllib.parse.quote" here because the exact output # differs on different Python versions because of how they handle # invalid encoding sequences self.assertEqual('http://localhost/%s' % quote('%83'), event.metadata['request']['url'])
def invoke_exception_on_other_file(config): from bugsnag.event import Event return Event(Exception("another file!"), config, {})
def __call__(self, event: Event): config = event.request_config event.set_user(id=config.user_id) event.set_user(**config.user) if not event.context: event.context = config.get("context") for name, dictionary in config.metadata.items(): if name in event.metadata: for key, value in dictionary.items(): if key not in event.metadata[name]: event.metadata[name][key] = value else: event.add_tab(name, dictionary) event.add_tab("request", config.get("request_data")) if bugsnag.configure().send_environment: event.add_tab("environment", config.get("environment_data")) event.add_tab("session", config.get("session_data")) event.add_tab("extraData", config.get("extra_data")) self.bugsnag(event)