Skip to content

Commit 7c10709

Browse files
committed
Rename _set_cache_data to _get_cache_data
1 parent c2dfdc3 commit 7c10709

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

sentry_sdk/integrations/redis/_async_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from sentry_sdk.integrations.redis.consts import SPAN_ORIGIN
44
from sentry_sdk.integrations.redis.modules.caches import (
55
_compile_cache_span_properties,
6-
_set_cache_data,
6+
_get_cache_data,
77
)
88
from sentry_sdk.integrations.redis.modules.queries import _compile_db_span_properties
99
from sentry_sdk.integrations.redis.utils import (
@@ -99,7 +99,7 @@ async def _sentry_execute_command(self, name, *args, **kwargs):
9999
db_span.__exit__(None, None, None)
100100

101101
if cache_span:
102-
_set_cache_data(cache_span, self, cache_properties, value)
102+
cache_span_data = _get_cache_data(self, cache_properties, value)
103103
cache_span.__exit__(None, None, None)
104104

105105
return value

sentry_sdk/integrations/redis/_sync_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from sentry_sdk.integrations.redis.consts import SPAN_ORIGIN
44
from sentry_sdk.integrations.redis.modules.caches import (
55
_compile_cache_span_properties,
6-
_set_cache_data,
6+
_get_cache_data,
77
)
88
from sentry_sdk.integrations.redis.modules.queries import _compile_db_span_properties
99
from sentry_sdk.integrations.redis.utils import (
@@ -105,7 +105,7 @@ def sentry_patched_execute_command(self, name, *args, **kwargs):
105105
db_span.__exit__(None, None, None)
106106

107107
if cache_span:
108-
_set_cache_data(cache_span, self, cache_properties, value)
108+
cache_span_data = _get_cache_data(self, cache_properties, value)
109109
cache_span.__exit__(None, None, None)
110110

111111
return value

sentry_sdk/integrations/redis/modules/caches.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,24 @@ def _get_cache_span_description(redis_command, args, kwargs, integration):
7575
return description
7676

7777

78-
def _set_cache_data(span, redis_client, properties, return_value):
79-
# type: (Span, Any, dict[str, Any], Optional[Any]) -> None
78+
def _get_cache_data(redis_client, properties, return_value):
79+
# type: (Any, dict[str, Any], Optional[Any]) -> dict[str, Any]
80+
data = {}
81+
8082
with capture_internal_exceptions():
81-
span.set_data(SPANDATA.CACHE_KEY, properties["key"])
83+
data[SPANDATA.CACHE_KEY] = properties["key"]
8284

8385
if properties["redis_command"] in GET_COMMANDS:
8486
if return_value is not None:
85-
span.set_data(SPANDATA.CACHE_HIT, True)
87+
data[SPANDATA.CACHE_HIT] = True
8688
size = (
8789
len(str(return_value).encode("utf-8"))
8890
if not isinstance(return_value, bytes)
8991
else len(return_value)
9092
)
91-
span.set_data(SPANDATA.CACHE_ITEM_SIZE, size)
93+
data[SPANDATA.CACHE_ITEM_SIZE] = size
9294
else:
93-
span.set_data(SPANDATA.CACHE_HIT, False)
95+
data[SPANDATA.CACHE_HIT] = False
9496

9597
elif properties["redis_command"] in SET_COMMANDS:
9698
if properties["value"] is not None:
@@ -99,7 +101,7 @@ def _set_cache_data(span, redis_client, properties, return_value):
99101
if not isinstance(properties["value"], bytes)
100102
else len(properties["value"])
101103
)
102-
span.set_data(SPANDATA.CACHE_ITEM_SIZE, size)
104+
data[SPANDATA.CACHE_ITEM_SIZE] = size
103105

104106
try:
105107
connection_params = redis_client.connection_pool.connection_kwargs
@@ -114,8 +116,10 @@ def _set_cache_data(span, redis_client, properties, return_value):
114116

115117
host = connection_params.get("host")
116118
if host is not None:
117-
span.set_data(SPANDATA.NETWORK_PEER_ADDRESS, host)
119+
data[SPANDATA.NETWORK_PEER_ADDRESS] = host
118120

119121
port = connection_params.get("port")
120122
if port is not None:
121-
span.set_data(SPANDATA.NETWORK_PEER_PORT, port)
123+
data[SPANDATA.NETWORK_PEER_PORT] = port
124+
125+
return data

0 commit comments

Comments
 (0)