Redis

The Redis integration hooks into the Redis client for Python and logs all Redis commands as breadcrumbs.

Copied
pip install --upgrade 'sentry-sdk'

If you have the redis Python package in your dependencies, the Redis integration will be enabled automatically. There is nothing to do for you except initializing the Sentry SDK.

Copied
import sentry_sdk
from sentry_sdk.integrations.redis import RedisIntegration

sentry_sdk.init(
    dsn='https://examplePublicKey@o0.ingest.sentry.io/0',
    enable_tracing=True,
)

The Redis integration is enabled automatically if you have the redis package installed.

Copied
import redis

def main():
    sentry_sdk.init(...)  # same as above
    r = redis.Redis(host='localhost', port=6379, decode_responses=True)

    with sentry_sdk.start_transaction(name="testing_sentry"):
        r.set("foo", "bar")
        r.get("foo")

main()

Copied
from redis.cluster import RedisCluster

def main():
    sentry_sdk.init(...)  # same as above
    rc = RedisCluster(host='localhost', port=16379)

    with sentry_sdk.start_transaction(name="testing_sentry"):
        rc.set("foo", "bar")
        rc.get("foo")

main()

Copied
import asyncio
import redis.asyncio as redis

async def main():
    sentry_sdk.init(...)  # same as above
    rc = RedisCluster(host='localhost', port=16379)

    with sentry_sdk.start_transaction(name="testing_sentry"):
        rc.set("foo", "bar")
        rc.get("foo")

asyncio.run(main())

These examples will create a transaction called testing_sentry in the Performance section of sentry.io, and create spans for the redis commands.

It takes a couple of moments for the data to appear in sentry.io.

With Redis integration the following information will be available to you on Sentry.io:

  • Performance information about requests to redis will be available in the waterfall diagram in the Performance section on Sentry.io.
  • Redis commands will be added as breadcrumbs.
  • If send_default_pii is set to True you will also see the data used in your redis commands.
  • Data of the AUTH command will never be collected.

If you want to change the default behavior of the Redis integration, you need to instantiate the integration manually to pass options to the integration and then pass it to Sentry's init function.

max_data_size

By default RedisIntegration() will trim data collected after 1024 characters. You can change this behavior with the max_data_size parameter:

  • When you set max_data_size to a value that evaluates to False (like 0 or None) no trimming will take place.
  • You can set max_data_size to an integer to control how many characters should be collected.

Example for disabling data trimming, the whole Redis command will be recorded:

Copied
import sentry_sdk
from sentry_sdk.integrations.redis import RedisIntegration

sentry_sdk.init(
    dsn='https://examplePublicKey@o0.ingest.sentry.io/0',
    enable_tracing=True,
    integrations=[
        RedisIntegration(
            max_data_size=None
        ),
    ]
)

Example of keeping just a maximum of 50 characters of Redis commands:

Copied
import sentry_sdk
from sentry_sdk.integrations.redis import RedisIntegration

sentry_sdk.init(
    dsn='https://examplePublicKey@o0.ingest.sentry.io/0',
    enable_tracing=True,
    integrations=[
        RedisIntegration(
            max_data_size=50
        ),
    ]
)

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