Skip to content

Commit cc90218

Browse files
BYKantonpirkersentrivana
authored
[breaking] Enable Django cache_spans by default (#3994)
This reverts commit 955108e (#3791) and simply enables `cache_spans` by default. Co-authored-by: Anton Pirker <[email protected]> Co-authored-by: Ivana Kellyer <[email protected]>
1 parent 32369cb commit cc90218

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

Diff for: sentry_sdk/integrations/django/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def __init__(
115115
transaction_style="url", # type: str
116116
middleware_spans=True, # type: bool
117117
signals_spans=True, # type: bool
118-
cache_spans=False, # type: bool
118+
cache_spans=True, # type: bool
119119
signals_denylist=None, # type: Optional[list[signals.Signal]]
120120
http_methods_to_capture=DEFAULT_HTTP_METHODS_TO_CAPTURE, # type: tuple[str, ...]
121121
):

Diff for: sentry_sdk/integrations/django/caching.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -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-
151137
def 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

Comments
 (0)