0

我的 Django Web 应用程序通过 raven 将异常记录到 Sentry。我还运行一些脚本(通过manage.py runscript)作为 cron 作业。目前,这些脚本中的任何异常都不会报告给 Sentry。如何设置此类报告?

4

2 回答 2

1

从 raven-python 的 5.3.1 版开始,它应该正确地修补 Django 的 BaseCommand.execute,这将有效地处理这些命令中的错误(除非从未进行过父调用)。

于 2015-05-30T07:53:56.083 回答
0

对于那些在那里:

  1. 仍然存在 raven 没有为 django 管理命令正确修补自身的问题

  2. 有 Django==1.6.11

  3. 避风港==5.12.0

我找到了一个适合我的修复程序。

问题似乎是 ravenBaseCommand.execute在 Django 调用它时没有打补丁。所以为了解决这个问题,我确保BaseCommand.execute立即修补。我已经更新了我的manage.py文件以包含以下几行:

from raven.contrib.django.management import patch_cli_runner
patch_cli_runner()

我的最终manage.py文件如下所示:

#!/usr/bin/env python
from os.path import abspath
from os.path import dirname
import os
import sys

if __name__ == "__main__":
# add the ../ directory to the os path, so that we can find
# app.settings below
sys.path.insert(0, os.path.abspath(os.path.join(dirname(abspath(__file__)), '..')))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")

from django.core.management import execute_from_command_line
from raven.contrib.django.management import patch_cli_runner
patch_cli_runner()

execute_from_command_line(sys.argv)
于 2016-04-07T20:01:21.813 回答