當前位置: 首頁>>代碼示例>>Python>>正文


Python Sentry.add_sentry_id_header方法代碼示例

本文整理匯總了Python中raven.contrib.flask.Sentry.add_sentry_id_header方法的典型用法代碼示例。如果您正苦於以下問題:Python Sentry.add_sentry_id_header方法的具體用法?Python Sentry.add_sentry_id_header怎麽用?Python Sentry.add_sentry_id_header使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在raven.contrib.flask.Sentry的用法示例。


在下文中一共展示了Sentry.add_sentry_id_header方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setup_app

# 需要導入模塊: from raven.contrib.flask import Sentry [as 別名]
# 或者: from raven.contrib.flask.Sentry import add_sentry_id_header [as 別名]
def setup_app(app):
    """Setup Sentry extension."""
    app.config.setdefault('SENTRY_DSN', None)
    # Sanitize data more
    app.config.setdefault('SENTRY_PROCESSORS', (
        'raven.processors.SanitizePasswordsProcessor',
        'invenio.ext.logging.backends.sentry.InvenioSanitizeProcessor',
    ))
    # When a user is logged in, also include the user info in the log message.
    app.config.setdefault('SENTRY_USER_ATTRS', ['info', ])
    # Defaults to only reporting errors and warnings.
    app.config.setdefault('LOGGING_SENTRY_LEVEL', 'WARNING')
    # Send warnings to Sentry?
    app.config.setdefault('LOGGING_SENTRY_INCLUDE_WARNINGS', True)
    # Send Celery log messages to Sentry?
    app.config.setdefault('LOGGING_SENTRY_CELERY', True)
    # Transport mechanism for Celery. Defaults to synchronous transport.
    # See http://raven.readthedocs.org/en/latest/transports/index.html
    app.config.setdefault('LOGGING_SENTRY_CELERY_TRANSPORT', 'sync')

    if app.config['SENTRY_DSN']:
        # Detect Invenio requirements and add to Sentry include paths so
        # version information about them is added to the log message.
        app.config.setdefault('SENTRY_INCLUDE_PATHS', sentry_include_paths())

        # Fix-up known version problems getting version information
        # Patch submitted to raven-python, if accepted the following lines
        # can be removed:
        # https://github.com/getsentry/raven-python/pull/452
        from raven.utils import _VERSION_CACHE
        import numpy
        import webassets
        import setuptools
        _VERSION_CACHE['invenio'] = invenio.__version__
        _VERSION_CACHE['numpy'] = numpy.__version__
        _VERSION_CACHE['webassets'] = webassets.__version__
        _VERSION_CACHE['setuptools'] = setuptools.__version__

        # Modify Sentry transport for Celery - must be called prior to client
        # creation.
        celery_dsn_fix(app)

        # Installs sentry in app.extensions['sentry']
        s = Sentry(
            app,
            logging=True,
            level=getattr(logging, app.config['LOGGING_SENTRY_LEVEL'])
        )

        # Replace method with more robust version
        s.add_sentry_id_header = add_sentry_id_header

        # Add extra tags information to sentry.
        s.client.extra_context({'version': invenio.__version__})

        # Capture warnings from warnings module
        if app.config['LOGGING_SENTRY_INCLUDE_WARNINGS']:
            setup_warnings(s)

        # Setup Celery logging to Sentry
        if app.config['LOGGING_SENTRY_CELERY']:
            # Setup Celery loggers
            after_setup_task_logger.connect(
                partial(celery_logger_setup, app=app),
                weak=False
            )
            after_setup_logger.connect(
                partial(celery_logger_setup, app=app),
                weak=False
            )

        # Werkzeug only adds a stream handler if there's no other handlers
        # defined, so when Sentry adds a log handler no output is
        # received from Werkzeug unless we install a console handler here on
        # the werkzeug logger.
        if app.debug:
            logger = logging.getLogger('werkzeug')
            logger.setLevel(logging.INFO)
            handler = logging.StreamHandler()
            logger.addHandler(handler)
開發者ID:lnielsen,項目名稱:flask-appexts,代碼行數:82,代碼來源:sentry.py


注:本文中的raven.contrib.flask.Sentry.add_sentry_id_header方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。