feat(redis): Add instrumentation for redis pipeline (#1543) · gitcommit90/sentry-python@7a7f6d9 · GitHub
Skip to content

Commit 7a7f6d9

Browse files
authored
feat(redis): Add instrumentation for redis pipeline (getsentry#1543)
Add automatic instrumentation of redis pipelining for both redis and rediscluster. https://redis.io/docs/manual/pipelining/ Note: This does not add instrumentation for StrictRedisCluster.
1 parent 976fff2 commit 7a7f6d9

3 files changed

Lines changed: 154 additions & 13 deletions

File tree

sentry_sdk/integrations/redis.py

Lines changed: 74 additions & 10 deletions

tests/integrations/redis/test_redis.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from sentry_sdk import capture_message
1+
from sentry_sdk import capture_message, start_transaction
22
from sentry_sdk.integrations.redis import RedisIntegration
33

44
from fakeredis import FakeStrictRedis
5+
import pytest
56

67

78
def test_basic(sentry_init, capture_events):
@@ -19,7 +20,41 @@ def test_basic(sentry_init, capture_events):
1920
assert crumb == {
2021
"category": "redis",
2122
"message": "GET 'foobar'",
22-
"data": {"redis.key": "foobar", "redis.command": "GET"},
23+
"data": {
24+
"redis.key": "foobar",
25+
"redis.command": "GET",
26+
"redis.is_cluster": False,
27+
},
2328
"timestamp": crumb["timestamp"],
2429
"type": "redis",
2530
}
31+
32+
33+
@pytest.mark.parametrize("is_transaction", [False, True])
34+
def test_redis_pipeline(sentry_init, capture_events, is_transaction):
35+
sentry_init(integrations=[RedisIntegration()], traces_sample_rate=1.0)
36+
events = capture_events()
37+
38+
connection = FakeStrictRedis()
39+
with start_transaction():
40+
41+
pipeline = connection.pipeline(transaction=is_transaction)
42+
pipeline.get("foo")
43+
pipeline.set("bar", 1)
44+
pipeline.set("baz", 2)
45+
pipeline.execute()
46+
47+
(event,) = events
48+
(span,) = event["spans"]
49+
assert span["op"] == "redis"
50+
assert span["description"] == "redis.pipeline.execute"
51+
assert span["data"] == {
52+
"redis.commands": {
53+
"count": 3,
54+
"first_ten": ["GET 'foo'", "SET 'bar' 1", "SET 'baz' 2"],
55+
}
56+
}
57+
assert span["tags"] == {
58+
"redis.transaction": is_transaction,
59+
"redis.is_cluster": False,
60+
}

tests/integrations/rediscluster/test_rediscluster.py

Lines changed: 43 additions & 1 deletion

0 commit comments

Comments
 (0)