Skip to content

Commit

Permalink
fix: add schematize service name for django caching (#11843)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: erikayasuda <[email protected]>
(cherry picked from commit 6613185)
  • Loading branch information
quinna-h authored and github-actions[bot] committed Jan 3, 2025
1 parent 2ba151b commit 11169c3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
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


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

0 comments on commit 11169c3

Please sign in to comment.