RQ (Redis Queue)
The RQ integration adds support for the RQ Job Queue System.
Create a file called
mysettings.py with the following content:
import sentry_sdk from sentry_sdk.integrations.rq import RqIntegration sentry_sdk.init( dsn="https://examplePublicKey@o0.ingest.sentry.io/0", integrations=[ RqIntegration(), ], # Set traces_sample_rate to 1.0 to capture 100% # of transactions for performance monitoring. # We recommend adjusting this value in production, traces_sample_rate=1.0, )
Start your worker with:
rq worker \ -c mysettings \ # module name of mysettings.py --sentry-dsn="" # only necessary for RQ < 1.0
The integration will automatically report errors from all RQ jobs.
Generally, make sure that the call to
init is loaded on worker startup, and not only in the module where your jobs are defined. Otherwise, the initialization happens too late and events might end up not being reported.
In addition, make sure that
init is called only once in your app. For example, if you have a Flask app and a worker that depends on the app, we recommend initializing Sentry with a single configuration that is suitable for Flask and RQ, as in:
import sentry_sdk from sentry_sdk.integrations.flask import FlaskIntegration from sentry_sdk.integrations.rq import RqIntegration sentry_sdk.init( dsn=https://examplePublicKey@o0.ingest.sentry.io/0, integrations=[ FlaskIntegration(), RqIntegration(), ], # Set traces_sample_rate to 1.0 to capture 100% # of transactions for performance monitoring. # We recommend adjusting this value in production, traces_sample_rate=1.0, )
The worker configuration
mysettings.py then becomes:
# This import causes the Sentry SDK to be initialized import app
--sentry-dsn="" to RQ forcibly disables RQ's shortcut for using Sentry. For RQ versions before 1.0 this is necessary to avoid conflicts, because back then RQ would attempt to use the
raven package instead of this SDK. Since RQ 1.0 it's possible to use this CLI option and the associated RQ settings for initializing the SDK.
We still recommend against using those shortcuts because it would be harder to provide options to the SDK at a later point. See the GitHub issue about RQ's Sentry integration for discussion.