mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-29 21:23:55 +08:00
Handle null statuses in http_status_to_status_code (#823)
This commit is contained in:
@ -64,6 +64,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- `opentelemetry-instrumentation-urllib` Fixed an error on unexpected status values.
|
||||||
|
([#823](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/823))
|
||||||
|
|
||||||
- `opentelemetry-exporter-richconsole` Fixed attribute error on parentless spans.
|
- `opentelemetry-exporter-richconsole` Fixed attribute error on parentless spans.
|
||||||
([#782](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/782))
|
([#782](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/782))
|
||||||
|
|
||||||
|
@ -49,6 +49,9 @@ def http_status_to_status_code(
|
|||||||
status (int): HTTP status code
|
status (int): HTTP status code
|
||||||
"""
|
"""
|
||||||
# See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#status
|
# See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#status
|
||||||
|
if not isinstance(status, int):
|
||||||
|
return StatusCode.UNSET
|
||||||
|
|
||||||
if status < 100:
|
if status < 100:
|
||||||
return StatusCode.ERROR
|
return StatusCode.ERROR
|
||||||
if status <= 299:
|
if status <= 299:
|
||||||
|
@ -56,6 +56,12 @@ class TestUtils(TestBase):
|
|||||||
actual = http_status_to_status_code(int(status_code))
|
actual = http_status_to_status_code(int(status_code))
|
||||||
self.assertEqual(actual, expected, status_code)
|
self.assertEqual(actual, expected, status_code)
|
||||||
|
|
||||||
|
def test_http_status_to_status_code_none(self):
|
||||||
|
for status_code, expected in ((None, StatusCode.UNSET),):
|
||||||
|
with self.subTest(status_code=status_code):
|
||||||
|
actual = http_status_to_status_code(status_code)
|
||||||
|
self.assertEqual(actual, expected, status_code)
|
||||||
|
|
||||||
def test_http_status_to_status_code_redirect(self):
|
def test_http_status_to_status_code_redirect(self):
|
||||||
for status_code, expected in (
|
for status_code, expected in (
|
||||||
(HTTPStatus.MULTIPLE_CHOICES, StatusCode.ERROR),
|
(HTTPStatus.MULTIPLE_CHOICES, StatusCode.ERROR),
|
||||||
|
Reference in New Issue
Block a user