Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
97251c0
Add arch64 wheel build support (#1917)
odidev Jan 15, 2021
843f87f
Merge branch 'master' of github.com:DataDog/dd-trace-py
Yun-Kim Jan 20, 2021
1912b09
Merge branch 'master' of github.com:DataDog/dd-trace-py
Yun-Kim Jan 20, 2021
7f8a036
Merge branch 'master' of github.com:DataDog/dd-trace-py
Yun-Kim Jan 21, 2021
77560ea
Merge branch 'master' of github.com:DataDog/dd-trace-py
Yun-Kim Jan 27, 2021
17fff49
auto-instrument django wsgi applications
Kyle-Verhoog Nov 18, 2020
98fdf54
Added distributed tracing default false when instrumenting django wit…
Yun-Kim Feb 1, 2021
da4ff4f
Merge branch 'master' of github.com:DataDog/dd-trace-py into wsgi-django
Yun-Kim Feb 1, 2021
c77a236
Merge branch 'master' of github.com:DataDog/dd-trace-py
Yun-Kim Feb 2, 2021
56d141d
Modified snapshot tests for django 1.11 and 2.1
Yun-Kim Feb 2, 2021
07961ba
auto-instrument django wsgi applications
Kyle-Verhoog Nov 18, 2020
a294e42
Added distributed tracing default false when instrumenting django wit…
Yun-Kim Feb 1, 2021
2313ce0
Modified snapshot tests for django 1.11 and 2.1
Yun-Kim Feb 2, 2021
9ce11a5
Merge branch 'wsgi-django' of github.com:Kyle-Verhoog/dd-trace-py int…
Yun-Kim Feb 2, 2021
a97a72e
Merge branch 'master' of github.com:DataDog/dd-trace-py into wsgi-django
Yun-Kim Feb 2, 2021
3eba509
Changed root span service/resource renaming to be wsgi-middleware spe…
Yun-Kim Feb 2, 2021
70e8eab
Fixed snapshot test for django 2.1
Yun-Kim Feb 3, 2021
dc4d139
Merge branch 'master' into wsgi-django
Yun-Kim Feb 3, 2021
a6dc762
Merge branch 'master' of github.com:DataDog/dd-trace-py into wsgi-django
Yun-Kim Feb 8, 2021
110d7c5
auto-instrument django wsgi applications
Kyle-Verhoog Nov 18, 2020
32ebce0
requests: remove context dependence from tests (#1973)
Kyle-Verhoog Feb 2, 2021
6389d40
aiohttp: remove context dependence (#1977)
Kyle-Verhoog Feb 2, 2021
aeff691
Add status_msg to set_http_meta() (#1972)
Yun-Kim Feb 2, 2021
935b59d
Changed root span service/resource renaming to be wsgi-middleware spe…
Yun-Kim Feb 2, 2021
dbb8e04
Update integration.md (#1979)
Kyle-Verhoog Feb 2, 2021
3ed2af5
chore(profiling): decrease max CPU usage for stack profiling to 1% (#…
Feb 2, 2021
24e6a9b
format futures (#1976)
Kyle-Verhoog Feb 2, 2021
5d944a0
Introduce CherryPy Tracing (#1966)
lewisoaten Feb 3, 2021
bef81d1
tracer: move hostname tagging to start_span (#1984)
Kyle-Verhoog Feb 3, 2021
a5cabcd
tests: make context independent (#1986)
Kyle-Verhoog Feb 3, 2021
7ee184b
gevent: remove implementation dependent tests (#1987)
Kyle-Verhoog Feb 3, 2021
30c5394
chore(mergify): warn on PR conflict (#1988)
Feb 3, 2021
b6e4d1a
context: _dd_origin -> dd_origin (#1982)
Kyle-Verhoog Feb 3, 2021
5a2de94
refactor(core): roll context manager into context provider (#1983)
Kyle-Verhoog Feb 3, 2021
f4ad7cc
span: make tests context independent (#1981)
Kyle-Verhoog Feb 3, 2021
1a22719
asyncio: clean-up tests (#1985)
Kyle-Verhoog Feb 3, 2021
0457e5e
httplib: enable distributed tracing by default (#1991)
Kyle-Verhoog Feb 4, 2021
b5bae01
feat(profiling): support most uwsgi modes (#1953)
Feb 5, 2021
c02e844
ci: disable output buffering (#1994)
majorgreys Feb 5, 2021
5e96a83
django: add measured tag to root span (#1997)
Kyle-Verhoog Feb 5, 2021
92c5e4e
Merge branch 'wsgi-django' of github.com:Kyle-Verhoog/dd-trace-py int…
Yun-Kim Feb 10, 2021
b1e4f91
Merge branch 'master' into wsgi-django
Yun-Kim Feb 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ddtrace/contrib/django/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ def traced_get_response(django, pin, func, instance, args, kwargs):
log.debug("Failed to trace django request %r", args, exc_info=True)
return func(*args, **kwargs)
else:
root_span = pin.tracer.current_root_span()
if root_span and root_span.name == "wsgi.request":
root_span.resource = resource
root_span.service = trace_utils.int_service(pin, config.django)
with pin.tracer.trace(
"django.request",
resource=resource,
Expand Down Expand Up @@ -553,6 +557,15 @@ def traced_as_view(django, pin, func, instance, args, kwargs):
return wrapt.FunctionWrapper(view, traced_func(django, "django.view", resource=func_name(view)))


@trace_utils.with_traced_module
def traced_get_wsgi_application(django, pin, func, instance, args, kwargs):
from ddtrace.contrib.wsgi import DDWSGIMiddleware

config.django["distributed_tracing"] = False

return DDWSGIMiddleware(func(*args, **kwargs))


def _patch(django):
Pin().onto(django)
trace_utils.wrap(django, "apps.registry.Apps.populate", traced_populate(django))
Expand Down Expand Up @@ -584,6 +597,10 @@ def _patch(django):
import django.views.generic.base
trace_utils.wrap(django, "views.generic.base.View.as_view", traced_as_view(django))

if "django.core.wsgi" not in sys.modules:
import django.core.wsgi
trace_utils.wrap(django, "core.wsgi.get_wsgi_application", traced_get_wsgi_application(django))


def patch():
# DEV: this import will eventually be replaced with the module given from an import hook
Expand All @@ -610,6 +627,7 @@ def _unpatch(django):
for conn in django.db.connections.all():
trace_utils.unwrap(conn, "cursor")
trace_utils.unwrap(django.db.connections, "all")
trace_utils.unwrap(django.core.wsgi, "get_wsgi_application")


def unpatch():
Expand Down
8 changes: 8 additions & 0 deletions ddtrace/contrib/wsgi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
The Datadog WSGI middleware traces all WSGI requests.


Enabling
~~~~~~~~

The WSGI instrumentation will be automatically added to a Django or Flask
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The WSGI instrumentation will be automatically added to a Django or Flask
The WSGI instrumentation will be automatically added to Django

application when using :ref:`ddtrace-run<ddtracerun>` or
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
application when using :ref:`ddtrace-run<ddtracerun>` or
applications when using :ref:`ddtrace-run<ddtracerun>` or

:ref:`patch_all()<patch_all>`.


Usage
~~~~~

Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/django-wsgi-e46a93f2fb7966a9.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
features:
- |
Auto-instrument Django get_wsgi_application.
3 changes: 3 additions & 0 deletions riotfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def select_pys(min_version=min(SUPPORTED_PYTHON_VERSIONS), max_version=max(SUPPO
Venv(
name="django",
command="pytest {cmdargs} tests/contrib/django",
pkgs={
"WebTest": latest,
},
venvs=[
Venv(
pys=select_pys(max_version=3.6),
Expand Down
2 changes: 1 addition & 1 deletion tests/contrib/django/django1_app/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

ALLOWED_HOSTS = [
"testserver",
"*",
]

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down
2 changes: 1 addition & 1 deletion tests/contrib/django/django_app/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

ALLOWED_HOSTS = [
"testserver",
"*",
]

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down
16 changes: 14 additions & 2 deletions tests/contrib/django/test_django_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def test_safe_string_encoding(client):
assert client.get("/safe-template/").status_code == 200


@pytest.mark.django_db
def test_404_exceptions(client):
assert client.get("/404-view/").status_code == 404


@pytest.mark.django_db
@snapshot(
variants={
"18x": django.VERSION < (1, 9),
Expand All @@ -65,5 +71,11 @@ def test_safe_string_encoding(client):
"": django.VERSION >= (2, 2),
}
)
def test_404_exceptions(client):
assert client.get("/404-view/").status_code == 404
def test_wsgi_app():
from django.core.wsgi import get_wsgi_application
from webtest import TestApp

app = TestApp(get_wsgi_application())
resp = app.get("/")
assert resp.status == "200 OK"
assert resp.status_int == 200
Loading