4

未捕获的异常不会报告给哨兵。

我已经跑了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()
4

2 回答 2

4

文档中所示,您应该client.captureException()在出现异常时调用:

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

wsgi.py应该这样做

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

application = Sentry(WSGIHandler()
于 2014-11-11T10:23:43.617 回答
0

首先你需要对你的 DSN 进行硬编码,因为它包含重要的信息,然后在 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 test 并分享控制台消息

于 2017-12-24T20:39:45.933 回答