1
1
import functools
2
2
from typing import TYPE_CHECKING
3
+ from sentry_sdk .integrations .redis .utils import _get_safe_key
3
4
from urllib3 .util import parse_url as urlparse
4
5
5
6
from django import VERSION as DJANGO_VERSION
8
9
import sentry_sdk
9
10
from sentry_sdk .consts import OP , SPANDATA
10
11
from sentry_sdk .utils import (
11
- SENSITIVE_DATA_SUBSTITUTE ,
12
12
capture_internal_exceptions ,
13
13
ensure_integration_enabled ,
14
14
)
28
28
]
29
29
30
30
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
-
49
31
def _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 )
52
34
53
35
54
36
def _patch_cache_method (cache , method_name , address , port ):
@@ -61,11 +43,11 @@ def _patch_cache_method(cache, method_name, address, port):
61
43
def _instrument_call (
62
44
cache , method_name , original_method , args , kwargs , address , port
63
45
):
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
65
47
is_set_operation = method_name .startswith ("set" )
66
48
is_get_operation = not is_set_operation
67
49
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
69
51
description = _get_span_description (method_name , args , kwargs )
70
52
71
53
with sentry_sdk .start_span (op = op , description = description ) as span :
@@ -78,7 +60,7 @@ def _instrument_call(
78
60
if port is not None :
79
61
span .set_data (SPANDATA .NETWORK_PEER_PORT , port )
80
62
81
- key = _get_key ( args , kwargs )
63
+ key = _get_safe_key ( method_name , args , kwargs )
82
64
if key != "" :
83
65
span .set_data (SPANDATA .CACHE_KEY , key )
84
66
0 commit comments