Add ASGI support to Django#2656
Conversation
0d2cfd9 to
1f82460
Compare
2c66fbd to
df3694f
Compare
52d3338 to
db445e7
Compare
Using the ASGI middleware we can relatively cleanly add async/ASGI
support for Django.
The previous method of instrumentation was first attempted but it was
decided against for a couple reasons:
- Tracing the ASGI application would require more than just wrapping
the get_response_async method (although this would provide most of
the visibility desired) as we'd need to trace the invocation of the
response method.
- We already have an ASGI middleware implementation.
db445e7 to
8436c69
Compare
|
I was wondering whether we could use https://docs.djangoproject.com/en/3.2/topics/async/#asgiref.sync.sync_to_async |
|
@Kyle-Verhoog this pull request is now in conflict 😩 |
|
@majorgreys looking at the implementation of |
mabdinur
left a comment
There was a problem hiding this comment.
Aside from Gab's comments LGTM
|
@Kyle-Verhoog this pull request is now in conflict 😩 |
914c7d9 to
30d4aa1
Compare
30d4aa1 to
bc1c353
Compare
It gets reused by the ASGI middleware
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2656 +/- ##
==========================================
- Coverage 84.95% 84.93% -0.03%
==========================================
Files 590 591 +1
Lines 43083 43113 +30
==========================================
+ Hits 36601 36617 +16
- Misses 6482 6496 +14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
If I'm understanding correctly, enabling the ASGI middleware will generate a trace with two vs. I'm concerned that this could create confusion to have two Can we have just one? |
|
Oh good catch @majorgreys, I missed that! Yeah we should add checks to only do the middleware if |
e85e959 to
de215d4
Compare
|
@Mergifyio backport 0.51 |
* Add ASGI support to Django
Using the ASGI middleware we can relatively cleanly add async/ASGI
support for Django.
The previous method of instrumentation was first attempted but it was
decided against for a couple reasons:
- Tracing the ASGI application would require more than just wrapping
the get_response_async method (although this would provide most of
the visibility desired) as we'd need to trace the invocation of the
response method.
- We already have an ASGI middleware implementation.
* Store span in ASGI scope
* Don't override distributed tracing setting
It gets reused by the ASGI middleware
* Don't wrap the asgi application when get_response is used for async
* Update ddtrace/contrib/django/patch.py
Co-authored-by: Tahir H. Butt <tahir.butt@datadoghq.com>
Co-authored-by: Brett Langdon <me@brett.is>
(cherry picked from commit 71ca68d)
# Conflicts:
# tests/contrib/django/asgi.py
# tests/snapshots/tests.contrib.django.test_django_snapshots.test_asgi_200_30.snap
# tests/snapshots/tests.contrib.django.test_django_snapshots.test_asgi_200_31.snap
# tests/snapshots/tests.contrib.django.test_django_snapshots.test_asgi_200_3x.snap
# tests/snapshots/tests.contrib.django.test_django_snapshots.test_asgi_500_30.snap
# tests/snapshots/tests.contrib.django.test_django_snapshots.test_asgi_500_31.snap
# tests/snapshots/tests.contrib.django.test_django_snapshots.test_asgi_500_3x.snap
|
Command
|
* Add ASGI support to Django
Using the ASGI middleware we can relatively cleanly add async/ASGI
support for Django.
The previous method of instrumentation was first attempted but it was
decided against for a couple reasons:
- Tracing the ASGI application would require more than just wrapping
the get_response_async method (although this would provide most of
the visibility desired) as we'd need to trace the invocation of the
response method.
- We already have an ASGI middleware implementation.
* Store span in ASGI scope
* Don't override distributed tracing setting
It gets reused by the ASGI middleware
* Don't wrap the asgi application when get_response is used for async
* Update ddtrace/contrib/django/patch.py
Co-authored-by: Tahir H. Butt <tahir.butt@datadoghq.com>
Co-authored-by: Brett Langdon <me@brett.is>
(cherry picked from commit 71ca68d)
# Conflicts:
# tests/contrib/django/asgi.py
# tests/snapshots/tests.contrib.django.test_django_snapshots.test_asgi_200_30.snap
# tests/snapshots/tests.contrib.django.test_django_snapshots.test_asgi_200_31.snap
# tests/snapshots/tests.contrib.django.test_django_snapshots.test_asgi_200_3x.snap
# tests/snapshots/tests.contrib.django.test_django_snapshots.test_asgi_500_30.snap
# tests/snapshots/tests.contrib.django.test_django_snapshots.test_asgi_500_31.snap
# tests/snapshots/tests.contrib.django.test_django_snapshots.test_asgi_500_3x.snap
Co-authored-by: Kyle Verhoog <kyle@verhoog.ca>
Co-authored-by: Brett Langdon <brett.langdon@datadoghq.com>
Motivation
In Django 3.1 the internal implementation was modified to follow a completely different codepath for async requests. Our integration only patches
get_responseand notget_response_asyncwhich means that the top leveldjango.requestspan doesn't get generated.Solution
Builds off of #1812