Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def __init__(
transaction_style="url", # type: str
middleware_spans=True, # type: bool
signals_spans=True, # type: bool
cache_spans=False, # type: bool
cache_spans=True, # type: bool
signals_denylist=None, # type: Optional[list[signals.Signal]]
http_methods_to_capture=DEFAULT_HTTP_METHODS_TO_CAPTURE, # type: tuple[str, ...]
):
Expand Down
22 changes: 6 additions & 16 deletions sentry_sdk/integrations/django/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,10 @@ def _get_address_port(settings):
return address, int(port) if port is not None else None


def should_enable_cache_spans():
# type: () -> bool
from sentry_sdk.integrations.django import DjangoIntegration

client = sentry_sdk.get_client()
integration = client.get_integration(DjangoIntegration)
from django.conf import settings

return integration is not None and (
(client.spotlight is not None and settings.DEBUG is True)
or integration.cache_spans is True
)


def patch_caching():
# type: () -> None
from sentry_sdk.integrations.django import DjangoIntegration

if not hasattr(CacheHandler, "_sentry_patched"):
if DJANGO_VERSION < (3, 2):
original_get_item = CacheHandler.__getitem__
Expand All @@ -158,7 +146,8 @@ def sentry_get_item(self, alias):
# type: (CacheHandler, str) -> Any
cache = original_get_item(self, alias)

if should_enable_cache_spans():
integration = sentry_sdk.get_client().get_integration(DjangoIntegration)
if integration is not None and integration.cache_spans:
from django.conf import settings

address, port = _get_address_port(
Expand All @@ -180,7 +169,8 @@ def sentry_create_connection(self, alias):
# type: (CacheHandler, str) -> Any
cache = original_create_connection(self, alias)

if should_enable_cache_spans():
integration = sentry_sdk.get_client().get_integration(DjangoIntegration)
if integration is not None and integration.cache_spans:
address, port = _get_address_port(self.settings[alias or "default"])

_patch_cache(cache, address, port)
Expand Down
Loading