Skip to content

Commit

Permalink
Remove unnecessary warning when (not) setting status description (#1721)
Browse files Browse the repository at this point in the history
  • Loading branch information
owais authored Apr 2, 2021
1 parent 58521be commit 0c0466e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Adjust `B3Format` propagator to be spec compliant by not modifying context
when propagation headers are not present/invalid/empty
([#1728](https://github.com/open-telemetry/opentelemetry-python/pull/1728))
- Silence unnecessary warning when creating a new Status object without description.
([#1721](https://github.com/open-telemetry/opentelemetry-python/pull/1721))
- Update bootstrap cmd to use exact version when installing instrumentation packages.
([#1722](https://github.com/open-telemetry/opentelemetry-python/pull/1722))

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 0c0466e

Please sign in to comment.