From 66448722737b78fc94f0ad2a9f0d0adf3a028e95 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Wed, 21 May 2014 09:34:09 +0200 Subject: [PATCH] Raise warning when using async Sentry transport. --- CHANGES.md | 2 +- rq/contrib/sentry.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index dc933bc..f75ff1c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,7 @@ ### 0.4.6 (not released yet) -- ... +- Fix where Sentry logging did not reliably work in the worker process. ### 0.4.5 diff --git a/rq/contrib/sentry.py b/rq/contrib/sentry.py index 5608e63..a99134a 100644 --- a/rq/contrib/sentry.py +++ b/rq/contrib/sentry.py @@ -1,12 +1,24 @@ # -*- coding: utf-8 -*- from __future__ import (absolute_import, division, print_function, unicode_literals) +import warnings def register_sentry(client, worker): """Given a Raven client and an RQ worker, registers exception handlers with the worker so exceptions are logged to Sentry. """ + def uses_supported_transport(url): + supported_transports = set(['sync+', 'requests+']) + return any(url.startswith(prefix) for prefix in supported_transports) + + if not any(uses_supported_transport(s) for s in client.servers): + msg = ('Sentry error delivery is known to be unreliable when not ' + 'delivered synchronously from RQ workers. You are encouraged ' + 'to change your DSN to use the sync+ or requests+ transport ' + 'prefix.') + warnings.warn(msg, UserWarning, stacklevel=2) + def send_to_sentry(job, *exc_info): client.captureException( exc_info=exc_info,