mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-30 21:56:07 +08:00
wsgi: always record span status code to have it available in metrics (#3148)
This commit is contained in:
@ -23,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
([#3133](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3133))
|
([#3133](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3133))
|
||||||
- `opentelemetry-instrumentation-falcon` add support version to v4
|
- `opentelemetry-instrumentation-falcon` add support version to v4
|
||||||
([#3086](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3086))
|
([#3086](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3086))
|
||||||
|
- `opentelemetry-instrumentation-wsgi` always record span status code to have it available in metrics
|
||||||
|
([#3148](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3148))
|
||||||
- add support to Python 3.13
|
- add support to Python 3.13
|
||||||
([#3134](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3134))
|
([#3134](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3134))
|
||||||
|
|
||||||
|
@ -480,11 +480,7 @@ def add_response_attributes(
|
|||||||
"""Adds HTTP response attributes to span using the arguments
|
"""Adds HTTP response attributes to span using the arguments
|
||||||
passed to a PEP3333-conforming start_response callable.
|
passed to a PEP3333-conforming start_response callable.
|
||||||
"""
|
"""
|
||||||
if not span.is_recording():
|
|
||||||
return
|
|
||||||
status_code_str, _ = start_response_status.split(" ", 1)
|
status_code_str, _ = start_response_status.split(" ", 1)
|
||||||
|
|
||||||
status_code = 0
|
|
||||||
try:
|
try:
|
||||||
status_code = int(status_code_str)
|
status_code = int(status_code_str)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -779,6 +779,19 @@ class TestWsgiAttributes(unittest.TestCase):
|
|||||||
self.span.set_attribute.assert_has_calls(expected, any_order=True)
|
self.span.set_attribute.assert_has_calls(expected, any_order=True)
|
||||||
self.span.set_attribute.assert_has_calls(expected_new, any_order=True)
|
self.span.set_attribute.assert_has_calls(expected_new, any_order=True)
|
||||||
|
|
||||||
|
def test_response_attributes_noop(self):
|
||||||
|
mock_span = mock.Mock()
|
||||||
|
mock_span.is_recording.return_value = False
|
||||||
|
|
||||||
|
attrs = {}
|
||||||
|
otel_wsgi.add_response_attributes(
|
||||||
|
mock_span, "404 Not Found", {}, duration_attrs=attrs
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(mock_span.set_attribute.call_count, 0)
|
||||||
|
self.assertEqual(mock_span.is_recording.call_count, 2)
|
||||||
|
self.assertEqual(attrs[SpanAttributes.HTTP_STATUS_CODE], 404)
|
||||||
|
|
||||||
def test_credential_removal(self):
|
def test_credential_removal(self):
|
||||||
self.environ["HTTP_HOST"] = "username:password@mock"
|
self.environ["HTTP_HOST"] = "username:password@mock"
|
||||||
self.environ["PATH_INFO"] = "/status/200"
|
self.environ["PATH_INFO"] = "/status/200"
|
||||||
|
Reference in New Issue
Block a user