本文整理汇总了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)