【问题标题】:How to get raven to report Django runscript exceptions to Sentry?如何让 raven 向 Sentry 报告 Django runscript 异常?
【发布时间】:2015-05-26 16:59:42
【问题描述】:

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

【问题讨论】:

    标签: django sentry raven


    【解决方案1】:

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

    【讨论】:

    • 啊,听起来不错,我使用的是旧版本。一旦我确认有效,就会回来并接受答案。
    【解决方案2】:

    对于那些:

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

    2. 有 Django==1.6.11

    3. 避风港乌鸦==5.12.0

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

    问题似乎是 raven 在 Django 调用它时没有修补 BaseCommand.execute。因此,为了解决这个问题,我确保立即修补 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)
    

    【讨论】:

      猜你喜欢
      • 2014-09-07
      • 1970-01-01
      • 2019-06-18
      • 1970-01-01
      • 2020-08-28
      • 1970-01-01
      • 2018-03-18
      • 2018-11-11
      • 1970-01-01
      相关资源
      最近更新 更多