Skip to content

Commit f7d06b1

Browse files
committed
Doc
1 parent 7a5af67 commit f7d06b1

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
([#3884](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3884))
2828
- `opentelemetry-instrumentation-aiohttp-server`: add support for custom header captures via `OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST` and `OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE`
2929
([#3916](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3916))
30+
- `opentelemetry-instrumentation-redis`: add support for `suppress_instrumentation` context manager for both sync and async Redis clients and pipelines
3031

3132
### Fixed
3233

instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,35 @@ def response_hook(span, instance, response):
110110
client = redis.StrictRedis(host="localhost", port=6379)
111111
client.get("my-key")
112112
113+
Suppress Instrumentation
114+
-------------------------
115+
116+
You can use the ``suppress_instrumentation`` context manager to prevent instrumentation
117+
from being applied to specific Redis operations. This is useful when you want to avoid
118+
creating spans for internal operations, health checks, or during specific code paths.
119+
120+
.. code:: python
121+
122+
from opentelemetry.instrumentation.redis import RedisInstrumentor
123+
from opentelemetry.instrumentation.utils import suppress_instrumentation
124+
import redis
125+
126+
# Instrument redis
127+
RedisInstrumentor().instrument()
128+
129+
client = redis.StrictRedis(host="localhost", port=6379)
130+
131+
# This will report a span
132+
client.get("my-key")
133+
134+
# This will NOT report a span
135+
with suppress_instrumentation():
136+
client.get("internal-key")
137+
client.set("cache-key", "value")
138+
139+
# This will report a span again
140+
client.get("another-key")
141+
113142
API
114143
---
115144
"""

0 commit comments

Comments
 (0)