@@ -133,22 +133,10 @@ def _get_address_port(settings):
133133 return address , int (port ) if port is not None else None
134134
135135
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-
150136def patch_caching ():
151137 # type: () -> None
138+ from sentry_sdk .integrations .django import DjangoIntegration
139+
152140 if not hasattr (CacheHandler , "_sentry_patched" ):
153141 if DJANGO_VERSION < (3 , 2 ):
154142 original_get_item = CacheHandler .__getitem__
@@ -158,7 +146,8 @@ def sentry_get_item(self, alias):
158146 # type: (CacheHandler, str) -> Any
159147 cache = original_get_item (self , alias )
160148
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 :
162151 from django .conf import settings
163152
164153 address , port = _get_address_port (
@@ -180,7 +169,8 @@ def sentry_create_connection(self, alias):
180169 # type: (CacheHandler, str) -> Any
181170 cache = original_create_connection (self , alias )
182171
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 :
184174 address , port = _get_address_port (self .settings [alias or "default" ])
185175
186176 _patch_cache (cache , address , port )
0 commit comments