Ejemplo n.º 1
0
    def init_plugins():
        """初始化日志、错误追踪、打点插件"""
        from everyclass.rpc import init as init_rpc
        from everyclass.common.flask import print_config

        # Sentry
        if plugin_available("sentry"):
            sentry.init_app(app=__app)
            sentry_handler = SentryHandler(sentry.client)
            sentry_handler.setLevel(logging.WARNING)
            logging.getLogger().addHandler(sentry_handler)

            init_rpc(sentry=sentry)
            logger.info('Sentry is inited because you are in {} mode.'.format(
                __app.config['CONFIG_NAME']))

        # metrics
        global statsd
        statsd = DogStatsd(
            namespace=
            f"{__app.config['SERVICE_NAME']}.{os.environ.get('MODE').lower()}",
            use_default_route=True)

        init_rpc(logger=logger)

        print_config(__app, logger)
Ejemplo n.º 2
0
 def internal_server_error(error):
     if plugin_available("sentry"):
         return render_template('common/error.html',
                                message=MSG_INTERNAL_ERROR,
                                event_id=g.sentry_event_id,
                                public_dsn=sentry.client.get_public_dsn('https'))
     return "<h4>500 Error: {}</h4><br>You are seeing this page because Sentry is not available.".format(repr(error))
Ejemplo n.º 3
0
 def _return_string(cls,
                    status_code,
                    string,
                    sentry_capture=False,
                    log=None):
     if sentry_capture and plugin_available("sentry"):
         sentry.captureException()
     if log:
         logger.info(log)
     return string, status_code
Ejemplo n.º 4
0
def _error_page(message: str, sentry_capture: bool = False, log: str = None):
    """return a error page with a message. if sentry is available, tell user that they can report the problem."""
    sentry_param = {}
    if sentry_capture and plugin_available("sentry"):
        sentry.captureException()
        sentry_param.update({
            "event_id": g.sentry_event_id,
            "public_dsn": sentry.client.get_public_dsn('https')
        })
    if log:
        logger.info(log)
    return render_template('common/error.html',
                           message=message,
                           **sentry_param)