Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c0466e

Browse files
authored
Remove unnecessary warning when (not) setting status description (open-telemetry#1721)
1 parent 58521be commit 0c0466e

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- Adjust `B3Format` propagator to be spec compliant by not modifying context
1616
when propagation headers are not present/invalid/empty
1717
([#1728](https://github.com/open-telemetry/opentelemetry-python/pull/1728))
18+
- Silence unnecessary warning when creating a new Status object without description.
19+
([#1721](https://github.com/open-telemetry/opentelemetry-python/pull/1721))
1820
- Update bootstrap cmd to use exact version when installing instrumentation packages.
1921
([#1722](https://github.com/open-telemetry/opentelemetry-python/pull/1722))
2022

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

Lines changed: 9 additions & 9 deletions
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

Lines changed: 2 additions & 2 deletions
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)