Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-asgi`: add explicit http duration buckets for stable semconv
([#3526](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3526))

### Breaking changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def client_response_hook(span: Span, scope: dict[str, Any], message: dict[str, A

from opentelemetry import context, trace
from opentelemetry.instrumentation._semconv import (
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
_filter_semconv_active_request_count_attr,
_filter_semconv_duration_attrs,
_get_schema_url,
Expand Down Expand Up @@ -589,6 +590,7 @@ def __init__(
name=HTTP_SERVER_REQUEST_DURATION,
description="Duration of HTTP server requests.",
unit="s",
explicit_bucket_boundaries_advisory=HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
)
self.server_response_size_histogram = None
if _report_old(sem_conv_opt_in_mode):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import opentelemetry.instrumentation.asgi as otel_asgi
from opentelemetry import trace as trace_api
from opentelemetry.instrumentation._semconv import (
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
OTEL_SEMCONV_STABILITY_OPT_IN,
_OpenTelemetrySemanticConventionStability,
_server_active_requests_count_attrs_new,
Expand Down Expand Up @@ -1245,6 +1246,7 @@ async def test_asgi_metrics(self):
self.assertTrue(number_data_point_seen and histogram_data_point_seen)

async def test_asgi_metrics_new_semconv(self):
# pylint: disable=too-many-nested-blocks
app = otel_asgi.OpenTelemetryMiddleware(simple_asgi)
self.seed_app(app)
await self.send_default_request()
Expand Down Expand Up @@ -1274,6 +1276,11 @@ async def test_asgi_metrics_new_semconv(self):
for point in data_points:
if isinstance(point, HistogramDataPoint):
self.assertEqual(point.count, 3)
if metric.name == "http.server.request.duration":
self.assertEqual(
point.explicit_bounds,
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
)
histogram_data_point_seen = True
if isinstance(point, NumberDataPoint):
number_data_point_seen = True
Expand All @@ -1284,6 +1291,7 @@ async def test_asgi_metrics_new_semconv(self):
self.assertTrue(number_data_point_seen and histogram_data_point_seen)

async def test_asgi_metrics_both_semconv(self):
# pylint: disable=too-many-nested-blocks
app = otel_asgi.OpenTelemetryMiddleware(simple_asgi)
self.seed_app(app)
await self.send_default_request()
Expand Down Expand Up @@ -1313,6 +1321,11 @@ async def test_asgi_metrics_both_semconv(self):
for point in data_points:
if isinstance(point, HistogramDataPoint):
self.assertEqual(point.count, 3)
if metric.name == "http.server.request.duration":
self.assertEqual(
point.explicit_bounds,
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
)
histogram_data_point_seen = True
if isinstance(point, NumberDataPoint):
number_data_point_seen = True
Expand Down