Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(spotlight): Auto enable cache_spans for Spotlight on DEBUG #3791

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Changes from all 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
22 changes: 16 additions & 6 deletions sentry_sdk/integrations/django/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,22 @@ def _get_address_port(settings):
return address, int(port) if port is not None else None


def patch_caching():
# type: () -> 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
if not hasattr(CacheHandler, "_sentry_patched"):
if DJANGO_VERSION < (3, 2):
original_get_item = CacheHandler.__getitem__
Expand All @@ -145,8 +157,7 @@ def sentry_get_item(self, alias):
# type: (CacheHandler, str) -> Any
cache = original_get_item(self, alias)

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

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

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

_patch_cache(cache, address, port)
Expand Down
Loading