Skip to content

Commit fa6d972

Browse files
authored
opentelemetry-instrumentation-wsgi: add explicit http duration buckets for stable semconv (#3527)
* opentelemetry-instrumentation-wsgi: add explicit http duration buckets for stable semconv * Please pylint
1 parent 5e4b558 commit fa6d972

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-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
- `opentelemetry-instrumentation-asgi`: add explicit http duration buckets for stable semconv
1921
([#3526](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3526))
2022
- `opentelemetry-instrumentation-flask`: proper bucket boundaries in stable semconv http duration

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: 13 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,
@@ -398,6 +399,7 @@ def test_wsgi_metrics(self):
398399
self.assertTrue(number_data_point_seen and histogram_data_point_seen)
399400

400401
def test_wsgi_metrics_new_semconv(self):
402+
# pylint: disable=too-many-nested-blocks
401403
app = otel_wsgi.OpenTelemetryMiddleware(error_wsgi_unhandled)
402404
self.assertRaises(ValueError, app, self.environ, self.start_response)
403405
self.assertRaises(ValueError, app, self.environ, self.start_response)
@@ -418,6 +420,11 @@ def test_wsgi_metrics_new_semconv(self):
418420
for point in data_points:
419421
if isinstance(point, HistogramDataPoint):
420422
self.assertEqual(point.count, 3)
423+
if metric.name == "http.server.request.duration":
424+
self.assertEqual(
425+
point.explicit_bounds,
426+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
427+
)
421428
histogram_data_point_seen = True
422429
if isinstance(point, NumberDataPoint):
423430
number_data_point_seen = True
@@ -429,6 +436,7 @@ def test_wsgi_metrics_new_semconv(self):
429436
self.assertTrue(number_data_point_seen and histogram_data_point_seen)
430437

431438
def test_wsgi_metrics_both_semconv(self):
439+
# pylint: disable=too-many-nested-blocks
432440
app = otel_wsgi.OpenTelemetryMiddleware(error_wsgi_unhandled)
433441
self.assertRaises(ValueError, app, self.environ, self.start_response)
434442
metrics_list = self.memory_metrics_reader.get_metrics_data()
@@ -456,6 +464,11 @@ def test_wsgi_metrics_both_semconv(self):
456464
for point in data_points:
457465
if isinstance(point, HistogramDataPoint):
458466
self.assertEqual(point.count, 1)
467+
if metric.name == "http.server.request.duration":
468+
self.assertEqual(
469+
point.explicit_bounds,
470+
HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
471+
)
459472
histogram_data_point_seen = True
460473
if isinstance(point, NumberDataPoint):
461474
number_data_point_seen = True

0 commit comments

Comments
 (0)