Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary warning when setting status description for non-error status #1721

Merged
merged 3 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))


## [1.0.0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.0.0) - 2021-03-26
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