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

fix: ensure status is always string #640

Merged

Conversation

codeboten
Copy link
Contributor

@codeboten codeboten commented May 3, 2020

During some testing, found that the pymongo instrumentation was setting the status description field as a dict which made the otcollector fail to process any spans.

Added a check for the description type to avoid the exporter being throwing an exception.

Additionally, added a check in the Status constructor to log and skip setting the description if it is not None and not a string.

During some testing, found that the pymongo instrumentation was setting the status description field as a dict which made the otcollector fail to process any spans. Added a test and wrapped the description field in a `str`.
@Oberon00
Copy link
Member

Oberon00 commented May 4, 2020

IMHO you added a workaround for a bug in the pymongo instrumentation to the otcollector exporter. This workaround would need to be applied to every eporter, and every span processor that consumes the status directly in the end callback.

I think the otcollector exporter is the wrong place to handle a non-string status. This should be fixed either in the Status constructor or the pymongo instrumentation (or both?). I think we should handle invalid types for status message consistently with invalid types for set_attribute.

@codeboten
Copy link
Contributor Author

IMHO you added a workaround for a bug in the pymongo instrumentation to the otcollector exporter. This workaround would need to be applied to every eporter, and every span processor that consumes the status directly in the end callback.

Fair enough, though my thinking here was that as the exporter, if the data type causes an exception, it might not be a bad idea to be a bit more defensive anyways.

@codeboten
Copy link
Contributor Author

@Oberon00 also just to follow up I did open an issue for pymongo here: #641

@mauriciovasquezbernal
Copy link
Member

I second @Oberon00. I think the most straightforward solution here is to update the PyMongo integration to use a string in the description and update the Status' constructor to ignore and print a warning if the description is not a string, as we do in set_attribute.

opentelemetry-api/tests/trace/test_status.py Outdated Show resolved Hide resolved
opentelemetry-api/tests/trace/test_status.py Outdated Show resolved Hide resolved
self.assertEqual(status.description, "unavailable")

def test_invalid_description(self):
status = Status(description={"test": "val"})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include a test checking that a warning is printed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Copy link
Member

@mauriciovasquezbernal mauriciovasquezbernal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Some code suggestions and a comment about the case included in the otcollector, but None of them is blocking.

opentelemetry-api/tests/trace/test_status.py Outdated Show resolved Hide resolved
opentelemetry-api/tests/trace/test_status.py Outdated Show resolved Hide resolved
opentelemetry-api/tests/trace/test_status.py Outdated Show resolved Hide resolved
Comment on lines 271 to 275
self.assertEqual(
output_spans[1].status.code,
trace_api.status.StatusCanonicalCode.INTERNAL.value,
)
self.assertEqual(output_spans[1].status.message, "")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this particular test should not be included here as it's testing something implemented in a different place.

@toumorokoshi toumorokoshi merged commit 194824b into open-telemetry:master May 15, 2020
cnnradams pushed a commit to cnnradams/opentelemetry-python that referenced this pull request May 15, 2020
Ensuring that exporters can always expect status descriptions to be a string.

This was implemented to be defensive against instrumentations such as PyMongo, which currently set status as a dict.

Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
Co-authored-by: Yusuke Tsutsumi <yusuke@tsutsumi.io>
owais pushed a commit to owais/opentelemetry-python that referenced this pull request May 22, 2020
Ensuring that exporters can always expect status descriptions to be a string.

This was implemented to be defensive against instrumentations such as PyMongo, which currently set status as a dict.

Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
Co-authored-by: Yusuke Tsutsumi <yusuke@tsutsumi.io>
srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this pull request Nov 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants