Ghopper21
Ghopper21

Reputation: 10477

How to get raven to report Django runscript exceptions to Sentry?

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?

Upvotes: 0

Views: 343

Answers (2)

Paul
Paul

Reputation: 1242

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)

Upvotes: 0

David Cramer
David Cramer

Reputation: 1998

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).

Upvotes: 1

Related Questions