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

fix: add schematize service name for django caching #11843

Merged
merged 9 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion ddtrace/contrib/internal/django/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def traced_cache(django, pin, func, instance, args, kwargs):
"django.cache",
span_name="django.cache",
span_type=SpanTypes.CACHE,
service=config.django.cache_service_name,
service=schematize_service_name(config.django.cache_service_name),
resource=utils.resource_from_cache_prefix(func_name(func), instance),
tags=tags,
pin=pin,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
tracing(django): Fixes issue where django cache is represented as a django service rather than the third party service.
13 changes: 13 additions & 0 deletions tests/contrib/django/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from ddtrace.ext import http
from ddtrace.ext import user
from ddtrace.internal.compat import ensure_text
from ddtrace.internal.schema import schematize_service_name
from ddtrace.propagation._utils import get_wsgi_header
from ddtrace.propagation.http import HTTP_HEADER_PARENT_ID
from ddtrace.propagation.http import HTTP_HEADER_SAMPLING_PRIORITY
Expand Down Expand Up @@ -769,6 +770,18 @@ def test_cache_get(test_spans):
assert_dict_issuperset(span.get_tags(), expected_meta)


def test_cache_service_schematization(test_spans):
cache = django.core.cache.caches["default"]

with override_config("django", dict(cache_service_name="test-cache-service")):
cache.get("missing_key")
spans = test_spans.get_spans()
assert spans
span = spans[0]
expected_service_name = schematize_service_name(config.django.cache_service_name)
assert span.service == expected_service_name
quinna-h marked this conversation as resolved.
Show resolved Hide resolved


def test_cache_get_rowcount_existing_key(test_spans):
# get the default cache
cache = django.core.cache.caches["default"]
Expand Down
Loading