Registry / observability / opentelemetry-instrumentation-redis

opentelemetry-instrumentation-redis

JSON →
library0.65b0pypypi✓ verified 25d ago

The `opentelemetry-instrumentation-redis` library provides automatic instrumentation for the Python `redis` client, capturing Redis commands as OpenTelemetry spans. It is part of the `opentelemetry-python-contrib` project and is currently in a beta state, with the latest version being 0.61b0. New versions are released as part of the broader OpenTelemetry Python Contrib release cadence.

pip install opentelemetry-instrumentation-redis redis
INSTALL
IMPORT
SIG · OPENTELEMETRY-INST
O
opentelemetry-instrumentation-redis
observabilitypythonv0.65b0
Install
3.0s avg
Import
583ms
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.65b0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.614s · 27.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.0s · import 0.552s · 28MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RedisInstrumentor
from opentelemetry.instrumentation.redis import RedisInstrumentor
suppress_instrumentation
from opentelemetry.instrumentation.utils import suppress_instrumentation
Used to temporarily disable instrumentation for specific code blocks.

This quickstart demonstrates how to set up OpenTelemetry with the Redis instrumentation. It configures a simple `TracerProvider` with a `ConsoleSpanExporter` (for demonstration purposes), then enables Redis instrumentation globally using `RedisInstrumentor().instrument()`. Any subsequent Redis client operations will generate spans. Ensure a Redis server is running at `localhost:6379` or configure environment variables `REDIS_HOST` and `REDIS_PORT`.

import os from opentelemetry import trace from opentelemetry.sdk.resources import Resource, SERVICE_NAME from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter from opentelemetry.instrumentation.redis import RedisInstrumentor import redis # 1. Configure OpenTelemetry TracerProvider resource = Resource.create({"service.name": os.environ.get('OTEL_SERVICE_NAME', 'redis-app')}) tracer_provider = TracerProvider(resource=resource) tracer_provider.add_span_processor( BatchSpanProcessor(ConsoleSpanExporter()) ) trace.set_tracer_provider(tracer_provider) # 2. Instrument Redis RedisInstrumentor().instrument() # 3. Use Redis client (operations will be traced) try: client = redis.StrictRedis(host=os.environ.get('REDIS_HOST', 'localhost'), port=int(os.environ.get('REDIS_PORT', 6379)), db=0) client.ping() print("Successfully connected to Redis.") client.set("mykey", "myvalue") value = client.get("mykey") print(f"Retrieved from Redis: {value.decode('utf-8')}") client.delete("mykey") except redis.exceptions.ConnectionError as e: print(f"Could not connect to Redis: {e}. Please ensure Redis is running.") # Example of suppressing instrumentation for a specific call # from opentelemetry.instrumentation.utils import suppress_instrumentation # with suppress_instrumentation(): # client.get("untraced-key")
opentelemetry-instrument --version
Debug
Known issues
betaThis instrumentation library is currently in beta. The API and behavior may change in future versions, and it should generally not be used in production environments without careful consideration.
fix
Monitor `opentelemetry-python-contrib` releases for stable versions and breaking changes. Review your code when upgrading to newer beta versions.
affects: All versions up to 0.61b0
gotchaBy default, `RedisInstrumentor().instrument()` instruments *all* `redis` client instances created *after* the `instrument()` call. If you only want to instrument specific Redis clients, use `RedisInstrumentor().instrument_client(client_instance)` instead.
fix
For granular control, explicitly call `instrument_client()` on the desired `redis.Redis` or `redis.StrictRedis` objects. Alternatively, use `suppress_instrumentation()` for operations that should not be traced.
affects: All versions
gotchaThe instrumentation records Redis commands in the `db.statement` attribute. While efforts are made to obfuscate sensitive arguments by default, be cautious about logging or exposing this attribute, especially if sensitive data could be part of Redis commands.
fix
Review the configuration options for `db.statement` serialization (if available, consult documentation for specific options) or implement custom hooks to further filter or mask sensitive data before it's recorded in spans.
affects: All versions
gotchaOpenTelemetry auto-instrumentation adds performance overhead. While generally optimized, it's crucial to benchmark your application with instrumentation enabled to understand its impact on CPU and memory usage, especially in high-throughput scenarios.
fix
Regularly benchmark your application with and without OpenTelemetry instrumentation. Use sampling strategies to reduce the volume of traces if overhead is a concern.
affects: All versions
breakingOpenTelemetry SDK and API packages are not installed or are not discoverable. This error typically occurs when `opentelemetry-api` and `opentelemetry-sdk` are missing from the environment, which are essential for any OpenTelemetry application.
fix
Ensure that `opentelemetry-api` and `opentelemetry-sdk` are installed in your environment. For example, run `pip install opentelemetry-api opentelemetry-sdk` or include them in your project's dependency management file.
affects: All versions
breakingThe application failed to run due to a `ModuleNotFoundError` for `opentelemetry.sdk`. This indicates that the core OpenTelemetry SDK package was not installed or is not accessible in the environment. All OpenTelemetry applications require the `opentelemetry-sdk` package for basic functionality.
fix
Ensure that `opentelemetry-sdk` is explicitly installed in your environment (e.g., `pip install opentelemetry-sdk`) or that your dependency management correctly includes it. Verify that all necessary OpenTelemetry core and instrumentation packages are present.
affects: All versions
Upgrade
Version history
0.65b0latest on PyPI · released Jul 16, 2026
Audit
Dependencies
redisrequiredThis instrumentation library wraps the `redis` Python client, so `redis` must be installed separately.
opentelemetry-apirequiredCore OpenTelemetry API for defining telemetry.
opentelemetry-sdkrequiredOpenTelemetry SDK for processing and exporting telemetry.
Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources