def emit(self, record): # type: (logging.LogRecord) -> None try: if record.exc_info: stack_trace = ''.join( traceback.format_exception( *record.exc_info)) # type: Optional[str] message = str(record.exc_info[1]) else: stack_trace = None message = record.getMessage() if '\n' in message: # Some exception code paths in queue processors # seem to result in super-long messages stack_trace = message message = message.split('\n')[0] report = dict( node=platform.node(), host=platform.node(), message=message, stack_trace=stack_trace, ) if hasattr(record, "request"): add_request_metadata( report, record.request ) # type: ignore # record.request is added dynamically except Exception: traceback.print_exc() report = dict( node=platform.node(), host=platform.node(), message=record.getMessage(), stack_trace="See /var/log/zulip/errors.log", ) try: if settings.STAGING_ERROR_NOTIFICATIONS: # On staging, process the report directly so it can happen inside this # try/except to prevent looping from zerver.lib.error_notify import notify_server_error notify_server_error(report) else: queue_json_publish('error_reports', dict( type="server", report=report, ), lambda x: None, call_consume_in_tests=True) except Exception: # If this breaks, complain loudly but don't pass the traceback up the stream # However, we *don't* want to use logging.exception since that could trigger a loop. logging.warning("Reporting an exception triggered an exception!", exc_info=True)
def emit(self, record: logging.LogRecord) -> None: report = {} # type: Dict[str, Any] try: report['node'] = platform.node() report['host'] = platform.node() add_deployment_metadata(report) if record.exc_info: stack_trace = ''.join( traceback.format_exception(*record.exc_info)) message = str(record.exc_info[1]) else: stack_trace = 'No stack trace available' message = record.getMessage() if '\n' in message: # Some exception code paths in queue processors # seem to result in super-long messages stack_trace = message message = message.split('\n')[0] report['stack_trace'] = stack_trace report['message'] = message report['logger_name'] = record.name report['log_module'] = find_log_caller_module(record) report['log_lineno'] = record.lineno if hasattr(record, "request"): add_request_metadata( report, record.request ) # type: ignore # record.request is added dynamically except Exception: report['message'] = "Exception in preparing exception report!" logging.warning(report['message'], exc_info=True) report['stack_trace'] = "See /var/log/zulip/errors.log" try: if settings.STAGING_ERROR_NOTIFICATIONS: # On staging, process the report directly so it can happen inside this # try/except to prevent looping from zerver.lib.error_notify import notify_server_error notify_server_error(report) else: queue_json_publish('error_reports', dict( type="server", report=report, )) except Exception: # If this breaks, complain loudly but don't pass the traceback up the stream # However, we *don't* want to use logging.exception since that could trigger a loop. logging.warning("Reporting an exception triggered an exception!", exc_info=True)
def emit(self, record: logging.LogRecord) -> None: report = {} # type: Dict[str, Any] try: report['node'] = platform.node() report['host'] = platform.node() add_deployment_metadata(report) if record.exc_info: stack_trace = ''.join(traceback.format_exception(*record.exc_info)) message = str(record.exc_info[1]) else: stack_trace = 'No stack trace available' message = record.getMessage() if '\n' in message: # Some exception code paths in queue processors # seem to result in super-long messages stack_trace = message message = message.split('\n')[0] report['stack_trace'] = stack_trace report['message'] = message report['logger_name'] = record.name report['log_module'] = find_log_caller_module(record) report['log_lineno'] = record.lineno if hasattr(record, "request"): add_request_metadata(report, record.request) # type: ignore # record.request is added dynamically except Exception: report['message'] = "Exception in preparing exception report!" logging.warning(report['message'], exc_info=True) report['stack_trace'] = "See /var/log/zulip/errors.log" try: if settings.STAGING_ERROR_NOTIFICATIONS: # On staging, process the report directly so it can happen inside this # try/except to prevent looping from zerver.lib.error_notify import notify_server_error notify_server_error(report) else: queue_json_publish('error_reports', dict( type = "server", report = report, )) except Exception: # If this breaks, complain loudly but don't pass the traceback up the stream # However, we *don't* want to use logging.exception since that could trigger a loop. logging.warning("Reporting an exception triggered an exception!", exc_info=True)
def emit(self, record): # type: (logging.LogRecord) -> None try: if record.exc_info: stack_trace = ''.join(traceback.format_exception(*record.exc_info)) # type: Optional[str] message = str(record.exc_info[1]) else: stack_trace = None message = record.getMessage() if '\n' in message: # Some exception code paths in queue processors # seem to result in super-long messages stack_trace = message message = message.split('\n')[0] report = dict( node = platform.node(), host = platform.node(), message = message, stack_trace = stack_trace, ) if hasattr(record, "request"): add_request_metadata(report, record.request) # type: ignore # record.request is added dynamically except Exception: traceback.print_exc() report = dict( node = platform.node(), host = platform.node(), message = record.getMessage(), stack_trace = "See /var/log/zulip/errors.log", ) try: if settings.STAGING_ERROR_NOTIFICATIONS: # On staging, process the report directly so it can happen inside this # try/except to prevent looping from zerver.lib.error_notify import notify_server_error notify_server_error(report) else: queue_json_publish('error_reports', dict( type = "server", report = report, ), lambda x: None) except Exception: # If this breaks, complain loudly but don't pass the traceback up the stream # However, we *don't* want to use logging.exception since that could trigger a loop. logging.warning("Reporting an exception triggered an exception!", exc_info=True)
def emit(self, record: logging.LogRecord) -> None: report = {} # type: Dict[str, Any] # This parameter determines whether Zulip should attempt to # send Zulip messages containing the error report. If there's # syntax that makes the markdown processor throw an exception, # we really don't want to send that syntax into a new Zulip # message in exception handler (that's the stuff of which # recursive exception loops are made). # # We initialize is_bugdown_rendering_exception to `True` to # prevent the infinite loop of zulip messages by ERROR_BOT if # the outer try block here throws an exception before we have # a chance to check the exception for whether it comes from # bugdown. is_bugdown_rendering_exception = True try: report['node'] = platform.node() report['host'] = platform.node() add_deployment_metadata(report) if record.exc_info: stack_trace = ''.join(traceback.format_exception(*record.exc_info)) message = str(record.exc_info[1]) from zerver.lib.exceptions import BugdownRenderingException is_bugdown_rendering_exception = record.msg.startswith('Exception in Markdown parser') else: stack_trace = 'No stack trace available' message = record.getMessage() if '\n' in message: # Some exception code paths in queue processors # seem to result in super-long messages stack_trace = message message = message.split('\n')[0] is_bugdown_rendering_exception = False report['stack_trace'] = stack_trace report['message'] = message report['logger_name'] = record.name report['log_module'] = find_log_caller_module(record) report['log_lineno'] = record.lineno if hasattr(record, "request"): add_request_metadata(report, record.request) # type: ignore # record.request is added dynamically except Exception: report['message'] = "Exception in preparing exception report!" logging.warning(report['message'], exc_info=True) report['stack_trace'] = "See /var/log/zulip/errors.log" if settings.DEBUG_ERROR_REPORTING: # nocoverage logging.warning("Reporting an error to admins...") logging.warning("Reporting an error to admins: {} {} {} {} {}" .format( record.levelname, report['logger_name'], report['log_module'], report['message'], report['stack_trace'])) try: if settings.STAGING_ERROR_NOTIFICATIONS: # On staging, process the report directly so it can happen inside this # try/except to prevent looping from zerver.lib.error_notify import notify_server_error notify_server_error(report, is_bugdown_rendering_exception) else: queue_json_publish('error_reports', dict( type = "server", report = report, )) except Exception: # If this breaks, complain loudly but don't pass the traceback up the stream # However, we *don't* want to use logging.exception since that could trigger a loop. logging.warning("Reporting an exception triggered an exception!", exc_info=True)
def emit(self, record: logging.LogRecord) -> None: report: Dict[str, Any] = {} # This parameter determines whether Zulip should attempt to # send Zulip messages containing the error report. If there's # syntax that makes the Markdown processor throw an exception, # we really don't want to send that syntax into a new Zulip # message in exception handler (that's the stuff of which # recursive exception loops are made). # # We initialize is_markdown_rendering_exception to `True` to # prevent the infinite loop of zulip messages by ERROR_BOT if # the outer try block here throws an exception before we have # a chance to check the exception for whether it comes from # markdown. is_markdown_rendering_exception = True try: report['node'] = platform.node() report['host'] = platform.node() report['deployment_data'] = dict( git=try_git_describe(), ZULIP_VERSION=ZULIP_VERSION, ) if record.exc_info: stack_trace = ''.join(traceback.format_exception(*record.exc_info)) message = str(record.exc_info[1]) is_markdown_rendering_exception = record.msg.startswith('Exception in Markdown parser') else: stack_trace = 'No stack trace available' message = record.getMessage() if '\n' in message: # Some exception code paths in queue processors # seem to result in super-long messages stack_trace = message message = message.split('\n')[0] is_markdown_rendering_exception = False report['stack_trace'] = stack_trace report['message'] = message report['logger_name'] = record.name report['log_module'] = find_log_caller_module(record) report['log_lineno'] = record.lineno if isinstance(record, HasRequest): add_request_metadata(report, record.request) except Exception: report['message'] = "Exception in preparing exception report!" logging.warning(report['message'], exc_info=True) report['stack_trace'] = "See /var/log/zulip/errors.log" if settings.DEBUG_ERROR_REPORTING: # nocoverage logging.warning("Reporting an error to admins...") logging.warning( "Reporting an error to admins: %s %s %s %s %s", record.levelname, report['logger_name'], report['log_module'], report['message'], report['stack_trace'], ) try: if settings.STAGING_ERROR_NOTIFICATIONS: # On staging, process the report directly so it can happen inside this # try/except to prevent looping from zerver.lib.error_notify import notify_server_error notify_server_error(report, is_markdown_rendering_exception) else: queue_json_publish('error_reports', dict( type = "server", report = report, )) except Exception: # If this breaks, complain loudly but don't pass the traceback up the stream # However, we *don't* want to use logging.exception since that could trigger a loop. logging.warning("Reporting an exception triggered an exception!", exc_info=True)