Skip to content

Commit ad2dc85

Browse files
fix: add schematize service name for django caching [backport 2.19] (#11854)
Backport 6613185 from #11843 to 2.19. 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: Quinna Halim <[email protected]>
1 parent e16d68c commit ad2dc85

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

ddtrace/contrib/internal/django/patch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def traced_cache(django, pin, func, instance, args, kwargs):
215215
"django.cache",
216216
span_name="django.cache",
217217
span_type=SpanTypes.CACHE,
218-
service=config.django.cache_service_name,
218+
service=schematize_service_name(config.django.cache_service_name),
219219
resource=utils.resource_from_cache_prefix(func_name(func), instance),
220220
tags=tags,
221221
pin=pin,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
tracing(django): Fixes issue where django cache is represented as a django service rather than the third party service.

tests/contrib/django/test_django.py

+13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from ddtrace.ext import http
3131
from ddtrace.ext import user
3232
from ddtrace.internal.compat import ensure_text
33+
from ddtrace.internal.schema import schematize_service_name
3334
from ddtrace.propagation._utils import get_wsgi_header
3435
from ddtrace.propagation.http import HTTP_HEADER_PARENT_ID
3536
from ddtrace.propagation.http import HTTP_HEADER_SAMPLING_PRIORITY
@@ -769,6 +770,18 @@ def test_cache_get(test_spans):
769770
assert_dict_issuperset(span.get_tags(), expected_meta)
770771

771772

773+
def test_cache_service_schematization(test_spans):
774+
cache = django.core.cache.caches["default"]
775+
776+
with override_config("django", dict(cache_service_name="test-cache-service")):
777+
cache.get("missing_key")
778+
spans = test_spans.get_spans()
779+
assert spans
780+
span = spans[0]
781+
expected_service_name = schematize_service_name(config.django.cache_service_name)
782+
assert span.service == expected_service_name
783+
784+
772785
def test_cache_get_rowcount_existing_key(test_spans):
773786
# get the default cache
774787
cache = django.core.cache.caches["default"]

0 commit comments

Comments
 (0)