Skip to content

Commit

Permalink
Handle null statuses in http_status_to_status_code (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregbuehler committed Feb 2, 2022
1 parent e69030e commit 0e55341
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### 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.
([#782](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/782))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def http_status_to_status_code(
status (int): HTTP status code
"""
# 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:
return StatusCode.ERROR
if status <= 299:
Expand Down
6 changes: 6 additions & 0 deletions opentelemetry-instrumentation/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ def test_http_status_to_status_code(self):
actual = http_status_to_status_code(int(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):
for status_code, expected in (
(HTTPStatus.MULTIPLE_CHOICES, StatusCode.ERROR),
Expand Down

0 comments on commit 0e55341

Please sign in to comment.