11import functools
22from typing import TYPE_CHECKING
3+ from sentry_sdk .integrations .redis .utils import _get_safe_key
34from urllib3 .util import parse_url as urlparse
45
56from django import VERSION as DJANGO_VERSION
89import sentry_sdk
910from sentry_sdk .consts import OP , SPANDATA
1011from sentry_sdk .utils import (
11- SENSITIVE_DATA_SUBSTITUTE ,
1212 capture_internal_exceptions ,
1313 ensure_integration_enabled ,
1414)
2828]
2929
3030
31- def _get_key (args , kwargs ):
32- # type: (list[Any], dict[str, Any]) -> str
33- key = ""
34-
35- if args is not None and len (args ) >= 1 :
36- key = args [0 ]
37- elif kwargs is not None and "key" in kwargs :
38- key = kwargs ["key" ]
39-
40- if isinstance (key , dict ):
41- # Do not leak sensitive data
42- # `set_many()` has a dict {"key1": "value1", "key2": "value2"} as first argument.
43- # Those values could include sensitive data so we replace them with a placeholder
44- key = {x : SENSITIVE_DATA_SUBSTITUTE for x in key }
45-
46- return str (key )
47-
48-
4931def _get_span_description (method_name , args , kwargs ):
50- # type: (str, list [Any], dict[str, Any]) -> str
51- return _get_key ( args , kwargs )
32+ # type: (str, tuple [Any], dict[str, Any]) -> str
33+ return _get_safe_key ( method_name , args , kwargs )
5234
5335
5436def _patch_cache_method (cache , method_name , address , port ):
@@ -61,11 +43,11 @@ def _patch_cache_method(cache, method_name, address, port):
6143 def _instrument_call (
6244 cache , method_name , original_method , args , kwargs , address , port
6345 ):
64- # type: (CacheHandler, str, Callable[..., Any], list [Any], dict[str, Any], Optional[str], Optional[int]) -> Any
46+ # type: (CacheHandler, str, Callable[..., Any], tuple [Any, ... ], dict[str, Any], Optional[str], Optional[int]) -> Any
6547 is_set_operation = method_name .startswith ("set" )
6648 is_get_operation = not is_set_operation
6749
68- op = OP .CACHE_SET if is_set_operation else OP .CACHE_GET
50+ op = OP .CACHE_PUT if is_set_operation else OP .CACHE_GET
6951 description = _get_span_description (method_name , args , kwargs )
7052
7153 with sentry_sdk .start_span (op = op , description = description ) as span :
@@ -78,7 +60,7 @@ def _instrument_call(
7860 if port is not None :
7961 span .set_data (SPANDATA .NETWORK_PEER_PORT , port )
8062
81- key = _get_key ( args , kwargs )
63+ key = _get_safe_key ( method_name , args , kwargs )
8264 if key != "" :
8365 span .set_data (SPANDATA .CACHE_KEY , key )
8466
0 commit comments