def _handle_request_exception(self, exc): options = { "user": { "id": self.request.remote_ip }, "context": self._get_context(), "request": { "url": self.request.full_url(), "method": self.request.method, "arguments": self.request.arguments, } } # Notify bugsnag, unless it's an HTTPError that we specifically want # to ignore should_notify_bugsnag = True if type(exc) == HTTPError: ignore_status_codes = self.bugsnag_ignore_status_codes() if ignore_status_codes and exc.status_code in ignore_status_codes: should_notify_bugsnag = False if should_notify_bugsnag: bugsnag.auto_notify(exc, **options) # Call the parent handler RequestHandler._handle_request_exception(self, exc)
def _handle_request_exception(self, exc): options = { "user": {"id": self.request.remote_ip}, "context": self._get_context(), "request": { "url": self.request.full_url(), "method": self.request.method, "arguments": self.request.arguments, }, "severity_reason": { "type": "unhandledExceptionMiddleware", "attributes": { "framework": "Tornado" } } } # Notify bugsnag, unless it's an HTTPError that we specifically want # to ignore should_notify_bugsnag = True if type(exc) == HTTPError: ignore_status_codes = self.bugsnag_ignore_status_codes() if ignore_status_codes and exc.status_code in ignore_status_codes: should_notify_bugsnag = False if should_notify_bugsnag: bugsnag.auto_notify(exc, **options) # Call the parent handler RequestHandler._handle_request_exception(self, exc)
def _handle_request_exception(self, exc: BaseException): options = { "user": { "id": self.request.remote_ip }, "context": self._get_context(), "request": { "url": self.request.full_url(), "method": self.request.method, "arguments": self.request.arguments, }, "severity_reason": { "type": "unhandledExceptionMiddleware", "attributes": { "framework": "Tornado" } } } # Notify bugsnag, unless it's an HTTPError that we specifically want # to ignore should_notify_bugsnag = True if isinstance(exc, HTTPError): ignore_status_codes = self.bugsnag_ignore_status_codes() if ignore_status_codes and exc.status_code in ignore_status_codes: should_notify_bugsnag = False if should_notify_bugsnag: bugsnag.auto_notify(exc, **options) # Call the parent handler RequestHandler._handle_request_exception(self, exc) # type: ignore
def __log_exception(sender, exception, **extra): bugsnag.auto_notify(exception, severity_reason={ "type": "unhandledExceptionMiddleware", "attributes": { "framework": "Flask" } })
def failure_handler(sender, task_id, exception, args, kwargs, traceback, einfo, **kw): task = {"task_id": task_id, "args": args, "kwargs": kwargs} bugsnag.auto_notify(exception, traceback=traceback, context=sender.name, extra_data=task)
def __iter__(self): try: for response in self.app: yield response except Exception as e: bugsnag.auto_notify(e) raise
def __iter__(self): try: for response in self.app: yield response except Exception as e: bugsnag.auto_notify(e, severity_reason=self.SEVERITY_REASON) raise
def close(self): try: if hasattr(self.app, 'close'): return self.app.close() except Exception as e: bugsnag.auto_notify(e) raise finally: bugsnag.clear_request_config()
def test_auto_notify_defaults(self): bugsnag.auto_notify(ScaryException("unexpected failover")) json_body = self.server.received[0]['json_body'] event = json_body['events'][0] self.assertTrue(event['unhandled']) self.assertEqual(event['severity'], 'error') self.assertEqual(event['severityReason'], {"type": "unhandledException"})
async def __call__(self, scope, receive, send): bugsnag.configure_request(asgi_scope=scope) try: if bugsnag.configuration.auto_capture_sessions: bugsnag.start_session() await self.app(scope, receive, send) except Exception as e: bugsnag.auto_notify(e, severity_reason=SEVERITY_REASON) raise
def close(self): try: if hasattr(self.app, 'close'): return self.app.close() except Exception as e: bugsnag.auto_notify(e, severity_reason=self.SEVERITY_REASON) raise finally: bugsnag.clear_request_config()
def test_auto_notify_defaults(self): bugsnag.auto_notify(ScaryException("unexpected failover")) json_body = self.server.received[0]['json_body'] event = json_body['events'][0] self.assertTrue(event['unhandled']) self.assertEqual(event['severity'], 'error') self.assertEqual(event['severityReason'], { "type": "unhandledException" })
def process_exception(self, request, exception): try: bugsnag.auto_notify(exception) except Exception: bugsnag.logger.exception('Error in exception middleware') bugsnag.clear_request_config() return None
def __init__(self, application, environ, start_response): self.environ = environ bugsnag.configure_request(wsgi_environ=self.environ) try: self.app = application(environ, start_response) except Exception as e: bugsnag.auto_notify(e) raise
def process_exception(self, request, exception): try: bugsnag.auto_notify(exception) except Exception as exc: bugsnag.log("Error in exception middleware: %s" % exc) bugsnag.clear_request_config() return None
def failure_handler(sender, task_id, exception, args, kwargs, traceback, einfo, **kw): task = { "task_id": task_id, "args": args, "kwargs": kwargs } bugsnag.auto_notify(exception, traceback=traceback, context=sender.name, extra_data=task)
def __iter__(self): try: for response in self.app: yield response except Exception as e: bugsnag.auto_notify( e, severity_reason=self.SEVERITY_REASON ) raise
def __init__(self, application, environ, start_response): self.environ = environ bugsnag.configure_request(wsgi_environ=self.environ) try: if bugsnag.configuration.auto_capture_sessions: bugsnag.start_session() self.app = application(environ, start_response) except Exception as e: bugsnag.auto_notify(e, severity_reason=self.SEVERITY_REASON) raise
def close(self): try: if hasattr(self.app, 'close'): return self.app.close() except Exception as e: bugsnag.auto_notify( e, severity_reason=self.SEVERITY_REASON ) raise finally: bugsnag.clear_request_config()
def failure_handler(sender, task_id, exception, args, kwargs, traceback, einfo, **kw): task = {"task_id": task_id, "args": args, "kwargs": kwargs} bugsnag.auto_notify(exception, traceback=traceback, context=sender.name, extra_data=task, severity_reason={ 'type': 'unhandledExceptionMiddleware', 'attributes': { 'framework': 'Celery' } })
def __init__(self, application, environ, start_response): self.environ = environ bugsnag.configure_request(wsgi_environ=self.environ) try: if bugsnag.configuration.auto_capture_sessions: bugsnag.start_session() self.app = application(environ, start_response) except Exception as e: bugsnag.auto_notify( e, severity_reason=self.SEVERITY_REASON ) raise
def handle_exception(exception, env): request = Request(env) bugsnag.configure_request( context="%s %s" % (request.method, request_path(env)), user_id=request.remote_addr, request_data={ "url": request.base_url, "headers": dict(request.headers), "cookies": dict(request.cookies), "params": dict(request.form), }, environment_data=dict(request.environ), ) bugsnag.auto_notify(exception) bugsnag.clear_request_config()
def __log_exception(sender, exception, **extra): bugsnag.configure_request( context="%s %s" % (request.method, request_path(request.environ)), user_id=request.remote_addr, request_data={ "url": request.base_url, "headers": dict(request.headers), "cookies": dict(request.cookies), "params": dict(request.form), }, session_data=dict(session), environment_data=dict(request.environ), ) bugsnag.auto_notify(exception) bugsnag.clear_request_config()
def process_exception(self, request, exception): try: bugsnag.auto_notify( exception, severity_reason={ "type": "unhandledExceptionMiddleware", "attributes": { "framework": "Django" } } ) except Exception: bugsnag.logger.exception("Error in exception middleware") bugsnag.clear_request_config() return None
async def bugsnag_app(self, scope: Scope, receive: Receive, send: Send) -> None: bugsnag.configure_request(scope=scope) inner = self.app try: await inner(scope, receive, send) except Exception as exc: bugsnag.configure_request(frame_locals=self.get_locals(exc)) bugsnag.auto_notify(exc, severity_reason={ "type": "unhandledExceptionMiddleware", "attributes": { "framework": "Starlette" } }) raise exc from None finally: bugsnag.clear_request_config()
def failure_handler(sender, task_id, exception, args, kwargs, traceback, einfo, **kw): """ Overriding configuration in bugsnag.celery in order to set the severity to warning instead of error. """ task = {"task_id": task_id, "args": args, "kwargs": kwargs} bugsnag.auto_notify( exception, traceback=traceback, context=sender.name, extra_data=task, severity='warning', # adding this to original code severity_reason={ 'type': 'unhandledExceptionMiddleware', 'attributes': { 'framework': 'Celery' } })
def failure_handler(sender, task_id, exception, args, kwargs, traceback, einfo, **kw): """ Overriding configuration in bugsnag.celery in order to set the severity to warning instead of error. """ task = { "task_id": task_id, "args": args, "kwargs": kwargs } bugsnag.auto_notify(exception, traceback=traceback, context=sender.name, extra_data=task, severity='warning', # adding this to original code severity_reason={ 'type': 'unhandledExceptionMiddleware', 'attributes': { 'framework': 'Celery' } })
def test_auto_notify_overrides(self): bugsnag.auto_notify(ScaryException("unexpected failover"), severity='info', unhandled=False, severity_reason={ "type": "middleware_handler", "attributes": { "name": "test middleware" } }) json_body = self.server.received[0]['json_body'] event = json_body['events'][0] self.assertFalse(event['unhandled']) self.assertEqual(event['severity'], 'info') self.assertEqual( event['severityReason'], { "type": "middleware_handler", "attributes": { "name": "test middleware" } })
def test_auto_notify_overrides(self): bugsnag.auto_notify( ScaryException("unexpected failover"), severity='info', unhandled=False, severity_reason={ "type": "middleware_handler", "attributes": { "name": "test middleware" } } ) json_body = self.server.received[0]['json_body'] event = json_body['events'][0] self.assertFalse(event['unhandled']) self.assertEqual(event['severity'], 'info') self.assertEqual(event['severityReason'], { "type": "middleware_handler", "attributes": { "name": "test middleware" } })
def _handle_request_exception(self, exc): options = { "user": {"ip": self.request.remote_ip, "id": getattr(self, "current_user_id", 0)}, "context": self._get_context(), "request": { "url": self.request.full_url(), "method": self.request.method, "arguments": self.request.arguments, } } # Notify bugsnag, unless it's an HTTPError that we specifically want to ignore should_notify_bugsnag = True if type(exc) == HTTPError: if (exc.status_code<500 and exc.status_code>=400): should_notify_bugsnag = False if should_notify_bugsnag: bugsnag.auto_notify(exc, **options) # Call the parent handler _RequestHandler._handle_request_exception(self, exc)
def _handle_request_exception(self, exc): options = { "user": {"id": self.request.remote_ip}, "context": self._get_context(), "request": { "url": self.request.full_url(), "method": self.request.method, "arguments": self.request.arguments, }, } # Notify bugsnag, unless it's an HTTPError that we specifically want to ignore should_notify_bugsnag = True if type(exc) == HTTPError: ignore_status_codes = self.bugsnag_ignore_status_codes() if ignore_status_codes and exc.status_code in ignore_status_codes: should_notify_bugsnag = False if should_notify_bugsnag: bugsnag.auto_notify(exc, **options) # Call the parent handler RequestHandler._handle_request_exception(self, exc)
def __log_exception(sender, exception, **extra): bugsnag.auto_notify(exception)