Always use LogRecord.getMessage to get the log body#4327
Always use LogRecord.getMessage to get the log body#4327pR0Ps wants to merge 1 commit intoopen-telemetry:mainfrom
LogRecord.getMessage to get the log body#4327Conversation
5171c81 to
33d48a4
Compare
|
Any updates on the status here? I think this is a good change that will make otel logging a lot more consistent. Once logging is no longer considered experimental, it'd be much harder to argue leaving a "feature" like this behind. |
|
I've added this to the logging api/sdk rc project so it is being tracked for something to be addressed before logging is stable. |
|
This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment. |
33d48a4 to
1eeebd4
Compare
|
Rebased on the current |
Mostly a revert of open-telemetry#3343 Related to open-telemetry#4528
1eeebd4 to
ffe34cf
Compare
|
This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment. |
|
Hi, thanks for this change. I would like to vote in favor of moving forward with it: it simplifies OTel Python code/behavior, and it's consistent with the expected usage of However, the LoggingHandler is migrating to a contrib instrumentation and this one in the SDK is deprecated, so I think this functionality should go there instead. @pR0Ps if you feel up to applying this change to contrib, we can continue this discussion there. I intend to approve it once in contrib but am interested in what others think. |
|
@pmcollins I opened a pull request on the new repo: open-telemetry/opentelemetry-python-contrib#4372 |
See context in #4216
This is mostly a revert of #3343
Related: #4528
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.msgobject 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.msggiven 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.msgshould not be converted to a string before being set as the body.However, this goes against the Python documentation that states that the
record.msgis 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
msgitself should be an object to log out. The "when the logging system needs to convert it to a string" part happens when theLogRecordis processed by a handler, applies the logic in [2] and converts themsgto a format string that it then formats therecord.argsinto (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: