Skip to content

Commit 2c3fa5e

Browse files
committed
opentelemetry-instrumentation-asgi: add explicit http duration buckets for stable semconv
1 parent 71bfc95 commit 2c3fa5e

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-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-asgi`: add explicit http duration buckets for stable semconv
19+
([#3526](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3526))
1820

1921
### Breaking changes
2022

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def client_response_hook(span: Span, scope: dict[str, Any], message: dict[str, A
202202

203203
from opentelemetry import context, trace
204204
from opentelemetry.instrumentation._semconv import (
205+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
205206
_filter_semconv_active_request_count_attr,
206207
_filter_semconv_duration_attrs,
207208
_get_schema_url,
@@ -589,6 +590,7 @@ def __init__(
589590
name=HTTP_SERVER_REQUEST_DURATION,
590591
description="Duration of HTTP server requests.",
591592
unit="s",
593+
explicit_bucket_boundaries_advisory=HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
592594
)
593595
self.server_response_size_histogram = None
594596
if _report_old(sem_conv_opt_in_mode):

instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import opentelemetry.instrumentation.asgi as otel_asgi
2424
from opentelemetry import trace as trace_api
2525
from opentelemetry.instrumentation._semconv import (
26+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
2627
OTEL_SEMCONV_STABILITY_OPT_IN,
2728
_OpenTelemetrySemanticConventionStability,
2829
_server_active_requests_count_attrs_new,
@@ -1274,6 +1275,11 @@ async def test_asgi_metrics_new_semconv(self):
12741275
for point in data_points:
12751276
if isinstance(point, HistogramDataPoint):
12761277
self.assertEqual(point.count, 3)
1278+
if metric.name == "http.server.request.duration":
1279+
self.assertEqual(
1280+
point.explicit_bounds,
1281+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
1282+
)
12771283
histogram_data_point_seen = True
12781284
if isinstance(point, NumberDataPoint):
12791285
number_data_point_seen = True
@@ -1313,6 +1319,11 @@ async def test_asgi_metrics_both_semconv(self):
13131319
for point in data_points:
13141320
if isinstance(point, HistogramDataPoint):
13151321
self.assertEqual(point.count, 3)
1322+
if metric.name == "http.server.request.duration":
1323+
self.assertEqual(
1324+
point.explicit_bounds,
1325+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
1326+
)
13161327
histogram_data_point_seen = True
13171328
if isinstance(point, NumberDataPoint):
13181329
number_data_point_seen = True

0 commit comments

Comments
 (0)