Always use LogRecord.getMessage
to get the log body
#4327
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.
See context in #4216
This is mostly a revert of #3343
Description
This change makes the log exporting always call
LogRecord.getMessage()
in order to format and return the record's body text. Previously in #3343 a special case was added so that therecord.msg
object was used directly if no args were provided. This special case was further scoped down and changed to callrecord.getMessage()
to improve compatibility with other Python logging libraries in #4216 . This PR proposes doing away with the special case entirely and always callingrecord.getMessage()
in order to get the body text.The reason for preserving the original type of the
record.msg
given in #3343 was that the body field type in the OTel 1.22.0 Logs Data Model is supposed to be "any", not "str", so therecord.msg
should not be converted to a string before being set as the body.However, this goes against the Python documentation that states that the
record.msg
is only supposed to be a format string[1] or an object to convert into a format string[2] and not an actual object to be logged.[1]: From logging.Logger.debug(msg, *args, **kwargs) docs (emphasis mine):
[2]: From logging.LogRecord.getMessage() docs (emphasis mine):
Note that while the "Using arbitrary objects as messages" section of the logging HOWTO states:
this doesn't mean that the
msg
itself should be an object to log out. The "when the logging system needs to convert it to a string" part happens when theLogRecord
is processed by a handler, applies the logic in [2] and converts themsg
to a format string that it then formats therecord.args
into (if any).Type of change
How Has This Been Tested?
I've updated and run the unit tests, as well as run manual tests of the functionality (see #4216 for details)
Does This PR Require a Contrib Repo Change?
Checklist: