Skip to content

Commit 38acff5

Browse files
committed
fix(pyramid): add missing http.response.status_code in duration metrics
The new convention for metrics use http.response.status_code in metrics for http.server.request.duration metric: https://opentelemetry.io/docs/specs/semconv/http/http-metrics/#metric-httpserverrequestduration Only the old convention had the attribute for pyramid, but the new one was missing.
1 parent 498b928 commit 38acff5

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
)
4444
from opentelemetry.semconv._incubating.attributes.http_attributes import (
4545
HTTP_STATUS_CODE,
46+
HTTP_RESPONSE_STATUS_CODE,
4647
)
4748
from opentelemetry.semconv.attributes.http_attributes import HTTP_ROUTE
4849
from opentelemetry.semconv.metrics import MetricInstruments
@@ -265,9 +266,8 @@ def trace_tween(request):
265266
status = getattr(response, "status", status)
266267
status_code = otel_wsgi._parse_status_code(status)
267268
if status_code is not None:
268-
duration_attrs[HTTP_STATUS_CODE] = (
269-
otel_wsgi._parse_status_code(status)
270-
)
269+
duration_attrs[HTTP_STATUS_CODE] = status_code
270+
duration_attrs[HTTP_RESPONSE_STATUS_CODE] = status_code
271271

272272
# Record metrics for old semconv (milliseconds)
273273
if duration_histogram_old:

instrumentation/opentelemetry-instrumentation-pyramid/tests/test_automatic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ def _verify_metric_names(
480480

481481
def _verify_duration_point(self, point):
482482
self.assertIn(HTTP_REQUEST_METHOD, point.attributes)
483+
self.assertIn(HTTP_RESPONSE_STATUS_CODE, point.attributes)
483484
self.assertIn(URL_SCHEME, point.attributes)
484485
self.assertNotIn(HTTP_METHOD, point.attributes)
485486
self.assertNotIn(HTTP_SCHEME, point.attributes)

0 commit comments

Comments
 (0)