diff --git a/ddtrace/contrib/internal/django/patch.py b/ddtrace/contrib/internal/django/patch.py index c40f49b627f..d4b14487e39 100644 --- a/ddtrace/contrib/internal/django/patch.py +++ b/ddtrace/contrib/internal/django/patch.py @@ -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, diff --git a/releasenotes/notes/django-cache-service-name-schematization-bef19b44b7414016.yaml b/releasenotes/notes/django-cache-service-name-schematization-bef19b44b7414016.yaml new file mode 100644 index 00000000000..0fbdb9993a5 --- /dev/null +++ b/releasenotes/notes/django-cache-service-name-schematization-bef19b44b7414016.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + tracing(django): Fixes issue where django cache is represented as a django service rather than the third party service. \ No newline at end of file diff --git a/tests/contrib/django/test_django.py b/tests/contrib/django/test_django.py index cf44ed6bcdd..1bd223539c9 100644 --- a/tests/contrib/django/test_django.py +++ b/tests/contrib/django/test_django.py @@ -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 @@ -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 + + def test_cache_get_rowcount_existing_key(test_spans): # get the default cache cache = django.core.cache.caches["default"]