Skip to content

Commit d6a332c

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

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

1921
### Breaking changes
2022

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ def response_hook(span: Span, environ: WSGIEnvironment, status: str, response_he
223223

224224
from opentelemetry import context, trace
225225
from opentelemetry.instrumentation._semconv import (
226+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
226227
_filter_semconv_active_request_count_attr,
227228
_filter_semconv_duration_attrs,
228229
_get_schema_url,
@@ -592,6 +593,7 @@ def __init__(
592593
name=HTTP_SERVER_REQUEST_DURATION,
593594
unit="s",
594595
description="Duration of HTTP server requests.",
596+
explicit_bucket_boundaries_advisory=HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
595597
)
596598
# We don't need a separate active request counter for old/new semantic conventions
597599
# because the new attributes are a subset of the old attributes

instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import opentelemetry.instrumentation.wsgi as otel_wsgi
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,
@@ -418,6 +419,11 @@ def test_wsgi_metrics_new_semconv(self):
418419
for point in data_points:
419420
if isinstance(point, HistogramDataPoint):
420421
self.assertEqual(point.count, 3)
422+
if metric.name == "http.server.request.duration":
423+
self.assertEqual(
424+
point.explicit_bounds,
425+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
426+
)
421427
histogram_data_point_seen = True
422428
if isinstance(point, NumberDataPoint):
423429
number_data_point_seen = True
@@ -456,6 +462,11 @@ def test_wsgi_metrics_both_semconv(self):
456462
for point in data_points:
457463
if isinstance(point, HistogramDataPoint):
458464
self.assertEqual(point.count, 1)
465+
if metric.name == "http.server.request.duration":
466+
self.assertEqual(
467+
point.explicit_bounds,
468+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
469+
)
459470
histogram_data_point_seen = True
460471
if isinstance(point, NumberDataPoint):
461472
number_data_point_seen = True

0 commit comments

Comments
 (0)