diff --git a/CHANGELOG.md b/CHANGELOG.md index beac03f24b..4da62257af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-instrumentation-fastapi`: fix wrapping of middlewares ([#3012](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3012)) +- `opentelemetry-instrumentation-django`: proper bucket boundaries in stable semconv http duration + ([#3524](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3524)) - `opentelemetry-instrumentation-grpc`: support non-list interceptors ([#3520](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3520)) diff --git a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py index 3b9af4127f..7d92aff145 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py @@ -246,6 +246,7 @@ def response_hook(span, request, response): from django.core.exceptions import ImproperlyConfigured from opentelemetry.instrumentation._semconv import ( + HTTP_DURATION_HISTOGRAM_BUCKETS_NEW, _get_schema_url, _OpenTelemetrySemanticConventionStability, _OpenTelemetryStabilitySignalType, @@ -378,6 +379,7 @@ def _instrument(self, **kwargs): name=HTTP_SERVER_REQUEST_DURATION, description="Duration of HTTP server requests.", unit="s", + explicit_bucket_boundaries_advisory=HTTP_DURATION_HISTOGRAM_BUCKETS_NEW, ) _DjangoMiddleware._active_request_counter = ( create_http_server_active_requests(meter) diff --git a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py index 1c85935892..960bf97bc4 100644 --- a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py @@ -26,6 +26,8 @@ from opentelemetry import trace from opentelemetry.instrumentation._semconv import ( + HTTP_DURATION_HISTOGRAM_BUCKETS_NEW, + HTTP_DURATION_HISTOGRAM_BUCKETS_OLD, OTEL_SEMCONV_STABILITY_OPT_IN, _OpenTelemetrySemanticConventionStability, ) @@ -814,6 +816,10 @@ def test_wsgi_metrics_new_semconv(self): expected_duration_attributes, dict(point.attributes), ) + self.assertEqual( + point.explicit_bounds, + HTTP_DURATION_HISTOGRAM_BUCKETS_NEW, + ) if isinstance(point, NumberDataPoint): number_data_point_seen = True self.assertEqual(point.value, 0) @@ -886,6 +892,10 @@ def test_wsgi_metrics_both_semconv(self): expected_duration_attributes_new, dict(point.attributes), ) + self.assertEqual( + point.explicit_bounds, + HTTP_DURATION_HISTOGRAM_BUCKETS_NEW, + ) elif metric.name == "http.server.duration": self.assertAlmostEqual( duration, point.sum, delta=100 @@ -894,6 +904,10 @@ def test_wsgi_metrics_both_semconv(self): expected_duration_attributes_old, dict(point.attributes), ) + self.assertEqual( + point.explicit_bounds, + HTTP_DURATION_HISTOGRAM_BUCKETS_OLD, + ) if isinstance(point, NumberDataPoint): number_data_point_seen = True self.assertEqual(point.value, 0)