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