Skip to content

Commit f8f58ee

Browse files
authored
Add http.target to Django duration metric attributes (#2624)
1 parent 7e48ee7 commit f8f58ee

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3131
([#2652](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2652))
3232
- `opentelemetry-instrumentation-aiohttp-client` Implement new semantic convention opt-in migration
3333
([#2673](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2673))
34+
- `opentelemetry-instrumentation-django` Add `http.target` to Django duration metric attributes
35+
([#2624](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2624))
3436

3537
### Breaking changes
3638

instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py

+6
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,12 @@ def process_view(self, request, view_func, *args, **kwargs):
315315
route = getattr(match, "route", None)
316316
if route:
317317
span.set_attribute(SpanAttributes.HTTP_ROUTE, route)
318+
duration_attrs = request.META[
319+
self._environ_duration_attr_key
320+
]
321+
# Metrics currently use the 1.11.0 schema, which puts the route in `http.target`.
322+
# TODO: use `http.route` when the user sets `OTEL_SEMCONV_STABILITY_OPT_IN`.
323+
duration_attrs[SpanAttributes.HTTP_TARGET] = route
318324

319325
def process_exception(self, request, exception):
320326
if self._excluded_urls.url_disabled(request.build_absolute_uri("?")):

instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ def test_wsgi_metrics(self):
480480
]
481481
_recommended_attrs = {
482482
"http.server.active_requests": _active_requests_count_attrs,
483-
"http.server.duration": _duration_attrs,
483+
"http.server.duration": _duration_attrs
484+
| {SpanAttributes.HTTP_TARGET},
484485
}
485486
start = default_timer()
486487
for _ in range(3):

0 commit comments

Comments
 (0)