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 2a94455
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
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 2a94455

Please sign in to comment.