0

My Django web app logs exceptions to Sentry via raven. I also run a number of scripts (via manage.py runscript) as cron jobs. Right now any exceptions in those scripts are not being reported to Sentry. How do I set such reporting up?

Ghopper21
  • 10,287
  • 10
  • 63
  • 92

2 Answers2

1

As of version 5.3.1 of raven-python it should correctly patch Django's BaseCommand.execute, which effectively will handle errors in these commands (unless that parent call is never made).

David Cramer
  • 1,990
  • 14
  • 24
  • Ah that sounds great, I'm using an old version. Will come back and accept answer once I confirm that works. – Ghopper21 Jun 01 '15 at 15:43
0

For those out there that:

  1. still have an issue of raven not patching itself for django management commands correctly

  2. have Django==1.6.11

  3. haven raven==5.12.0

I have found a fix that works for me.

The problem seems to be that raven is not patching BaseCommand.execute by the time it is called by Django. So to fix that, I make sure BaseCommand.execute is patched right away. I've updated my manage.py file to include the following lines:

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

My final manage.py file looks like this:

#!/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)
Paul
  • 1,192
  • 1
  • 11
  • 23