Skip to content
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

Set Severity Text = WARN as defined #3566

Merged
merged 4 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions opentelemetry-sdk/tests/logs/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-sdk/tests/logs/test_multi_log_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
)
Expand Down
Loading