Re: Logging to Sentry from a Celery Task

1,137 views
Skip to first unread message

Jordi Llonch

unread,
May 22, 2013, 11:15:40 PM5/22/13
to gets...@googlegroups.com
Try this, works like charm...

from raven import Client
from raven.contrib.celery import register_signal

client = Client() #using SENTRY_DSN environ
register_signal(client)



2013/5/23 Christopher Burnor <christoph...@gmail.com>
I'm having an issue logging to Sentry from within a celery task.  Errors in tasks work fine.  However, when I try to manually log an event, it gets logged to the celery logs, but not to the sentry server.

The code I'm using is:

@task
def myWorker():
  logger = logging.getLogger('celery.task')
  logger.addHandler(SentryHandler())
  logger.warn("Some condition happened", exc_info=True, extra={ 'extra': 'data' })

I've found some posts on here and around the net on this, but they all seem to be very out of date

--
You received this message because you are subscribed to the Google Groups "sentry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to getsentry+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Maikas Katastrofa

unread,
Aug 21, 2013, 5:45:27 AM8/21/13
to gets...@googlegroups.com
Jordy, 

Where do you exactly put it ? in config ? in tasks.py ? in each task ? 
Sorry for my lack of understanding of how exactly all this works. But there seems to be no detailed info on this anywhere I was looking.

Jordi Llonch

unread,
Aug 21, 2013, 6:43:01 AM8/21/13
to gets...@googlegroups.com
Maikas,

Just set SENTRY_DSN as environ or the right parameters in raven.Client

Exceptions in tasks will be logged into Sentry.

Cheers


2013/8/21 Maikas Katastrofa <audrius....@gmail.com>

Maikas Katastrofa

unread,
Aug 21, 2013, 8:55:28 AM8/21/13
to gets...@googlegroups.com
Sorry for my stupidity, but I am even more confused now. Could you show me some example using tutorial code ? or something very obvious ? :)

David Cramer

unread,
Aug 21, 2013, 12:45:54 PM8/21/13
to gets...@googlegroups.com
You'd put it wherever you initialize your application.

e.g. somewhere that gets imported, but probably not settings.py

Maikas Katastrofa

unread,
Aug 22, 2013, 4:17:03 AM8/22/13
to gets...@googlegroups.com
so you just import it ? dont you need to do something with failure signals ?

David Cramer

unread,
Aug 22, 2013, 11:41:08 AM8/22/13
to gets...@googlegroups.com, gets...@googlegroups.com
You import whatever is going to hold the client and call register signals. 

Matthieu Rigal

unread,
Dec 4, 2014, 12:13:51 PM12/4/14
to gets...@googlegroups.com
I know this answer is old, but I think it wasn't updated in between and shows up early in Google.

I've tried to do this, in the task itself, as well as in my start module where I have the following

from celery import Celery
celery_app = Celery('myapp')

But it doesn't work...
Using celery 3.1 with sentry 6.4.4 on Django 1.6

Best,
Matthieu

Matthieu Rigal

unread,
Dec 4, 2014, 12:30:14 PM12/4/14
to gets...@googlegroups.com
OK, I've found the problem, since an upgrade to raven 5+, I need to add to Django settings:
CELERYD_HIJACK_ROOT_LOGGER = False

Thanks and sorry,
Matthieu
Reply all
Reply to author
Forward
0 new messages