Skip to content

Commit

Permalink
Add http.target to Django duration metric attributes (#2624)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmojaki authored Jul 16, 2024
1 parent 7e48ee7 commit f8f58ee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2652](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2652))
- `opentelemetry-instrumentation-aiohttp-client` Implement new semantic convention opt-in migration
([#2673](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2673))
- `opentelemetry-instrumentation-django` Add `http.target` to Django duration metric attributes
([#2624](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2624))

### Breaking changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ def process_view(self, request, view_func, *args, **kwargs):
route = getattr(match, "route", None)
if route:
span.set_attribute(SpanAttributes.HTTP_ROUTE, route)
duration_attrs = request.META[
self._environ_duration_attr_key
]
# Metrics currently use the 1.11.0 schema, which puts the route in `http.target`.
# TODO: use `http.route` when the user sets `OTEL_SEMCONV_STABILITY_OPT_IN`.
duration_attrs[SpanAttributes.HTTP_TARGET] = route

def process_exception(self, request, exception):
if self._excluded_urls.url_disabled(request.build_absolute_uri("?")):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ def test_wsgi_metrics(self):
]
_recommended_attrs = {
"http.server.active_requests": _active_requests_count_attrs,
"http.server.duration": _duration_attrs,
"http.server.duration": _duration_attrs
| {SpanAttributes.HTTP_TARGET},
}
start = default_timer()
for _ in range(3):
Expand Down

0 comments on commit f8f58ee

Please sign in to comment.