You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py
Copy file name to clipboardExpand all lines: instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py
+26-4
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,7 @@
16
16
fromtimeimporttime
17
17
fromtypingimportCallable
18
18
19
+
fromdjangoimportVERSIONasdjango_version
19
20
fromdjango.httpimportHttpRequest, HttpResponse
20
21
21
22
fromopentelemetry.contextimportattach, detach
@@ -42,10 +43,31 @@
42
43
exceptImportError:
43
44
fromdjango.urlsimportResolver404, resolve
44
45
45
-
try:
46
-
fromdjango.utils.deprecationimportMiddlewareMixin
47
-
exceptImportError:
48
-
MiddlewareMixin=object
46
+
DJANGO_2_0=django_version>= (2, 0)
47
+
48
+
ifDJANGO_2_0:
49
+
# Since Django 2.0, only `settings.MIDDLEWARE` is supported, so new-style
50
+
# middlewares can be used.
51
+
classMiddlewareMixin:
52
+
def__init__(self, get_response):
53
+
self.get_response=get_response
54
+
55
+
def__call__(self, request):
56
+
self.process_request(request)
57
+
response=self.get_response(request)
58
+
returnself.process_response(request, response)
59
+
60
+
61
+
else:
62
+
# Django versions 1.x can use `settings.MIDDLEWARE_CLASSES` and expect
63
+
# old-style middlewares, which are created by inheriting from
64
+
# `deprecation.MiddlewareMixin` since its creation in Django 1.10 and 1.11,
0 commit comments