Skip to content

Commit

Permalink
Remove unnecessary warning when (not) setting status description
Browse files Browse the repository at this point in the history
Currently we log a warning that status description should only be set
for an error condition even when description is not being set. This
commit silences such warnings.
  • Loading branch information
owais committed Mar 28, 2021
1 parent b9c0b6f commit dcc3c98
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.0.0...HEAD)

- Silence unnecessary warning when creating a new Status object without description.
([#1721](https://github.com/open-telemetry/opentelemetry-python/pull/1721))


## [1.0.0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.0.0) - 2021-03-26
### Added
Expand Down
18 changes: 9 additions & 9 deletions opentelemetry-api/src/opentelemetry/trace/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ def __init__(
self._status_code = status_code
self._description = None

if description is not None and not isinstance(description, str):
logger.warning("Invalid status description type, expected str")
return

if status_code is not StatusCode.ERROR:
logger.warning(
"description should only be set when status_code is set to StatusCode.ERROR"
)
return
if description:
if not isinstance(description, str):
logger.warning("Invalid status description type, expected str")
return
if status_code is not StatusCode.ERROR:
logger.warning(
"description should only be set when status_code is set to StatusCode.ERROR"
)
return

self._description = description

Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-api/tests/trace/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def test_constructor(self):

def test_invalid_description(self):
with self.assertLogs(level=WARNING) as warning:
status = Status(description={"test": "val"}) # type: ignore
self.assertIs(status.status_code, StatusCode.UNSET)
status = Status(status_code=StatusCode.ERROR, description={"test": "val"}) # type: ignore
self.assertIs(status.status_code, StatusCode.ERROR)
self.assertEqual(status.description, None)
self.assertIn(
"Invalid status description type, expected str",
Expand Down

0 comments on commit dcc3c98

Please sign in to comment.