diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 46432dc880..13fde465c3 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -508,20 +508,7 @@ def _translate(self, record: logging.LogRecord) -> LogRecord: if self.formatter: body = self.format(record) else: - # Since the body field has a type of 'any' and the logging module is - # sometimes used in such a way that objects incorrectly end up set as - # record.msg, in those cases we would like to set the object as the - # body instead of its string representation. - # Here we take advantage of the fact that no formatting is applied - # when no args are provided in order to ensure that we're only - # deviating from the norm where formatting wasn't going to be applied - # anyway. - # For more background, see: https://github.com/open-telemetry/opentelemetry-python/pull/4216 - if not record.args and not isinstance(record.msg, str): - # no args are provided so it's *mostly* safe to use the message template as the body - body = record.msg - else: - body = record.getMessage() + body = record.getMessage() # related to https://github.com/open-telemetry/opentelemetry-python/issues/3548 # Severity Text = WARN as defined in https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#displaying-severity. diff --git a/opentelemetry-sdk/tests/logs/test_export.py b/opentelemetry-sdk/tests/logs/test_export.py index ce31d3991f..bc333373a5 100644 --- a/opentelemetry-sdk/tests/logs/test_export.py +++ b/opentelemetry-sdk/tests/logs/test_export.py @@ -217,8 +217,8 @@ def test_simple_log_record_processor_different_msg_types(self): "Temperature hits high 420 C in Hyderabad", "CRITICAL", ), - (["list", "of", "strings"], "WARN"), - ({"key": "value"}, "ERROR"), + ("['list', 'of', 'strings']", "WARN"), + ("{'key': 'value'}", "ERROR"), ] emitted = [ (item.log_record.body, item.log_record.severity_text)