@@ -134,22 +134,10 @@ def _get_address_port(settings):
134
134
return address , int (port ) if port is not None else None
135
135
136
136
137
- def should_enable_cache_spans ():
138
- # type: () -> bool
139
- from sentry_sdk .integrations .django import DjangoIntegration
140
-
141
- client = sentry_sdk .get_client ()
142
- integration = client .get_integration (DjangoIntegration )
143
- from django .conf import settings
144
-
145
- return integration is not None and (
146
- (client .spotlight is not None and settings .DEBUG is True )
147
- or integration .cache_spans is True
148
- )
149
-
150
-
151
137
def patch_caching ():
152
138
# type: () -> None
139
+ from sentry_sdk .integrations .django import DjangoIntegration
140
+
153
141
if not hasattr (CacheHandler , "_sentry_patched" ):
154
142
if DJANGO_VERSION < (3 , 2 ):
155
143
original_get_item = CacheHandler .__getitem__
@@ -159,7 +147,8 @@ def sentry_get_item(self, alias):
159
147
# type: (CacheHandler, str) -> Any
160
148
cache = original_get_item (self , alias )
161
149
162
- if should_enable_cache_spans ():
150
+ integration = sentry_sdk .get_client ().get_integration (DjangoIntegration )
151
+ if integration is not None and integration .cache_spans :
163
152
from django .conf import settings
164
153
165
154
address , port = _get_address_port (
@@ -181,7 +170,8 @@ def sentry_create_connection(self, alias):
181
170
# type: (CacheHandler, str) -> Any
182
171
cache = original_create_connection (self , alias )
183
172
184
- if should_enable_cache_spans ():
173
+ integration = sentry_sdk .get_client ().get_integration (DjangoIntegration )
174
+ if integration is not None and integration .cache_spans :
185
175
address , port = _get_address_port (self .settings [alias or "default" ])
186
176
187
177
_patch_cache (cache , address , port )
0 commit comments