Skip to content

Commit 2a94455

Browse files
committed
Remove unnecessary warning when (not) setting status description
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.
1 parent b9c0b6f commit 2a94455

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

opentelemetry-api/src/opentelemetry/trace/status.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ def __init__(
4949
self._status_code = status_code
5050
self._description = None
5151

52-
if description is not None and not isinstance(description, str):
53-
logger.warning("Invalid status description type, expected str")
54-
return
55-
56-
if status_code is not StatusCode.ERROR:
57-
logger.warning(
58-
"description should only be set when status_code is set to StatusCode.ERROR"
59-
)
60-
return
52+
if description:
53+
if not isinstance(description, str):
54+
logger.warning("Invalid status description type, expected str")
55+
return
56+
if status_code is not StatusCode.ERROR:
57+
logger.warning(
58+
"description should only be set when status_code is set to StatusCode.ERROR"
59+
)
60+
return
6161

6262
self._description = description
6363

opentelemetry-api/tests/trace/test_status.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def test_constructor(self):
3030

3131
def test_invalid_description(self):
3232
with self.assertLogs(level=WARNING) as warning:
33-
status = Status(description={"test": "val"}) # type: ignore
34-
self.assertIs(status.status_code, StatusCode.UNSET)
33+
status = Status(status_code=StatusCode.ERROR, description={"test": "val"}) # type: ignore
34+
self.assertIs(status.status_code, StatusCode.ERROR)
3535
self.assertEqual(status.description, None)
3636
self.assertIn(
3737
"Invalid status description type, expected str",

0 commit comments

Comments
 (0)