dd-trace-py icon indicating copy to clipboard operation
dd-trace-py copied to clipboard

feat(django): add option to append url_name of resolver match to span resource name

Open ca-simone-chiorazzo opened this issue 2 years ago • 9 comments

Description

This PR aims to introduce a backwards compatible change that allows Django <2.2.0 developers to be able to distinguish different spans related to URLs under the same view.

As of today, ddtrace uses a pattern {method} {handler} that in case of class-based viewsets doesn't allow the installer to distinguish different endpoints under the same class in a clear way.

In the end, the PR adds a new optional configuration to append the url_name of Django resolver match to differentiate endpoints under the same ViewSet.

Checklist

Motivation

Without this change, using django 1.X, it's not possible to trace different DRF endpoints that are under the same ViewSet. The actual behaviour is that ddtrace aggregates everything that is served under the same ViewSet.

Design

Testing strategy

Reviewer Checklist

  • [X] Title is accurate.
  • [X] Description motivates each change.
  • [X] No unnecessary changes were introduced in this PR.
  • [X] PR cannot be broken up into smaller PRs.
  • [X] Avoid breaking API changes unless absolutely necessary.
  • [X] Tests provided or description of manual testing performed is included in the code or PR.
  • [x] Release note has been added for fixes and features, or else changelog/no-changelog label added.
  • [ ] All relevant GitHub issues are correctly linked.
  • [ ] Backports are identified and tagged with Mergifyio.
  • [ ] Add to milestone.

ca-simone-chiorazzo avatar Sep 16 '22 16:09 ca-simone-chiorazzo

Hi @brettlangdon ,

it would be great if you could give a look at this PR since it would allow us to build the Datadog dashboard that we would like to have for Django 1 application.

In addition to whatever needs to be fixed, I also ask you for help on the CI part. There is mypy failing on internal modules in which there is no changes mine. Any clue on it?

Thanks!

ca-simone-chiorazzo avatar Sep 26 '22 20:09 ca-simone-chiorazzo

In addition to whatever needs to be fixed, I also ask you for help on the CI part. There is mypy failing on internal modules in which there is no changes mine. Any clue on it?

Thanks!

It looks like mypy just released a new version 0.981 which we automatically use in our mypy check. I'll investigate if this is the cause of our sudden CI failures.

Yun-Kim avatar Sep 26 '22 20:09 Yun-Kim

@ca-simone-chiorazzo This will need a release note, thanks!

majorgreys avatar Sep 30 '22 14:09 majorgreys

@ca-simone-chiorazzo This will need a release note, thanks!

Sorry @majorgreys, is there a guide on how to add a release note for the PR? Thanks!

ca-simone-chiorazzo avatar Sep 30 '22 16:09 ca-simone-chiorazzo

Hi @ca-simone-chiorazzo for the release notes, I couldn't find a guide (we're working on improving this) but basically: running reno new <file_name_for_note> will create the release note and tell you where it is. From there you can just reference other release notes for what the file content should look like: https://github.com/DataDog/dd-trace-py/tree/1.x/releasenotes/notes

ZStriker19 avatar Oct 03 '22 15:10 ZStriker19

@ZStriker19 @majorgreys Release note added! Let me know what do you think

ca-simone-chiorazzo avatar Oct 03 '22 16:10 ca-simone-chiorazzo

Looks like that there are flaky/broken tests related to psycopc and httpx. What's the procedure in this case? It doesn't seems related to my PR

ca-simone-chiorazzo avatar Oct 06 '22 09:10 ca-simone-chiorazzo

Hi folks, I've just noticed that the merge is blocked due to missing signatures on commits. I've set up a GPG signature on my account, but the only way I found to sign commits already pushed is to execute a forced push.

Do you perhaps have some guide or best practice in order to resign commit already pushed?

ca-simone-chiorazzo avatar Oct 14 '22 14:10 ca-simone-chiorazzo

Codecov Report

Merging #4201 (5a47974) into 1.x (dd1b0cf) will decrease coverage by 0.05%. The diff coverage is 32.91%.

@@            Coverage Diff             @@
##              1.x    #4201      +/-   ##
==========================================
- Coverage   78.24%   78.18%   -0.06%     
==========================================
  Files         745      747       +2     
  Lines       59359    59428      +69     
==========================================
+ Hits        46446    46466      +20     
- Misses      12913    12962      +49     
Impacted Files Coverage Δ
ddtrace/contrib/django/__init__.py 100.00% <ø> (ø)
ddtrace/contrib/django/patch.py 83.07% <ø> (ø)
ddtrace/profiling/profiler.py 0.00% <0.00%> (ø)
tests/contrib/flask/test_flask_appsec.py 0.00% <0.00%> (ø)
tests/profiling/gunicorn-app.py 0.00% <0.00%> (ø)
tests/profiling/test_gunicorn.py 0.00% <0.00%> (ø)
tests/tracer/test_trace_utils.py 99.75% <ø> (ø)
ddtrace/appsec/processor.py 92.85% <100.00%> (+0.11%) :arrow_up:
ddtrace/contrib/django/utils.py 92.07% <100.00%> (+0.16%) :arrow_up:
ddtrace/contrib/trace_utils.py 94.61% <100.00%> (-0.05%) :arrow_down:
... and 2 more

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov-commenter avatar Oct 14 '22 14:10 codecov-commenter