Skip to content

Commit 1909c91

Browse files
authored
opentelemetry-instrumentation-django: add explicit http duration buckets for stable semconv (#3524)
* opentelemetry-instrumentation-django: add explicit http duration buckets for stable semconv * Update CHANGELOG.md
1 parent f9d9f19 commit 1909c91

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
- `opentelemetry-instrumentation-fastapi`: fix wrapping of middlewares
1717
([#3012](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3012))
18+
- `opentelemetry-instrumentation-django`: proper bucket boundaries in stable semconv http duration
19+
([#3524](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3524))
1820
- `opentelemetry-instrumentation-grpc`: support non-list interceptors
1921
([#3520](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3520))
2022

instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ def response_hook(span, request, response):
246246
from django.core.exceptions import ImproperlyConfigured
247247

248248
from opentelemetry.instrumentation._semconv import (
249+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
249250
_get_schema_url,
250251
_OpenTelemetrySemanticConventionStability,
251252
_OpenTelemetryStabilitySignalType,
@@ -378,6 +379,7 @@ def _instrument(self, **kwargs):
378379
name=HTTP_SERVER_REQUEST_DURATION,
379380
description="Duration of HTTP server requests.",
380381
unit="s",
382+
explicit_bucket_boundaries_advisory=HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
381383
)
382384
_DjangoMiddleware._active_request_counter = (
383385
create_http_server_active_requests(meter)

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
from opentelemetry import trace
2828
from opentelemetry.instrumentation._semconv import (
29+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
30+
HTTP_DURATION_HISTOGRAM_BUCKETS_OLD,
2931
OTEL_SEMCONV_STABILITY_OPT_IN,
3032
_OpenTelemetrySemanticConventionStability,
3133
)
@@ -814,6 +816,10 @@ def test_wsgi_metrics_new_semconv(self):
814816
expected_duration_attributes,
815817
dict(point.attributes),
816818
)
819+
self.assertEqual(
820+
point.explicit_bounds,
821+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
822+
)
817823
if isinstance(point, NumberDataPoint):
818824
number_data_point_seen = True
819825
self.assertEqual(point.value, 0)
@@ -886,6 +892,10 @@ def test_wsgi_metrics_both_semconv(self):
886892
expected_duration_attributes_new,
887893
dict(point.attributes),
888894
)
895+
self.assertEqual(
896+
point.explicit_bounds,
897+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
898+
)
889899
elif metric.name == "http.server.duration":
890900
self.assertAlmostEqual(
891901
duration, point.sum, delta=100
@@ -894,6 +904,10 @@ def test_wsgi_metrics_both_semconv(self):
894904
expected_duration_attributes_old,
895905
dict(point.attributes),
896906
)
907+
self.assertEqual(
908+
point.explicit_bounds,
909+
HTTP_DURATION_HISTOGRAM_BUCKETS_OLD,
910+
)
897911
if isinstance(point, NumberDataPoint):
898912
number_data_point_seen = True
899913
self.assertEqual(point.value, 0)

0 commit comments

Comments
 (0)