RQ (Redis Queue)

The RQ integration adds support for the RQ Job Queue System.

Create a file called mysettings.py with the following content:

mysettings.py
Copied
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:

Copied
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:

app.py
Copied
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:

mysettings.py
Copied
# This import causes the Sentry SDK to be initialized
import app

The --sentry-dsn CLI option

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

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").