diff --git a/CHANGELOG.md b/CHANGELOG.md index 2278dcbbacd..62fb27fbfce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- Fix loglevel warning text + ([#3566](https://github.com/open-telemetry/opentelemetry-python/pull/3566)) - Prometheus Exporter string representation for target_info labels ([#3659](https://github.com/open-telemetry/opentelemetry-python/pull/3659)) - Logs: ObservedTimestamp field is missing in console exporter output diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 046025754b3..ab9e69ba6d6 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -521,12 +521,19 @@ def _translate(self, record: logging.LogRecord) -> LogRecord: body = record.msg % record.args else: body = record.msg + + # 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. + level_name = ( + "WARN" if record.levelname == "WARNING" else record.levelname + ) + return LogRecord( timestamp=timestamp, trace_id=span_context.trace_id, span_id=span_context.span_id, trace_flags=span_context.trace_flags, - severity_text=record.levelname, + severity_text=level_name, severity_number=severity_number, body=body, resource=self._logger.resource, diff --git a/opentelemetry-sdk/tests/logs/test_export.py b/opentelemetry-sdk/tests/logs/test_export.py index 2828504eaa9..d48dcf8e242 100644 --- a/opentelemetry-sdk/tests/logs/test_export.py +++ b/opentelemetry-sdk/tests/logs/test_export.py @@ -67,7 +67,7 @@ def test_simple_log_record_processor_default_level(self): self.assertEqual(len(finished_logs), 1) warning_log_record = finished_logs[0].log_record self.assertEqual(warning_log_record.body, "Something is wrong") - self.assertEqual(warning_log_record.severity_text, "WARNING") + self.assertEqual(warning_log_record.severity_text, "WARN") self.assertEqual( warning_log_record.severity_number, SeverityNumber.WARN ) @@ -122,7 +122,7 @@ def test_simple_log_record_processor_trace_correlation(self): self.assertEqual(len(finished_logs), 1) log_record = finished_logs[0].log_record self.assertEqual(log_record.body, "Warning message") - self.assertEqual(log_record.severity_text, "WARNING") + self.assertEqual(log_record.severity_text, "WARN") self.assertEqual(log_record.severity_number, SeverityNumber.WARN) self.assertEqual(log_record.trace_id, INVALID_SPAN_CONTEXT.trace_id) self.assertEqual(log_record.span_id, INVALID_SPAN_CONTEXT.span_id) @@ -162,7 +162,7 @@ def test_simple_log_record_processor_shutdown(self): self.assertEqual(len(finished_logs), 1) warning_log_record = finished_logs[0].log_record self.assertEqual(warning_log_record.body, "Something is wrong") - self.assertEqual(warning_log_record.severity_text, "WARNING") + self.assertEqual(warning_log_record.severity_text, "WARN") self.assertEqual( warning_log_record.severity_number, SeverityNumber.WARN ) @@ -192,13 +192,13 @@ def test_simple_log_record_processor_different_msg_types(self): finished_logs = exporter.get_finished_logs() expected = [ - ("warning message: possible upcoming heatwave", "WARNING"), + ("warning message: possible upcoming heatwave", "WARN"), ("Very high rise in temperatures across the globe", "ERROR"), ( "Temperature hits high 420 C in Hyderabad", "CRITICAL", ), - (["list", "of", "strings"], "WARNING"), + (["list", "of", "strings"], "WARN"), ({"key": "value"}, "ERROR"), ] emitted = [ @@ -367,7 +367,7 @@ def test_shutdown(self): finished_logs = exporter.get_finished_logs() expected = [ - ("warning message: possible upcoming heatwave", "WARNING"), + ("warning message: possible upcoming heatwave", "WARN"), ("Very high rise in temperatures across the globe", "ERROR"), ( "Temperature hits high 420 C in Hyderabad", diff --git a/opentelemetry-sdk/tests/logs/test_multi_log_processor.py b/opentelemetry-sdk/tests/logs/test_multi_log_processor.py index 7f4bbc32c15..110fedb9578 100644 --- a/opentelemetry-sdk/tests/logs/test_multi_log_processor.py +++ b/opentelemetry-sdk/tests/logs/test_multi_log_processor.py @@ -82,7 +82,7 @@ def test_log_record_processor(self): logger.error("Some error message") expected_list_1 = [ - ("Brace yourself", "WARNING"), + ("Brace yourself", "WARN"), ("Some error message", "ERROR"), ] self.assertEqual(logs_list_1, expected_list_1) @@ -107,7 +107,7 @@ def _get_multi_log_record_processor(self): def make_record(self): return LogRecord( timestamp=1622300111608942000, - severity_text="WARNING", + severity_text="WARN", severity_number=SeverityNumber.WARN, body="Warning message", )