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

### Breaking changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def response_hook(span: Span, environ: WSGIEnvironment, status: str, response_he

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 @@ -592,6 +593,7 @@ def __init__(
name=HTTP_SERVER_REQUEST_DURATION,
unit="s",
description="Duration of HTTP server requests.",
explicit_bucket_boundaries_advisory=HTTP_DURATION_HISTOGRAM_BUCKETS_NEW,
)
# We don't need a separate active request counter for old/new semantic conventions
# because the new attributes are a subset of the old attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import opentelemetry.instrumentation.wsgi as otel_wsgi
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 @@ -398,6 +399,7 @@ def test_wsgi_metrics(self):
self.assertTrue(number_data_point_seen and histogram_data_point_seen)

def test_wsgi_metrics_new_semconv(self):
# pylint: disable=too-many-nested-blocks
app = otel_wsgi.OpenTelemetryMiddleware(error_wsgi_unhandled)
self.assertRaises(ValueError, app, self.environ, self.start_response)
self.assertRaises(ValueError, app, self.environ, self.start_response)
Expand All @@ -418,6 +420,11 @@ def test_wsgi_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 @@ -429,6 +436,7 @@ def test_wsgi_metrics_new_semconv(self):
self.assertTrue(number_data_point_seen and histogram_data_point_seen)

def test_wsgi_metrics_both_semconv(self):
# pylint: disable=too-many-nested-blocks
app = otel_wsgi.OpenTelemetryMiddleware(error_wsgi_unhandled)
self.assertRaises(ValueError, app, self.environ, self.start_response)
metrics_list = self.memory_metrics_reader.get_metrics_data()
Expand Down Expand Up @@ -456,6 +464,11 @@ def test_wsgi_metrics_both_semconv(self):
for point in data_points:
if isinstance(point, HistogramDataPoint):
self.assertEqual(point.count, 1)
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