|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 |
| -import time |
16 | 15 | from logging import getLogger
|
| 16 | +from time import time |
17 | 17 |
|
18 | 18 | from django.conf import settings
|
19 | 19 |
|
20 |
| -from opentelemetry.configuration import Configuration |
21 | 20 | from opentelemetry.context import attach, detach
|
22 | 21 | from opentelemetry.instrumentation.django.version import __version__
|
23 | 22 | from opentelemetry.instrumentation.utils import extract_attributes_from_object
|
|
28 | 27 | )
|
29 | 28 | from opentelemetry.propagators import extract
|
30 | 29 | from opentelemetry.trace import SpanKind, get_tracer
|
| 30 | +from opentelemetry.util.http import get_excluded_urls, get_traced_request_attrs |
31 | 31 |
|
32 | 32 | try:
|
33 | 33 | from django.core.urlresolvers import ( # pylint: disable=no-name-in-module
|
@@ -61,9 +61,8 @@ class _DjangoMiddleware(MiddlewareMixin):
|
61 | 61 | _environ_span_key = "opentelemetry-instrumentor-django.span_key"
|
62 | 62 | _environ_exception_key = "opentelemetry-instrumentor-django.exception_key"
|
63 | 63 |
|
64 |
| - _excluded_urls = Configuration()._excluded_urls("django") |
65 |
| - |
66 |
| - _traced_request_attrs = Configuration()._traced_request_attrs("django") |
| 64 | + _traced_request_attrs = get_traced_request_attrs("DJANGO") |
| 65 | + _excluded_urls = get_excluded_urls("DJANGO") |
67 | 66 |
|
68 | 67 | @staticmethod
|
69 | 68 | def _get_span_name(request):
|
@@ -111,23 +110,23 @@ def process_request(self, request):
|
111 | 110 | return
|
112 | 111 |
|
113 | 112 | # pylint:disable=W0212
|
114 |
| - request._otel_start_time = time.time() |
| 113 | + request._otel_start_time = time() |
115 | 114 |
|
116 |
| - environ = request.META |
| 115 | + request_meta = request.META |
117 | 116 |
|
118 |
| - token = attach(extract(carrier_getter, environ)) |
| 117 | + token = attach(extract(carrier_getter, request_meta)) |
119 | 118 |
|
120 | 119 | tracer = get_tracer(__name__, __version__)
|
121 | 120 |
|
122 | 121 | span = tracer.start_span(
|
123 | 122 | self._get_span_name(request),
|
124 | 123 | kind=SpanKind.SERVER,
|
125 |
| - start_time=environ.get( |
| 124 | + start_time=request_meta.get( |
126 | 125 | "opentelemetry-instrumentor-django.starttime_key"
|
127 | 126 | ),
|
128 | 127 | )
|
129 | 128 |
|
130 |
| - attributes = collect_request_attributes(environ) |
| 129 | + attributes = collect_request_attributes(request_meta) |
131 | 130 | # pylint:disable=W0212
|
132 | 131 | request._otel_labels = self._get_metric_labels_from_attributes(
|
133 | 132 | attributes
|
@@ -215,7 +214,7 @@ def process_response(self, request, response):
|
215 | 214 | if metric_recorder is not None:
|
216 | 215 | # pylint:disable=W0212
|
217 | 216 | metric_recorder.record_server_duration_range(
|
218 |
| - request._otel_start_time, time.time(), request._otel_labels |
| 217 | + request._otel_start_time, time(), request._otel_labels |
219 | 218 | )
|
220 | 219 | except Exception as ex: # pylint: disable=W0703
|
221 | 220 | _logger.warning("Error recording duration metrics: %s", ex)
|
|
0 commit comments