From 6613185ccbb73aa3a982ac4b8e7659875a3fbad2 Mon Sep 17 00:00:00 2001 From: Quinna Halim Date: Thu, 2 Jan 2025 10:56:05 -0500 Subject: [PATCH] fix: add schematize service name for django caching (#11843) Currently, we treat django caching as a separate service. This is a quick fix so that behavior aligns with our public docs; inferred services connected to django should be directly connected to the third-party service not django. The service name should adhere to the name rule from `schematize_service_name` rather than `django`. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) --------- Co-authored-by: Munir Abdinur Co-authored-by: erikayasuda <153395705+erikayasuda@users.noreply.github.com> --- ddtrace/contrib/internal/django/patch.py | 2 +- ...ervice-name-schematization-bef19b44b7414016.yaml | 4 ++++ tests/contrib/django/test_django.py | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/django-cache-service-name-schematization-bef19b44b7414016.yaml 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"]