Skip to content

Commit d8439f8

Browse files
lzchenxrmx
authored andcommitted
Re-add http.target to Django old sem conv server duration metric (open-telemetry#2746)
1 parent fcfc317 commit d8439f8

File tree

4 files changed

+168
-144
lines changed

4 files changed

+168
-144
lines changed

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Fixed
11+
12+
- `opentelemetry-instrumentation-django` Fix regression - `http.target` re-added back to old semconv duration metrics
13+
([#2746](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2746))
14+
1015
## Version 1.26.0/0.47b0 (2024-07-23)
1116

1217
### Added

Diff for: instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py

+5
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ def process_exception(self, request, exception):
333333

334334
# pylint: disable=too-many-branches
335335
# pylint: disable=too-many-locals
336+
# pylint: disable=too-many-statements
336337
def process_response(self, request, response):
337338
if self._excluded_urls.url_disabled(request.build_absolute_uri("?")):
338339
return response
@@ -426,6 +427,10 @@ def process_response(self, request, response):
426427
duration_attrs_old = _parse_duration_attrs(
427428
duration_attrs, _HTTPStabilityMode.DEFAULT
428429
)
430+
# http.target to be included in old semantic conventions
431+
target = duration_attrs.get(SpanAttributes.HTTP_TARGET)
432+
if target:
433+
duration_attrs_old[SpanAttributes.HTTP_TARGET] = target
429434
self._duration_histogram_old.record(
430435
max(round(duration_s * 1000), 0), duration_attrs_old
431436
)

0 commit comments

Comments
 (0)