-
Notifications
You must be signed in to change notification settings - Fork 697
fix(exporter): convert body to str as fallback #4510
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this create unexpected behaviour when complex objects passed incorrectly?
eg. we mask an actual error by logging
<MyObject instance at 0x...
instead of raising an exceptionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is executed during batch processing, and not when the complex object is passed. Therefore, the exception does not carry a useful stack trace. The exception would carry the type name, but the type name is also contained in the string representation. Also, raising an exception here impacts the whole batch (all lines in it), so not raising here also has some benefits.
More importantly, Python's native
logging
also converts to strings by default instead of raising an exception. Therefore, OpenTelemetry should follow this approach instead of raising surprising exceptions:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would expand the scope of this function from serializing to the spec to transforming data to comply with the spec.
A different approach was suggested in #3389 which I think would be more appropriate here.
They sub-classed the LoggingHandler and modified it to account for this scenario.
The logging handler already includes a translate function (here), this would make it easy to create a Logging Handler in opentelemetry-python-contrib that handles this scenario for the third party library.
There is a contrib example that we never merged here: open-telemetry/opentelemetry-python-contrib#2492
A similar issue (support for structlog) was discussed in #2993.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this about the
_encode_value
function specifically? If so, this could be rewritten somehow. I still think that stringification should be the default, because application developers generally don't know what some library may pass to the logging function, and these exceptions result in a bad user experience for app developers integrating OpenTelemetry. For example, I decided to modify your sample to unconditionally stringify allrecord.msg
, because synapse including all of its dependencies is huge, and I don't want to continuously maintain ato_str_types
list.Thanks for the sample. It works for me now. I already used a custom LoggingHandler subclass, so only the emit method was missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this PR is useful for #4514, although it may not be ideal. This indicates that the behavior is useful for general purpose, not just for the StringifiableFromEvent from twisted.