Skip to content

Commit 4b2b6db

Browse files
authored
Fix redis pipeline commands, because otel attributes do not allow dicts (#3631)
Otel `span.set_attribute()` does not allow `dict` values, thus we change the data to be compatible
1 parent 58cd8aa commit 4b2b6db

File tree

7 files changed

+16
-31
lines changed

7 files changed

+16
-31
lines changed

MIGRATION_GUIDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
1717
- The `Profile()` constructor does not accept a `hub` parameter anymore.
1818
- A `Profile` object does not have a `.hub` property anymore.
1919
- `sentry_sdk.continue_trace` no longer returns a `Transaction` and is now a context manager.
20+
- Redis integration: In Redis pipeline spans there is no `span["data"]["redis.commands"]` that contains a dict `{"count": 3, "first_ten": ["cmd1", "cmd2", ...]}` but instead `span["data"]["redis.commands.count"]` (containing `3`) and `span["data"]["redis.commands.first_ten"]` (containing `["cmd1", "cmd2", ...]`).
2021

2122
### Removed
2223

sentry_sdk/integrations/redis/utils.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,8 @@ def _set_pipeline_data(
120120
command = get_command_args_fn(arg)
121121
commands.append(_get_safe_command(command[0], command[1:]))
122122

123-
span.set_data(
124-
"redis.commands",
125-
{
126-
"count": len(command_stack),
127-
"first_ten": commands,
128-
},
129-
)
123+
span.set_data("redis.commands.count", len(command_stack))
124+
span.set_data("redis.commands.first_ten", commands)
130125

131126

132127
def _set_client_data(span, is_cluster, name, *args):

tests/integrations/redis/asyncio/test_redis_asyncio.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,10 @@ async def test_async_redis_pipeline(
6565
(span,) = event["spans"]
6666
assert span["op"] == "db.redis"
6767
assert span["description"] == "redis.pipeline.execute"
68+
assert span["data"]["redis.commands.count"] == 3
69+
assert span["data"]["redis.commands.first_ten"] == expected_first_ten
6870
assert span["data"] == ApproxDict(
6971
{
70-
"redis.commands": {
71-
"count": 3,
72-
"first_ten": expected_first_ten,
73-
},
7472
SPANDATA.DB_SYSTEM: "redis",
7573
SPANDATA.DB_NAME: "0",
7674
SPANDATA.SERVER_ADDRESS: connection.connection_pool.connection_kwargs.get(

tests/integrations/redis/cluster/test_redis_cluster.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,10 @@ def test_rediscluster_pipeline(
128128
(span,) = event["spans"]
129129
assert span["op"] == "db.redis"
130130
assert span["description"] == "redis.pipeline.execute"
131+
assert span["data"]["redis.commands.count"] == 3
132+
assert span["data"]["redis.commands.first_ten"] == expected_first_ten
131133
assert span["data"] == ApproxDict(
132134
{
133-
"redis.commands": {
134-
"count": 3,
135-
"first_ten": expected_first_ten,
136-
},
137135
SPANDATA.DB_SYSTEM: "redis",
138136
# ClusterNode converts localhost to 127.0.0.1
139137
SPANDATA.SERVER_ADDRESS: "127.0.0.1",

tests/integrations/redis/cluster_asyncio/test_redis_cluster_asyncio.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,10 @@ async def test_async_redis_pipeline(
131131
(span,) = event["spans"]
132132
assert span["op"] == "db.redis"
133133
assert span["description"] == "redis.pipeline.execute"
134+
assert span["data"]["redis.commands.count"] == 3
135+
assert span["data"]["redis.commands.first_ten"] == expected_first_ten
134136
assert span["data"] == ApproxDict(
135137
{
136-
"redis.commands": {
137-
"count": 3,
138-
"first_ten": expected_first_ten,
139-
},
140138
SPANDATA.DB_SYSTEM: "redis",
141139
# ClusterNode converts localhost to 127.0.0.1
142140
SPANDATA.SERVER_ADDRESS: "127.0.0.1",

tests/integrations/redis/test_redis.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ def test_redis_pipeline(
7272
assert span["op"] == "db.redis"
7373
assert span["description"] == "redis.pipeline.execute"
7474
assert span["data"][SPANDATA.DB_SYSTEM] == "redis"
75-
assert span["data"]["redis.commands"] == {
76-
"count": 3,
77-
"first_ten": expected_first_ten,
78-
}
75+
assert span["data"]["redis.commands.count"] == 3
76+
assert span["data"]["redis.commands.first_ten"] == expected_first_ten
7977
assert span["tags"] == {
8078
"redis.transaction": is_transaction,
8179
"redis.is_cluster": False,

tests/integrations/redis_py_cluster_legacy/test_redis_py_cluster_legacy.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,10 @@ def test_rediscluster_pipeline(
9595
(span,) = event["spans"]
9696
assert span["op"] == "db.redis"
9797
assert span["description"] == "redis.pipeline.execute"
98+
assert span["data"]["redis.commands.count"] == 3
99+
assert span["data"]["redis.commands.first_ten"] == expected_first_ten
98100
assert span["data"] == ApproxDict(
99101
{
100-
"redis.commands": {
101-
"count": 3,
102-
"first_ten": expected_first_ten,
103-
},
104102
SPANDATA.DB_SYSTEM: "redis",
105103
SPANDATA.DB_NAME: "1",
106104
SPANDATA.SERVER_ADDRESS: "localhost",
@@ -158,12 +156,11 @@ def test_db_connection_attributes_pipeline(
158156
(span,) = event["spans"]
159157
assert span["op"] == "db.redis"
160158
assert span["description"] == "redis.pipeline.execute"
159+
assert span["data"]["redis.commands.count"] == 1
160+
assert span["data"]["redis.commands.first_ten"] == ["GET 'foo'"]
161+
161162
assert span["data"] == ApproxDict(
162163
{
163-
"redis.commands": {
164-
"count": 1,
165-
"first_ten": ["GET 'foo'"],
166-
},
167164
SPANDATA.DB_SYSTEM: "redis",
168165
SPANDATA.DB_NAME: "1",
169166
SPANDATA.SERVER_ADDRESS: "localhost",

0 commit comments

Comments
 (0)