Skip to content

Commit 1f47307

Browse files
committed
breaking: Enable Django cache_spans by default
This reverts commit 955108e (#3791) and simply enables `cache_spans` by default..
1 parent 968b362 commit 1f47307

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

sentry_sdk/integrations/django/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def __init__(
131131
transaction_style="url", # type: str
132132
middleware_spans=True, # type: bool
133133
signals_spans=True, # type: bool
134-
cache_spans=False, # type: bool
134+
cache_spans=True, # type: bool
135135
signals_denylist=None, # type: Optional[list[signals.Signal]]
136136
http_methods_to_capture=DEFAULT_HTTP_METHODS_TO_CAPTURE, # type: tuple[str, ...]
137137
):

sentry_sdk/integrations/django/caching.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
150136
def 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

Comments
 (0)