Skip to content

Commit 5445427

Browse files
committed
After gathering all the data, set it on the span
1 parent 05569f1 commit 5445427

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

sentry_sdk/integrations/redis/_async_common.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from sentry_sdk.integrations.redis.utils import (
1010
_get_client_data,
1111
_get_pipeline_data,
12+
_update_span,
1213
)
1314
from sentry_sdk.tracing import Span
1415
from sentry_sdk.utils import capture_internal_exceptions
@@ -48,6 +49,7 @@ async def _sentry_execute(self, *args, **kwargs):
4849
is_transaction=False if is_cluster else self.is_transaction,
4950
command_stack=self._command_stack if is_cluster else self.command_stack,
5051
)
52+
_update_span(span, span_data, pipeline_data)
5153

5254
return await old_execute(self, *args, **kwargs)
5355

@@ -92,14 +94,16 @@ async def _sentry_execute_command(self, name, *args, **kwargs):
9294
db_span.__enter__()
9395

9496
db_span_data = get_db_data_fn(self)
95-
db_client_span_data = _get_client_data(db_span, is_cluster, name, *args)
97+
db_client_span_data = _get_client_data(is_cluster, name, *args)
98+
_update_span(db_span, db_span_data, db_client_span_data)
9699

97100
value = await old_execute_command(self, name, *args, **kwargs)
98101

99102
db_span.__exit__(None, None, None)
100103

101104
if cache_span:
102105
cache_span_data = _get_cache_data(self, cache_properties, value)
106+
_update_span(cache_span, cache_span_data)
103107
cache_span.__exit__(None, None, None)
104108

105109
return value

sentry_sdk/integrations/redis/_sync_common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from sentry_sdk.integrations.redis.utils import (
1010
_get_client_data,
1111
_get_pipeline_data,
12+
_update_span,
1213
)
1314
from sentry_sdk.tracing import Span
1415
from sentry_sdk.utils import capture_internal_exceptions
@@ -50,6 +51,7 @@ def sentry_patched_execute(self, *args, **kwargs):
5051
is_transaction=False if is_cluster else self.transaction,
5152
command_stack=self.command_stack,
5253
)
54+
_update_span(span, span_data, pipeline_data)
5355

5456
return old_execute(self, *args, **kwargs)
5557

@@ -99,13 +101,15 @@ def sentry_patched_execute_command(self, name, *args, **kwargs):
99101

100102
db_span_data = get_db_data_fn(self)
101103
db_client_span_data = _get_client_data(db_span, is_cluster, name, *args)
104+
_update_span(db_span, db_span_data, db_client_span_data)
102105

103106
value = old_execute_command(self, name, *args, **kwargs)
104107

105108
db_span.__exit__(None, None, None)
106109

107110
if cache_span:
108111
cache_span_data = _get_cache_data(self, cache_properties, value)
112+
_update_span(cache_span, cache_span_data)
109113
cache_span.__exit__(None, None, None)
110114

111115
return value

sentry_sdk/integrations/redis/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@
1616
from sentry_sdk.tracing import Span
1717

1818

19+
TAG_KEYS = [
20+
"redis.commands",
21+
"redis.is_cluster",
22+
"redis.key",
23+
"redis.transaction",
24+
SPANDATA.DB_OPERATION,
25+
]
26+
27+
28+
def _update_span(span, *data_bags):
29+
# type: (Span, *dict[str, Any]) -> None
30+
for data in data_bags:
31+
for key, value in data.items():
32+
if key in TAG_KEYS:
33+
span.set_tag(key, value)
34+
else:
35+
span.set_data(key, value)
36+
37+
1938
def _get_safe_command(name, args):
2039
# type: (str, Sequence[Any]) -> str
2140
command_parts = [name]

0 commit comments

Comments
 (0)