Integrate sentry to rq worker script

I am using a worker script to start my worker. Sorry if I missed it in the documentation, but how can I integrate sentry from a worker script?

This is how I am setting up my workers

https://python-rq.org/docs/workers/#performance-notes

Previously with raven, I can do this.

from raven import Client
from raven.transport.http import HTTPTransport
from rq.contrib.sentry import register_sentry

app = create_app()
client = Client(app.config.get('SENTRY_DSN'), transport=HTTPTransport)

listen = ['default']
if len(sys.argv) > 1:
    listen = [queue_name.strip() for queue_name in sys.argv[1:]]

if __name__ == '__main__':
    with Connection(redis_conn):
        with app.app_context():
            worker = Worker(map(Queue, listen))
            register_sentry(client, worker)
            worker.work()

And running it like python worker.py name_of_queue

Not sure where to integrate this
sentry_sdk.init("https://random123455@sentry.io/12345", integrations=[RqIntegration()])

Thank you!

Hi, please refer to https://docs.sentry.io/platforms/python/rq/

Yes Ive seen that. I am not running my worker as rq worker so i am not sure where to incorporate the integration.

Sorry if its not too obvious on the documentation, but what is the equivalent of the raven register_sentry() functionality on the api?

Oh, sorry. Just put it anywhere in your script (or any module imported by your script). As long as it runs sometime on startup it should be fine.

1 Like