Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Django caching instrumentation update #3009

Open
wants to merge 55 commits into
base: master
Choose a base branch
from

Conversation

antonpirker
Copy link
Member

@antonpirker antonpirker commented Apr 24, 2024

This adds more data to the cache spans and makes adding the cache item size optional.
This implements parts of following spec https://develop.sentry.dev/sdk/performance/modules/cache/

Documentation for manual instrumentation for the Cache module can be found here:
getsentry/sentry-docs#9926

Load testing of the feature was done here: #3058

Fixes #2964

@antonpirker antonpirker changed the base branch from master to sentry-sdk-2.0 April 24, 2024 13:14
Base automatically changed from sentry-sdk-2.0 to master April 25, 2024 09:13
@antonpirker antonpirker marked this pull request as ready for review May 7, 2024 07:46
Copy link
Member

@szokeasaurusrex szokeasaurusrex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have some questions and suggestions

sentry_sdk/integrations/django/__init__.py Outdated Show resolved Hide resolved
sentry_sdk/integrations/django/__init__.py Outdated Show resolved Hide resolved
sentry_sdk/integrations/django/caching.py Outdated Show resolved Hide resolved
sentry_sdk/integrations/django/caching.py Show resolved Hide resolved
sentry_sdk/integrations/django/caching.py Outdated Show resolved Hide resolved
def _patch_cache_method(cache, method_name):
# type: (CacheHandler, str) -> None
def _patch_cache_method(cache, method_name, address, port):
# type: (CacheHandler, str, Optional[str], Optional[str]) -> None
from sentry_sdk.integrations.django import DjangoIntegration

original_method = getattr(cache, method_name)

@ensure_integration_enabled(DjangoIntegration, original_method)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@ensure_integration_enabled(DjangoIntegration, original_method)

I think it makes more sense to place this on the sentry_method function. It is inaccurate to say that this method maps original_method because it has a different signature. Although, perhaps it would be more appropriate to make this change in a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, probably better a new PR. Can you please create a ticket @szokeasaurusrex ?

item_size = len(str(args[1]))

if item_size is not None:
span.set_data(SPANDATA.CACHE_ITEM_SIZE, item_size)

return value

@functools.wraps(original_method)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@functools.wraps(original_method)
@ensure_integration_enabled(DjangoIntegration, original_method)

To be applied alongside my comment on (original version) line 41; also, likely makes sense to do in separate PR.

sentry_sdk/integrations/django/caching.py Outdated Show resolved Hide resolved
tests/integrations/django/test_basic.py Show resolved Hide resolved
tox.ini Show resolved Hide resolved
Co-authored-by: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>
Copy link
Member

@szokeasaurusrex szokeasaurusrex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found some logic that appears to be broken – this should be fixed, and we should also add tests for it.

Besides that, I have also added some more minor suggestions and questions.

sentry_sdk/integrations/django/caching.py Outdated Show resolved Hide resolved
sentry_sdk/integrations/django/caching.py Outdated Show resolved Hide resolved
sentry_sdk/integrations/django/caching.py Outdated Show resolved Hide resolved
sentry_sdk/integrations/django/caching.py Outdated Show resolved Hide resolved
sentry_sdk/integrations/django/caching.py Show resolved Hide resolved
sentry_sdk/integrations/django/caching.py Outdated Show resolved Hide resolved
sentry_sdk/integrations/redis/__init__.py Show resolved Hide resolved
sentry_sdk/integrations/redis/__init__.py Show resolved Hide resolved
sentry_sdk/integrations/redis/asyncio.py Show resolved Hide resolved
@antonpirker antonpirker self-assigned this May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Caching module update for DjangoIntegration
2 participants