Repository: DataDog/dd-trace-py

Issue:
Django ASGI capture `django.http.response.Http404` as error
### Which version of dd-trace-py are you using?
0.43.1

### DD-agent version
7

### Which version of the libraries are you using?
```
asgiref==3.3.1
ddtrace==0.43.1
Django==3.1.3
gunicorn==20.0.4
uvicorn==0.12.2
```

asgi.py
```
import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Grasp.settings')
django_asgi_application = get_asgi_application()

from ddtrace.contrib.asgi import TraceMiddleware  # noqa

application = TraceMiddleware(django_asgi_application)
```

settings.py
```
import ddtrace

ddtrace.tracer.configure(hostname='127.0.0.1')
ddtrace.config.django['service_name'] = 'my-service'
ddtrace.config.django['analytics_enabled'] = True
ddtrace.config.asgi['analytics_enabled'] = True
ddtrace.config.asgi['service_name'] = 'my-service'
ddtrace.tracer.set_tags({'env': 'production'})
ddtrace.patch_all()
```

running the server
```
gunicorn -w 4 -b 0.0.0.0:8000 -k uvicorn.workers.UvicornWorker myapp.asgi:application
```

### How can we reproduce your problem?
Just do a request to where it should return 404 the error appears on APM traces

<img width="806" alt="Screenshot 2020-11-11 at 16 47 49" src="https://user-images.githubusercontent.com/1225902/98833409-42aae380-243e-11eb-965b-933e72dbea99.png">



Discussion:
@bertonha thanks for reporting! This seems like it's being done implicitly by our DRF integration (it'll just report any exception as an error). I'll schedule this to be fixed in v0.45.

Resolving patch:
diff --git a/ddtrace/contrib/django/patch.py b/ddtrace/contrib/django/patch.py
--- a/ddtrace/contrib/django/patch.py
+++ b/ddtrace/contrib/django/patch.py
@@ -214,11 +214,14 @@ def traced_populate(django, pin, func, instance, args, kwargs):
     return ret
 
 
-def traced_func(django, name, resource=None):
+def traced_func(django, name, resource=None, ignored_excs=None):
     """Returns a function to trace Django functions."""
 
     def wrapped(django, pin, func, instance, args, kwargs):
-        with pin.tracer.trace(name, resource=resource):
+        with pin.tracer.trace(name, resource=resource) as s:
+            if ignored_excs:
+                for exc in ignored_excs:
+                    s._ignore_exception(exc)
             return func(*args, **kwargs)
 
     return trace_utils.with_traced_module(wrapped)(django)
@@ -509,7 +512,9 @@ def _instrument_view(django, view):
 
     # If the view itself is not wrapped, wrap it
     if not isinstance(view, wrapt.ObjectProxy):
-        view = wrapt.FunctionWrapper(view, traced_func(django, "django.view", resource=func_name(view)))
+        view = wrapt.FunctionWrapper(
+            view, traced_func(django, "django.view", resource=func_name(view), ignored_excs=[django.http.Http404])
+        )
     return view
 
 


Test patch:
diff --git a/tests/contrib/django/django_app/urls.py b/tests/contrib/django/django_app/urls.py
--- a/tests/contrib/django/django_app/urls.py
+++ b/tests/contrib/django/django_app/urls.py
@@ -56,4 +56,5 @@ def authenticated_view(request):
     url(r"^composed-template-view/$", views.ComposedTemplateView.as_view(), name="composed-template-view"),
     url(r"^composed-get-view/$", views.ComposedGetView.as_view(), name="composed-get-view"),
     url(r"^composed-view/$", views.ComposedView.as_view(), name="composed-view"),
+    url(r"^404-view/$", views.not_found_view, name="404-view"),
 ]
diff --git a/tests/contrib/django/test_django_snapshots.py b/tests/contrib/django/test_django_snapshots.py
--- a/tests/contrib/django/test_django_snapshots.py
+++ b/tests/contrib/django/test_django_snapshots.py
@@ -55,3 +55,15 @@ def test_middleware_trace_partial_based_view(client):
 )
 def test_safe_string_encoding(client):
     assert client.get("/safe-template/").status_code == 200
+
+
+@snapshot(
+    variants={
+        "18x": django.VERSION < (1, 9),
+        "111x": (1, 9) <= django.VERSION < (1, 12),
+        "21x": (1, 12) < django.VERSION < (2, 2),
+        "": django.VERSION >= (2, 2),
+    }
+)
+def test_404_exceptions(client):
+    assert client.get("/404-view/").status_code == 404
diff --git a/tests/contrib/django/views.py b/tests/contrib/django/views.py
--- a/tests/contrib/django/views.py
+++ b/tests/contrib/django/views.py
@@ -6,7 +6,7 @@
 
 from django.contrib.auth.models import User
 from django.contrib.syndication.views import Feed
-from django.http import HttpResponse
+from django.http import HttpResponse, Http404
 from django.template import loader
 from django.template.response import TemplateResponse
 from django.views.generic import ListView, TemplateView, View
@@ -162,3 +162,7 @@ def dispatch(self, request):
 
 class ComposedView(TemplateView, CustomDispatchView):
     template_name = "custom_dispatch.html"
+
+
+def not_found_view(request):
+    raise Http404("DNE")
diff --git a/tests/snapshots/tests.contrib.django.test_django_snapshots.test_404_exceptions.snap b/tests/snapshots/tests.contrib.django.test_django_snapshots.test_404_exceptions.snap
new file mode 100644
--- /dev/null
+++ b/tests/snapshots/tests.contrib.django.test_django_snapshots.test_404_exceptions.snap
@@ -0,0 +1,294 @@
+[[{"name" "django.request"
+   "service" "django"
+   "resource" "GET ^404-view/$"
+   "type" "web"
+   "error" 0
+   "span_id" 0
+   "trace_id" 0
+   "parent_id" nil
+   "start" 1606875759623332453
+   "duration" 10684014
+   "meta" {"runtime-id" "c81279f5dd4c4c43a1e5aab4f9cb69df"
+           "http.route" "^404-view/$"
+           "http.url" "http://testserver/404-view/"
+           "django.user.is_authenticated" "False"
+           "http.status_code" "404"
+           "http.method" "GET"
+           "django.response.class" "django.http.response.HttpResponseNotFound"
+           "django.request.class" "django.core.handlers.wsgi.WSGIRequest"
+           "django.view" "404-view"}
+   "metrics" {"_dd.agent_psr" 1.0
+              "_sampling_priority_v1" 1
+              "system.pid" 5117}}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.contrib.sessions.middleware.SessionMiddleware.__call__"
+       "error" 0
+       "span_id" 1
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606875759623852622
+       "duration" 9715658}
+          {"name" "django.middleware"
+           "service" "django"
+           "resource" "django.contrib.sessions.middleware.SessionMiddleware.process_request"
+           "error" 0
+           "span_id" 2
+           "trace_id" 0
+           "parent_id" 1
+           "start" 1606875759623889130
+           "duration" 296715}
+          {"name" "django.middleware"
+           "service" "django"
+           "resource" "django.middleware.common.CommonMiddleware.__call__"
+           "error" 0
+           "span_id" 3
+           "trace_id" 0
+           "parent_id" 1
+           "start" 1606875759624220786
+           "duration" 9306315}
+              {"name" "django.middleware"
+               "service" "django"
+               "resource" "django.middleware.common.CommonMiddleware.process_request"
+               "error" 0
+               "span_id" 5
+               "trace_id" 0
+               "parent_id" 3
+               "start" 1606875759624251876
+               "duration" 456852}
+              {"name" "django.middleware"
+               "service" "django"
+               "resource" "django.middleware.csrf.CsrfViewMiddleware.__call__"
+               "error" 0
+               "span_id" 6
+               "trace_id" 0
+               "parent_id" 3
+               "start" 1606875759624738903
+               "duration" 8745117}
+                  {"name" "django.middleware"
+                   "service" "django"
+                   "resource" "django.middleware.csrf.CsrfViewMiddleware.process_request"
+                   "error" 0
+                   "span_id" 8
+                   "trace_id" 0
+                   "parent_id" 6
+                   "start" 1606875759624769663
+                   "duration" 15016}
+                  {"name" "django.middleware"
+                   "service" "django"
+                   "resource" "django.contrib.auth.middleware.AuthenticationMiddleware.__call__"
+                   "error" 0
+                   "span_id" 9
+                   "trace_id" 0
+                   "parent_id" 6
+                   "start" 1606875759624807370
+                   "duration" 8642412}
+                      {"name" "django.middleware"
+                       "service" "django"
+                       "resource" "django.contrib.auth.middleware.AuthenticationMiddleware.process_request"
+                       "error" 0
+                       "span_id" 11
+                       "trace_id" 0
+                       "parent_id" 9
+                       "start" 1606875759624833203
+                       "duration" 12853}
+                      {"name" "django.middleware"
+                       "service" "django"
+                       "resource" "django.contrib.messages.middleware.MessageMiddleware.__call__"
+                       "error" 0
+                       "span_id" 12
+                       "trace_id" 0
+                       "parent_id" 9
+                       "start" 1606875759624868562
+                       "duration" 8575085}
+                          {"name" "django.middleware"
+                           "service" "django"
+                           "resource" "django.contrib.messages.middleware.MessageMiddleware.process_request"
+                           "error" 0
+                           "span_id" 13
+                           "trace_id" 0
+                           "parent_id" 12
+                           "start" 1606875759624893088
+                           "duration" 1562764}
+                          {"name" "django.middleware"
+                           "service" "django"
+                           "resource" "django.middleware.clickjacking.XFrameOptionsMiddleware.__call__"
+                           "error" 0
+                           "span_id" 14
+                           "trace_id" 0
+                           "parent_id" 12
+                           "start" 1606875759626486711
+                           "duration" 6915828}
+                              {"name" "django.middleware"
+                               "service" "django"
+                               "resource" "django.middleware.security.SecurityMiddleware.__call__"
+                               "error" 0
+                               "span_id" 16
+                               "trace_id" 0
+                               "parent_id" 14
+                               "start" 1606875759626521476
+                               "duration" 6835129}
+                                  {"name" "django.middleware"
+                                   "service" "django"
+                                   "resource" "django.middleware.security.SecurityMiddleware.process_request"
+                                   "error" 0
+                                   "span_id" 18
+                                   "trace_id" 0
+                                   "parent_id" 16
+                                   "start" 1606875759626548320
+                                   "duration" 9846}
+                                  {"name" "django.middleware"
+                                   "service" "django"
+                                   "resource" "tests.contrib.django.middleware.ClsMiddleware.__call__"
+                                   "error" 0
+                                   "span_id" 19
+                                   "trace_id" 0
+                                   "parent_id" 16
+                                   "start" 1606875759626579601
+                                   "duration" 6723494}
+                                      {"name" "django.middleware"
+                                       "service" "django"
+                                       "resource" "tests.contrib.django.middleware.EverythingMiddleware"
+                                       "error" 0
+                                       "span_id" 21
+                                       "trace_id" 0
+                                       "parent_id" 19
+                                       "start" 1606875759626602608
+                                       "duration" 6694914}
+                                          {"name" "django.middleware"
+                                           "service" "django"
+                                           "resource" "tests.contrib.django.middleware.EverythingMiddleware.__call__"
+                                           "error" 0
+                                           "span_id" 22
+                                           "trace_id" 0
+                                           "parent_id" 21
+                                           "start" 1606875759626623283
+                                           "duration" 6667630}
+                                              {"name" "django.middleware"
+                                               "service" "django"
+                                               "resource" "django.middleware.csrf.CsrfViewMiddleware.process_view"
+                                               "error" 0
+                                               "span_id" 23
+                                               "trace_id" 0
+                                               "parent_id" 22
+                                               "start" 1606875759626703042
+                                               "duration" 13086}
+                                              {"name" "django.middleware"
+                                               "service" "django"
+                                               "resource" "tests.contrib.django.middleware.EverythingMiddleware.process_view"
+                                               "error" 0
+                                               "span_id" 24
+                                               "trace_id" 0
+                                               "parent_id" 22
+                                               "start" 1606875759626736144
+                                               "duration" 9924}
+                                              {"name" "django.view"
+                                               "service" "django"
+                                               "resource" "tests.contrib.django.views.not_found_view"
+                                               "error" 0
+                                               "span_id" 25
+                                               "trace_id" 0
+                                               "parent_id" 22
+                                               "start" 1606875759626803479
+                                               "duration" 13950}
+                                              {"name" "django.middleware"
+                                               "service" "django"
+                                               "resource" "tests.contrib.django.middleware.EverythingMiddleware.process_exception"
+                                               "error" 0
+                                               "span_id" 26
+                                               "trace_id" 0
+                                               "parent_id" 22
+                                               "start" 1606875759626839151
+                                               "duration" 10504}
+                                              {"name" "django.middleware"
+                                               "service" "django"
+                                               "resource" "django.middleware.csrf.CsrfViewMiddleware.process_request"
+                                               "error" 0
+                                               "span_id" 27
+                                               "trace_id" 0
+                                               "parent_id" 22
+                                               "start" 1606875759626904835
+                                               "duration" 10719}
+                                              {"name" "django.middleware"
+                                               "service" "django"
+                                               "resource" "django.middleware.csrf.CsrfViewMiddleware.process_view"
+                                               "error" 0
+                                               "span_id" 28
+                                               "trace_id" 0
+                                               "parent_id" 22
+                                               "start" 1606875759626936393
+                                               "duration" 8767}
+                                              {"name" "django.template.render"
+                                               "service" "django"
+                                               "resource" "django.template.base.Template.render"
+                                               "type" "template"
+                                               "error" 0
+                                               "span_id" 29
+                                               "trace_id" 0
+                                               "parent_id" 22
+                                               "start" 1606875759632832321
+                                               "duration" 163590
+                                               "meta" {"django.template.engine.class" "django.template.engine.Engine"}}
+                                              {"name" "django.middleware"
+                                               "service" "django"
+                                               "resource" "django.middleware.csrf.CsrfViewMiddleware.process_response"
+                                               "error" 0
+                                               "span_id" 30
+                                               "trace_id" 0
+                                               "parent_id" 22
+                                               "start" 1606875759633267006
+                                               "duration" 13071}
+                                  {"name" "django.middleware"
+                                   "service" "django"
+                                   "resource" "django.middleware.security.SecurityMiddleware.process_response"
+                                   "error" 0
+                                   "span_id" 20
+                                   "trace_id" 0
+                                   "parent_id" 16
+                                   "start" 1606875759633325351
+                                   "duration" 24222}
+                              {"name" "django.middleware"
+                               "service" "django"
+                               "resource" "django.middleware.clickjacking.XFrameOptionsMiddleware.process_response"
+                               "error" 0
+                               "span_id" 17
+                               "trace_id" 0
+                               "parent_id" 14
+                               "start" 1606875759633377978
+                               "duration" 17997}
+                          {"name" "django.middleware"
+                           "service" "django"
+                           "resource" "django.contrib.messages.middleware.MessageMiddleware.process_response"
+                           "error" 0
+                           "span_id" 15
+                           "trace_id" 0
+                           "parent_id" 12
+                           "start" 1606875759633423098
+                           "duration" 14278}
+                  {"name" "django.middleware"
+                   "service" "django"
+                   "resource" "django.middleware.csrf.CsrfViewMiddleware.process_response"
+                   "error" 0
+                   "span_id" 10
+                   "trace_id" 0
+                   "parent_id" 6
+                   "start" 1606875759633469380
+                   "duration" 8792}
+              {"name" "django.middleware"
+               "service" "django"
+               "resource" "django.middleware.common.CommonMiddleware.process_response"
+               "error" 0
+               "span_id" 7
+               "trace_id" 0
+               "parent_id" 3
+               "start" 1606875759633503644
+               "duration" 17178}
+          {"name" "django.middleware"
+           "service" "django"
+           "resource" "django.contrib.sessions.middleware.SessionMiddleware.process_response"
+           "error" 0
+           "span_id" 4
+           "trace_id" 0
+           "parent_id" 1
+           "start" 1606875759633547149
+           "duration" 14974}]]
diff --git a/tests/snapshots/tests.contrib.django.test_django_snapshots.test_404_exceptions_111x.snap b/tests/snapshots/tests.contrib.django.test_django_snapshots.test_404_exceptions_111x.snap
new file mode 100644
--- /dev/null
+++ b/tests/snapshots/tests.contrib.django.test_django_snapshots.test_404_exceptions_111x.snap
@@ -0,0 +1,175 @@
+[[{"name" "django.request"
+   "service" "django"
+   "resource" "GET 404"
+   "type" "web"
+   "error" 0
+   "span_id" 0
+   "trace_id" 0
+   "parent_id" nil
+   "start" 1606877734043376000
+   "duration" 1585000
+   "meta" {"runtime-id" "bddaabb21d4f47838a28412a130065e7"
+           "http.method" "GET"
+           "django.response.class" "django.http.response.HttpResponseNotFound"
+           "http.url" "http://testserver/404-view/"
+           "django.request.class" "django.core.handlers.wsgi.WSGIRequest"
+           "http.status_code" "404"
+           "django.user.is_authenticated" "False"}
+   "metrics" {"_dd.agent_psr" 1.0
+              "_sampling_priority_v1" 1
+              "system.pid" 8472}}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.contrib.sessions.middleware.SessionMiddleware.process_request"
+       "error" 0
+       "span_id" 1
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734043448000
+       "duration" 41000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.common.CommonMiddleware.process_request"
+       "error" 0
+       "span_id" 2
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734043521000
+       "duration" 44000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.csrf.CsrfViewMiddleware.process_request"
+       "error" 0
+       "span_id" 3
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734043593000
+       "duration" 14000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.contrib.auth.middleware.AuthenticationMiddleware.process_request"
+       "error" 0
+       "span_id" 4
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734043631000
+       "duration" 16000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.contrib.auth.middleware.SessionAuthenticationMiddleware.process_request"
+       "error" 0
+       "span_id" 5
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734043670000
+       "duration" 9000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.contrib.messages.middleware.MessageMiddleware.process_request"
+       "error" 0
+       "span_id" 6
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734043701000
+       "duration" 34000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.security.SecurityMiddleware.process_request"
+       "error" 0
+       "span_id" 7
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734043758000
+       "duration" 11000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.csrf.CsrfViewMiddleware.process_request"
+       "error" 0
+       "span_id" 8
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734043870000
+       "duration" 13000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.csrf.CsrfViewMiddleware.process_view"
+       "error" 0
+       "span_id" 9
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734043911000
+       "duration" 16000}
+      {"name" "django.template.render"
+       "service" "django"
+       "resource" "django.template.base.Template.render"
+       "type" "template"
+       "error" 0
+       "span_id" 10
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734044178000
+       "duration" 111000
+       "meta" {"django.template.engine.class" "django.template.engine.Engine"}}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.csrf.CsrfViewMiddleware.process_response"
+       "error" 0
+       "span_id" 11
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734044364000
+       "duration" 14000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.security.SecurityMiddleware.process_response"
+       "error" 0
+       "span_id" 12
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734044409000
+       "duration" 11000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.clickjacking.XFrameOptionsMiddleware.process_response"
+       "error" 0
+       "span_id" 13
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734044443000
+       "duration" 49000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.contrib.messages.middleware.MessageMiddleware.process_response"
+       "error" 0
+       "span_id" 14
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734044543000
+       "duration" 12000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.csrf.CsrfViewMiddleware.process_response"
+       "error" 0
+       "span_id" 15
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734044577000
+       "duration" 23000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.common.CommonMiddleware.process_response"
+       "error" 0
+       "span_id" 16
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734044621000
+       "duration" 21000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.contrib.sessions.middleware.SessionMiddleware.process_response"
+       "error" 0
+       "span_id" 17
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877734044664000
+       "duration" 15000}]]
diff --git a/tests/snapshots/tests.contrib.django.test_django_snapshots.test_404_exceptions_18x.snap b/tests/snapshots/tests.contrib.django.test_django_snapshots.test_404_exceptions_18x.snap
new file mode 100644
--- /dev/null
+++ b/tests/snapshots/tests.contrib.django.test_django_snapshots.test_404_exceptions_18x.snap
@@ -0,0 +1,157 @@
+[[{"name" "django.request"
+   "service" "django"
+   "resource" "GET 404"
+   "type" "web"
+   "error" 0
+   "span_id" 0
+   "trace_id" 0
+   "parent_id" nil
+   "start" 1606877719264242000
+   "duration" 1798000
+   "meta" {"runtime-id" "9ef1e4b9b98748cea9337b9d914a8163"
+           "http.method" "GET"
+           "django.response.class" "django.http.response.HttpResponseNotFound"
+           "http.url" "http://testserver/404-view/"
+           "django.request.class" "django.core.handlers.wsgi.WSGIRequest"
+           "http.status_code" "404"
+           "django.user.is_authenticated" "False"}
+   "metrics" {"_dd.agent_psr" 1.0
+              "_sampling_priority_v1" 1
+              "system.pid" 8273}}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.contrib.sessions.middleware.SessionMiddleware.process_request"
+       "error" 0
+       "span_id" 1
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877719264325000
+       "duration" 46000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.common.CommonMiddleware.process_request"
+       "error" 0
+       "span_id" 2
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877719264409000
+       "duration" 38000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.contrib.auth.middleware.AuthenticationMiddleware.process_request"
+       "error" 0
+       "span_id" 3
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877719264512000
+       "duration" 18000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.contrib.auth.middleware.SessionAuthenticationMiddleware.process_request"
+       "error" 0
+       "span_id" 4
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877719264568000
+       "duration" 10000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.contrib.messages.middleware.MessageMiddleware.process_request"
+       "error" 0
+       "span_id" 5
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877719264601000
+       "duration" 31000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.security.SecurityMiddleware.process_request"
+       "error" 0
+       "span_id" 6
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877719264663000
+       "duration" 11000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.csrf.CsrfViewMiddleware.process_view"
+       "error" 0
+       "span_id" 7
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877719264827000
+       "duration" 125000}
+      {"name" "django.template.render"
+       "service" "django"
+       "resource" "django.template.base.Template.render"
+       "type" "template"
+       "error" 0
+       "span_id" 8
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877719265370000
+       "duration" 169000
+       "meta" {"django.template.engine.class" "django.template.engine.Engine"}}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.csrf.CsrfViewMiddleware.process_response"
+       "error" 0
+       "span_id" 9
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877719265618000
+       "duration" 15000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.security.SecurityMiddleware.process_response"
+       "error" 0
+       "span_id" 10
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877719265662000
+       "duration" 12000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.clickjacking.XFrameOptionsMiddleware.process_response"
+       "error" 0
+       "span_id" 11
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877719265698000
+       "duration" 22000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.contrib.messages.middleware.MessageMiddleware.process_response"
+       "error" 0
+       "span_id" 12
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877719265744000
+       "duration" 14000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.csrf.CsrfViewMiddleware.process_response"
+       "error" 0
+       "span_id" 13
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877719265782000
+       "duration" 11000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.middleware.common.CommonMiddleware.process_response"
+       "error" 0
+       "span_id" 14
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877719265815000
+       "duration" 11000}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.contrib.sessions.middleware.SessionMiddleware.process_response"
+       "error" 0
+       "span_id" 15
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877719265849000
+       "duration" 18000}]]
diff --git a/tests/snapshots/tests.contrib.django.test_django_snapshots.test_404_exceptions_21x.snap b/tests/snapshots/tests.contrib.django.test_django_snapshots.test_404_exceptions_21x.snap
new file mode 100644
--- /dev/null
+++ b/tests/snapshots/tests.contrib.django.test_django_snapshots.test_404_exceptions_21x.snap
@@ -0,0 +1,293 @@
+[[{"name" "django.request"
+   "service" "django"
+   "resource" "GET tests.contrib.django.views.not_found_view"
+   "type" "web"
+   "error" 0
+   "span_id" 0
+   "trace_id" 0
+   "parent_id" nil
+   "start" 1606877874181336142
+   "duration" 2069611
+   "meta" {"runtime-id" "df2f384ab5c14aebbd427098639d616e"
+           "django.view" "404-view"
+           "django.request.class" "django.core.handlers.wsgi.WSGIRequest"
+           "django.user.is_authenticated" "False"
+           "django.response.class" "django.http.response.HttpResponseNotFound"
+           "http.method" "GET"
+           "http.url" "http://testserver/404-view/"
+           "http.status_code" "404"}
+   "metrics" {"_dd.agent_psr" 1.0
+              "_sampling_priority_v1" 1
+              "system.pid" 9264}}
+      {"name" "django.middleware"
+       "service" "django"
+       "resource" "django.contrib.sessions.middleware.SessionMiddleware.__call__"
+       "error" 0
+       "span_id" 1
+       "trace_id" 0
+       "parent_id" 0
+       "start" 1606877874181416819
+       "duration" 1714553}
+          {"name" "django.middleware"
+           "service" "django"
+           "resource" "django.contrib.sessions.middleware.SessionMiddleware.process_request"
+           "error" 0
+           "span_id" 2
+           "trace_id" 0
+           "parent_id" 1
+           "start" 1606877874181446591
+           "duration" 52108}
+          {"name" "django.middleware"
+           "service" "django"
+           "resource" "django.middleware.common.CommonMiddleware.__call__"
+           "error" 0
+           "span_id" 3
+           "trace_id" 0
+           "parent_id" 1
+           "start" 1606877874181529538
+           "duration" 1559681}
+              {"name" "django.middleware"
+               "service" "django"
+               "resource" "django.middleware.common.CommonMiddleware.process_request"
+               "error" 0
+               "span_id" 5
+               "trace_id" 0
+               "parent_id" 3
+               "start" 1606877874181554109
+               "duration" 38574}
+              {"name" "django.middleware"
+               "service" "django"
+               "resource" "django.middleware.csrf.CsrfViewMiddleware.__call__"
+               "error" 0
+               "span_id" 6
+               "trace_id" 0
+               "parent_id" 3
+               "start" 1606877874181618052
+               "duration" 1425492}
+                  {"name" "django.middleware"
+                   "service" "django"
+                   "resource" "django.middleware.csrf.CsrfViewMiddleware.process_request"
+                   "error" 0
+                   "span_id" 8
+                   "trace_id" 0
+                   "parent_id" 6
+                   "start" 1606877874181641475
+                   "duration" 11166}
+                  {"name" "django.middleware"
+                   "service" "django"
+                   "resource" "django.contrib.auth.middleware.AuthenticationMiddleware.__call__"
+                   "error" 0
+                   "span_id" 9
+                   "trace_id" 0
+                   "parent_id" 6
+                   "start" 1606877874181674822
+                   "duration" 1333542}
+                      {"name" "django.middleware"
+                       "service" "django"
+                       "resource" "django.contrib.auth.middleware.AuthenticationMiddleware.process_request"
+                       "error" 0
+                       "span_id" 11
+                       "trace_id" 0
+                       "parent_id" 9
+                       "start" 1606877874181697065
+                       "duration" 15384}
+                      {"name" "django.middleware"
+                       "service" "django"
+                       "resource" "django.contrib.messages.middleware.MessageMiddleware.__call__"
+                       "error" 0
+                       "span_id" 12
+                       "trace_id" 0
+                       "parent_id" 9
+                       "start" 1606877874181735503
+                       "duration" 1266582}
+                          {"name" "django.middleware"
+                           "service" "django"
+                           "resource" "django.contrib.messages.middleware.MessageMiddleware.process_request"
+                           "error" 0
+                           "span_id" 13
+                           "trace_id" 0
+                           "parent_id" 12
+                           "start" 1606877874181757178
+                           "duration" 190112}
+                          {"name" "django.middleware"
+                           "service" "django"
+                           "resource" "django.middleware.clickjacking.XFrameOptionsMiddleware.__call__"
+                           "error" 0
+                           "span_id" 14
+                           "trace_id" 0
+                           "parent_id" 12
+                           "start" 1606877874181976378
+                           "duration" 987394}
+                              {"name" "django.middleware"
+                               "service" "django"
+                               "resource" "django.middleware.security.SecurityMiddleware.__call__"
+                               "error" 0
+                               "span_id" 16
+                               "trace_id" 0
+                               "parent_id" 14
+                               "start" 1606877874182001674
+                               "duration" 917112}
+                                  {"name" "django.middleware"
+                                   "service" "django"
+                                   "resource" "django.middleware.security.SecurityMiddleware.process_request"
+                                   "error" 0
+                                   "span_id" 18
+                                   "trace_id" 0
+                                   "parent_id" 16
+                                   "start" 1606877874182024031
+                                   "duration" 9589}
+                                  {"name" "django.middleware"
+                                   "service" "django"
+                                   "resource" "tests.contrib.django.middleware.ClsMiddleware.__call__"
+                                   "error" 0
+                                   "span_id" 19
+                                   "trace_id" 0
+                                   "parent_id" 16
+                                   "start" 1606877874182055504
+                                   "duration" 823445}
+                                      {"name" "django.middleware"
+                                       "service" "django"
+                                       "resource" "tests.contrib.django.middleware.EverythingMiddleware"
+                                       "error" 0
+                                       "span_id" 21
+                                       "trace_id" 0
+                                       "parent_id" 19
+                                       "start" 1606877874182077958
+                                       "duration" 794966}
+                                          {"name" "django.middleware"
+                                           "service" "django"
+                                           "resource" "tests.contrib.django.middleware.EverythingMiddleware.__call__"
+                                           "error" 0
+                                           "span_id" 22
+                                           "trace_id" 0
+                                           "parent_id" 21
+                                           "start" 1606877874182098960
+                                           "duration" 766990}
+                                              {"name" "django.middleware"
+                                               "service" "django"
+                                               "resource" "django.middleware.csrf.CsrfViewMiddleware.process_view"
+                                               "error" 0
+                                               "span_id" 23
+                                               "trace_id" 0
+                                               "parent_id" 22
+                                               "start" 1606877874182180385
+                                               "duration" 13461}
+                                              {"name" "django.middleware"
+                                               "service" "django"
+                                               "resource" "tests.contrib.django.middleware.EverythingMiddleware.process_view"
+                                               "error" 0
+                                               "span_id" 24
+                                               "trace_id" 0
+                                               "parent_id" 22
+                                               "start" 1606877874182215035
+                                               "duration" 8644}
+                                              {"name" "django.view"
+                                               "service" "django"
+                                               "resource" "tests.contrib.django.views.not_found_view"
+                                               "error" 0
+                                               "span_id" 25
+                                               "trace_id" 0
+                                               "parent_id" 22
+                                               "start" 1606877874182259212
+                                               "duration" 21564}
+                                              {"name" "django.middleware"
+                                               "service" "django"
+                                               "resource" "tests.contrib.django.middleware.EverythingMiddleware.process_exception"
+                                               "error" 0
+                                               "span_id" 26
+                                               "trace_id" 0
+                                               "parent_id" 22
+                                               "start" 1606877874182304438
+                                               "duration" 10496}
+                                              {"name" "django.middleware"
+                                               "service" "django"
+                                               "resource" "django.middleware.csrf.CsrfViewMiddleware.process_request"
+                                               "error" 0
+                                               "span_id" 27
+                                               "trace_id" 0
+                                               "parent_id" 22
+                                               "start" 1606877874182366104
+                                               "duration" 11250}
+                                              {"name" "django.middleware"
+                                               "service" "django"
+                                               "resource" "django.middleware.csrf.CsrfViewMiddleware.process_view"
+                                               "error" 0
+                                               "span_id" 28
+                                               "trace_id" 0
+                                               "parent_id" 22
+                                               "start" 1606877874182400608
+                                               "duration" 9069}
+                                              {"name" "django.template.render"
+                                               "service" "django"
+                                               "resource" "django.template.base.Template.render"
+                                               "type" "template"
+                                               "error" 0
+                                               "span_id" 29
+                                               "trace_id" 0
+                                               "parent_id" 22
+                                               "start" 1606877874182681463
+                                               "duration" 106237
+                                               "meta" {"django.template.engine.class" "django.template.engine.Engine"}}
+                                              {"name" "django.middleware"
+                                               "service" "django"
+                                               "resource" "django.middleware.csrf.CsrfViewMiddleware.process_response"
+                                               "error" 0
+                                               "span_id" 30
+                                               "trace_id" 0
+                                               "parent_id" 22
+                                               "start" 1606877874182844380
+                                               "duration" 11571}
+                                  {"name" "django.middleware"
+                                   "service" "django"
+                                   "resource" "django.middleware.security.SecurityMiddleware.process_response"
+                                   "error" 0
+                                   "span_id" 20
+                                   "trace_id" 0
+                                   "parent_id" 16
+                                   "start" 1606877874182902170
+                                   "duration" 9945}
+                              {"name" "django.middleware"
+                               "service" "django"
+                               "resource" "django.middleware.clickjacking.XFrameOptionsMiddleware.process_response"
+                               "error" 0
+                               "span_id" 17
+                               "trace_id" 0
+                               "parent_id" 14
+                               "start" 1606877874182940073
+                               "duration" 16845}
+                          {"name" "django.middleware"
+                           "service" "django"
+                           "resource" "django.contrib.messages.middleware.MessageMiddleware.process_response"
+                           "error" 0
+                           "span_id" 15
+                           "trace_id" 0
+                           "parent_id" 12
+                           "start" 1606877874182984757
+                           "duration" 10958}
+                  {"name" "django.middleware"
+                   "service" "django"
+                   "resource" "django.middleware.csrf.CsrfViewMiddleware.process_response"
+                   "error" 0
+                   "span_id" 10
+                   "trace_id" 0
+                   "parent_id" 6
+                   "start" 1606877874183028417
+                   "duration" 8876}
+              {"name" "django.middleware"
+               "service" "django"
+               "resource" "django.middleware.common.CommonMiddleware.process_response"
+               "error" 0
+               "span_id" 7
+               "trace_id" 0
+               "parent_id" 3
+               "start" 1606877874183063794
+               "duration" 18114}
+          {"name" "django.middleware"
+           "service" "django"
+           "resource" "django.contrib.sessions.middleware.SessionMiddleware.process_response"
+           "error" 0
+           "span_id" 4
+           "trace_id" 0
+           "parent_id" 1
+           "start" 1606877874183110368
+           "duration" 14381}]]