乌鸦不报告哨兵的例外情况

问题描述 投票:4回答:2

未被捕获的例外情况不会报告给哨兵。

我已经运行了manage.py raven test,我在哨兵处收到了测试消息,以确认通信正常。

我的配置包括:

# settings.py

RAVEN_CONFIG = {
    'dsn': '****',
}

SENTRY_CLIENT = 'raven.contrib.django.raven_compat.DjangoClient'

SENTRY_AUTO_LOG_STACKS = True

INSTALLED_APPS += [
    'raven.contrib.django.raven_compat',
]

然后

# wsgi.py

from raven.contrib.django.raven_compat.models import client

client.captureException()
python django wsgi sentry raven
2个回答
4
投票

docs所示,当出现异常时,您应该调用client.captureException()

try:
    1 / 0
except ZeroDivisionError:
    client.captureException()

wsgi.py你改为should do

from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
from django.core.handlers.wsgi import WSGIHandler

application = Sentry(WSGIHandler()

0
投票

首先你需要硬编码你的DSN,因为它包含importante信息,然后在django我认为最好使用python日志记录

RAVEN_CONFIG = {
'dsn': os.environ.get('SENTRY_DSN'),
}

 LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
    'verbose': {
        'format': '%(levelname)s [%(pathname)s:%(lineno)d] - %(message)s'
    },
    'simple': {
        'format': '%(levelname)s %(message)s'
    },
},
'handlers': {
    'sentry': {
        'level': 'ERROR',
        'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
        'tags': {'custom-tag': os.environ.get('SENTRY_TAG')},
    },
    'console': {
        'level': 'ERROR',
        'class': 'logging.StreamHandler',
        'formatter': 'verbose'
    }
},
'loggers': {
    'django': {
        'handlers': ['console', 'sentry'],
        'level': 'ERROR',
    },
    'Your_app {
        'handlers': ['console', 'sentry'],
        'level': 'ERROR',
    },
    'raven': {
        'level': 'ERROR',
        'handlers': ['sentry', 'console'],
        'propagate': False,
    }

}
}

然后运行python manage.py raven测试并共享控制台消息

© www.soinside.com 2019 - 2024. All rights reserved.