def capture_exception( self, error=None # type: Optional[Union[BaseException, ExcInfo]] ): # type: (...) -> Optional[str] """Captures an exception. :param error: An exception to catch. If `None`, `sys.exc_info()` will be used. :returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.Client.capture_event`). """ client = self.client if client is None: return None if error is not None: exc_info = exc_info_from_error(error) else: exc_info = sys.exc_info() event, hint = event_from_exception(exc_info, client_options=client.options) try: return self.capture_event(event, hint=hint) except Exception: self._capture_internal_exception(sys.exc_info()) return None
def capture_exception( self, error=None # type: Optional[BaseException] ): # type: (...) -> Optional[str] """Captures an exception. The argument passed can be `None` in which case the last exception will be reported, otherwise an exception object or an `exc_info` tuple. """ client = self.client if client is None: return None if error is None: exc_info = sys.exc_info() else: exc_info = exc_info_from_error(error) event, hint = event_from_exception(exc_info, client_options=client.options) try: return self.capture_event(event, hint=hint) except Exception: self._capture_internal_exception(sys.exc_info()) return None
def _capture_exception(exc_info, hub): # type: (ExcInfo, Hub) -> None client = hub.client client_options = client.options # type: ignore mechanism = {"type": "spark", "handled": False} exc_info = exc_info_from_error(exc_info) exc_type, exc_value, tb = exc_info rv = [] # On Exception worker will call sys.exit(-1), so we can ignore SystemExit and similar errors for exc_type, exc_value, tb in walk_exception_chain(exc_info): if exc_type not in (SystemExit, EOFError, ConnectionResetError): rv.append( single_exception_from_error_tuple(exc_type, exc_value, tb, client_options, mechanism)) if rv: rv.reverse() hint = event_hint_with_exc_info(exc_info) event = {"level": "error", "exception": {"values": rv}} _tag_task_context() hub.capture_event(event, hint=hint)
async def error_middleware(request, handler): request['start_time'] = get_request_start(request) try: r = await handler(request) except HTTPException as e: should_warn_ = request.app.get('middleware_should_warn') or should_warn if should_warn_(e): await log_warning(request, e) raise except Exception as exc: message, event = await event_extra(request, exception_extra=exc_extra(exc)) # make sure these errors appear independently event['fingerprint'] += (repr(exc), ) message += f', {exc!r}' logger.exception(message, extra=event) exc_data, hint = event_from_exception(exc_info_from_error(exc)) event.update(exc_data) event.update(level='error', message=message) capture_event(event, hint) raise HTTPInternalServerError() from exc else: # TODO cope with case that r is not a response should_warn_ = request.app.get('middleware_should_warn') or should_warn if should_warn_(r): await log_warning(request, r) return r
async def log_warning(request: Request, response: Optional[Response]): message, event = await event_extra(request, response) logger.warning(message, extra=event) event['message'] = message if isinstance(response, Exception): exc_data, hint = event_from_exception(exc_info_from_error(response)) event.update(exc_data) capture_event(event, hint) else: capture_event(event)
def handle_error(self, context, handler, exception): req = handler.request exc_info = exc_info_from_error(exception) with sentry_sdk.push_scope() as scope: event, hint = event_from_exception(exc_info) event["request"] = { "url": req.full_url(), "method": req.method, "data": req.arguments, "query_string": req.query, "headers": req.headers, "body": req.body, } scope.set_extra('thumbor-version', __version__) sentry_sdk.capture_event(event, hint=hint)
def handle_error(self, context, handler, exception): # pylint: disable=unused-argument req = handler.request exc_info = exc_info_from_error(exception) with sentry_sdk.push_scope() as scope: event, hint = event_from_exception(exc_info) event["request"] = { "url": req.full_url(), "method": req.method, "data": req.arguments, "query_string": req.query, "headers": req.headers, "body": req.body, } scope.set_extra("thumbor-version", __version__) scope.set_extra("thumbor-loader", self.config.LOADER) scope.set_extra("thumbor-storage", self.config.STORAGE) sentry_sdk.capture_event(event, hint=hint)
def capture_exception(self, error=None): """Captures an exception. The argument passed can be `None` in which case the last exception will be reported, otherwise an exception object or an `exc_info` tuple. """ client = self.client if client is None: return if error is None: exc_info = sys.exc_info() else: exc_info = exc_info_from_error(error) event, hint = event_from_exception( exc_info, with_locals=client.options["with_locals"]) try: return self.capture_event(event, hint=hint) except Exception: self._capture_internal_exception(sys.exc_info())
async def log(self, request: Request, *, exc: Optional[Exception] = None, response: Optional[Response] = None) -> None: event_data = await request_log_extra(request, exc, response) event_data['user'] = await self.user_info(request) view_ref = event_data['transaction'] if exc: level = 'error' message = f'"{line_one(request)}", {exc!r}' fingerprint = view_ref, request.method, repr(exc) request_logger.exception(message, extra=event_data) else: assert response is not None level = 'warning' message = f'"{line_one(request)}", unexpected response: {response.status_code}' request_logger.warning(message, extra=event_data) fingerprint = view_ref, request.method, str(response.status_code) if glove.settings.sentry_dsn: hint = None if exc: exc_data, hint = event_from_exception(exc_info_from_error(exc)) event_data.update(exc_data) event_data.update(message=message, level=level, logger='foxglove.request_errors', fingerprint=fingerprint) if not capture_event(event_data, hint): logger.critical( 'sentry not configured correctly, not sending message: %s', message, extra={'event_data': event_data}, )
def __init__(self, exception: Exception, description: str, additional_notes: str = "", additional_info=None): super().__init__() self.exception = exception self.additional_notes = additional_notes self.send_report_btn = QPushButton("Send information") self.send_report_btn.setDisabled(not state_store.report_errors) self.cancel_btn = QPushButton("Cancel") self.error_description = QTextEdit() self.traceback_summary = additional_info if additional_info is None: self.error_description.setText("".join( traceback.format_exception(type(exception), exception, exception.__traceback__))) elif isinstance(additional_info, traceback.StackSummary): self.error_description.setText("".join(additional_info.format())) elif isinstance(additional_info[1], traceback.StackSummary): self.error_description.setText("".join( additional_info[1].format())) self.error_description.append(str(exception)) self.error_description.setReadOnly(True) self.additional_info = QTextEdit() self.contact_info = QLineEdit() self.user_name = QLineEdit() self.cancel_btn.clicked.connect(self.reject) self.send_report_btn.clicked.connect(self.send_information) layout = QVBoxLayout() self.desc = QLabel(description) self.desc.setWordWrap(True) info_text = QLabel( "If you see these dialog it not means that you do something wrong. " "In such case you should see some message box not error report dialog." ) info_text.setWordWrap(True) layout.addWidget(info_text) layout.addWidget(self.desc) layout.addWidget(self.error_description) layout.addWidget(QLabel("Contact information")) layout.addWidget(self.contact_info) layout.addWidget(QLabel("User name")) layout.addWidget(self.user_name) layout.addWidget(QLabel("Additional information from user:"******"Sending reports was disabled by runtime flag. " "You can report it manually by creating report on " "https://github.com/4DNucleome/PartSeg/issues")) btn_layout = QHBoxLayout() btn_layout.addWidget(self.cancel_btn) btn_layout.addWidget(self.send_report_btn) layout.addLayout(btn_layout) self.setLayout(layout) if isinstance(additional_info, tuple): self.exception_tuple = additional_info[0], None else: exec_info = exc_info_from_error(exception) self.exception_tuple = event_from_exception(exec_info)