@@ -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