---
title: "RQ (Redis Queue)"
description: "Learn about using Sentry with RQ."
url: https://docs.sentry.io/platforms/python/integrations/rq/
---

# RQ (Redis Queue) for Python

The RQ integration adds support for the [RQ job queue system](https://python-rq.org/).

If you're using stream mode, this page's references to "transaction" should be applied to service spans instead. See [Streamed Spans](https://docs.sentry.io/platforms/python/tracing/streamed-spans.md) for more information.

## [Install](https://docs.sentry.io/platforms/python/integrations/rq.md#install)

Install `sentry-sdk` from PyPI:

```bash
pip install sentry-sdk
```

*Other available variations of the above snippet: uv*

## [Configure](https://docs.sentry.io/platforms/python/integrations/rq.md#configure)

If you have the `rq` package in your dependencies, the RQ integration will be enabled automatically when you initialize the Sentry SDK.

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

In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](https://docs.sentry.io/concepts/key-terms/tracing.md). You can also collect and analyze performance profiles from real users with [profiling](https://docs.sentry.io/product/profiling.md).

Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.

Error Monitoring\[ ]Tracing\[ ]Profiling

```python
# mysettings.py
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    # Add data like request headers and IP for users, if applicable;
    # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
    send_default_pii=True,
    # ___PRODUCT_OPTION_START___ performance
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for tracing.
    traces_sample_rate=1.0,
    # ___PRODUCT_OPTION_END___ performance
    # ___PRODUCT_OPTION_START___ profiling
    # To collect profiles for all profile sessions,
    # set `profile_session_sample_rate` to 1.0.
    profile_session_sample_rate=1.0,
    # Profiles will be automatically collected while
    # there is an active span.
    profile_lifecycle="trace",
    # ___PRODUCT_OPTION_END___ profiling
)
```

Start your worker with:

```shell
rq worker \
    -c mysettings  # module name of mysettings.py
```

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 only initializing Sentry once. Note that because the Flask integration is enabled automatically, you don't need to change the configuration shown above.

```python
# app.py
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    # Add data like request headers and IP for users, if applicable;
    # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
    send_default_pii=True,
    # ___PRODUCT_OPTION_START___ performance
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for tracing.
    traces_sample_rate=1.0,
    # ___PRODUCT_OPTION_END___ performance
    # ___PRODUCT_OPTION_START___ profiling
    # To collect profiles for all profile sessions,
    # set `profile_session_sample_rate` to 1.0.
    profile_session_sample_rate=1.0,
    # Profiles will be automatically collected while
    # there is an active span.
    profile_lifecycle="trace",
    # ___PRODUCT_OPTION_END___ profiling
)
```

The worker configuration `mysettings.py` then becomes:

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

## [Verify](https://docs.sentry.io/platforms/python/integrations/rq.md#verify)

To verify, create a `main.py` script that enqueues a function in RQ, then start an RQ worker to run the function:

### [Job definition:](https://docs.sentry.io/platforms/python/integrations/rq.md#job-definition)

```python
# jobs.py
def hello(name):
    1 / 0  # raises an error
    return "Hello %s!" % name
```

### [Settings for worker](https://docs.sentry.io/platforms/python/integrations/rq.md#settings-for-worker)

```python
# mysettings.py
import sentry_sdk

# Sentry configuration for RQ worker processes
sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    # Add data like request headers and IP for users, if applicable;
    # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
    send_default_pii=True,
    # ___PRODUCT_OPTION_START___ performance
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for tracing.
    traces_sample_rate=1.0,
    # ___PRODUCT_OPTION_END___ performance
    # ___PRODUCT_OPTION_START___ profiling
    # To collect profiles for all profile sessions,
    # set `profile_session_sample_rate` to 1.0.
    profile_session_sample_rate=1.0,
    # Profiles will be automatically collected while
    # there is an active span.
    profile_lifecycle="trace",
    # ___PRODUCT_OPTION_END___ profiling
)
```

### [Main Python Script](https://docs.sentry.io/platforms/python/integrations/rq.md#main-python-script)

```python
# main.py
from redis import Redis
from rq import Queue

from jobs import hello

import sentry_sdk

# Sentry configuration for main.py process
sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    # Add data like request headers and IP for users, if applicable;
    # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
    send_default_pii=True,
    # ___PRODUCT_OPTION_START___ performance
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for tracing.
    traces_sample_rate=1.0,
    # ___PRODUCT_OPTION_END___ performance
    # ___PRODUCT_OPTION_START___ profiling
    # To collect profiles for all profile sessions,
    # set `profile_session_sample_rate` to 1.0.
    profile_session_sample_rate=1.0,
    # Profiles will be automatically collected while
    # there is an active span.
    profile_lifecycle="trace",
    # ___PRODUCT_OPTION_END___ profiling
)

q = Queue(connection=Redis())

# or sentry_sdk.traces.start_span(name="testing_sentry", parent_span=None) in stream mode
with sentry_sdk.start_transaction(name="testing_sentry"):
    result = q.enqueue(hello, "World")
```

When you run `python main.py` a transaction named `testing_sentry` will be created in the Performance section of [sentry.io](https://sentry.io) and spans for the enqueueing will be created.

If you run the RQ worker with `rq worker -c mysettings`, a transaction for the execution of `hello()` will be created. Additionally, an error event will be sent to [sentry.io](https://sentry.io) and will be connected to the transaction.

It takes a couple of moments for the data to appear in [sentry.io](https://sentry.io).

## [The `--sentry-dsn` CLI option](https://docs.sentry.io/platforms/python/integrations/rq.md#the---sentry-dsn-cli-option)

The `--sentry-dsn` CLI option has been removed from RQ. Initialize the Sentry SDK directly in your worker settings file (e.g. `mysettings.py`) as shown above.

## [Supported Versions](https://docs.sentry.io/platforms/python/integrations/rq.md#supported-versions)

* RQ:

  * 0.6+ (SDK <3.0)
  * 1.0+ (SDK 3.0+)

* Python:

  * 3.6+ (SDK <3.0)
  * 3.7+ (SDK 3.0+)

If you're looking to use Sentry with older Python or framework versions, consider using an older major version of the SDK. The minimum versions for each major version are listed above.
