@@ -134,22 +134,10 @@ def _get_address_port(settings):
134134 return address , int (port ) if port is not None else None
135135
136136
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-
151137def patch_caching ():
152138 # type: () -> None
139+ from sentry_sdk .integrations .django import DjangoIntegration
140+
153141 if not hasattr (CacheHandler , "_sentry_patched" ):
154142 if DJANGO_VERSION < (3 , 2 ):
155143 original_get_item = CacheHandler .__getitem__
@@ -159,7 +147,8 @@ def sentry_get_item(self, alias):
159147 # type: (CacheHandler, str) -> Any
160148 cache = original_get_item (self , alias )
161149
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 :
163152 from django .conf import settings
164153
165154 address , port = _get_address_port (
@@ -181,7 +170,8 @@ def sentry_create_connection(self, alias):
181170 # type: (CacheHandler, str) -> Any
182171 cache = original_create_connection (self , alias )
183172
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 :
185175 address , port = _get_address_port (self .settings [alias or "default" ])
186176
187177 _patch_cache (cache , address , port )
0 commit comments