【问题标题】:raven not reporting exceptions to sentry乌鸦没有向哨兵报告异常
【发布时间】:2014-08-25 20:50:02
【问题描述】:

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

我已运行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


    【解决方案1】:

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

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

    wsgi.pyshould do 这个代替:

    from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
    from django.core.handlers.wsgi import WSGIHandler
    
    application = Sentry(WSGIHandler()
    

    【讨论】:

      【解决方案2】:

      首先您需要对 DSN 进行硬编码,因为它包含重要信息, 然后在 django 上,我认为最好使用 python logging

      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 并分享控制台消息

      【讨论】:

        猜你喜欢
        • 2012-04-06
        • 1970-01-01
        • 1970-01-01
        • 2012-06-05
        • 1970-01-01
        • 2018-09-05
        • 1970-01-01
        • 2014-10-05
        • 1970-01-01
        相关资源
        最近更新 更多