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

Fix exception in severity number transformation #2208

Merged
merged 5 commits into from
Oct 15, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from opentelemetry.proto.logs.v1.logs_pb2 import (
InstrumentationLibraryLogs,
ResourceLogs,
SeverityNumber,
)
from opentelemetry.proto.logs.v1.logs_pb2 import LogRecord as PB2LogRecord
from opentelemetry.sdk.logs import LogRecord as SDKLogRecord
Expand Down Expand Up @@ -164,10 +163,9 @@ def _translate_data(
self._translate_severity_text(log_data)
self._translate_attributes(log_data)

self._collector_log_kwargs["severity_number"] = getattr(
SeverityNumber,
"SEVERITY_NUMBER_{}".format(log_data.log_record.severity_text),
)
self._collector_log_kwargs[
"severity_number"
] = log_data.log_record.severity_number.value

instrumentation_library_logs.logs.append(
PB2LogRecord(**self._collector_log_kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
)
from opentelemetry.proto.logs.v1.logs_pb2 import InstrumentationLibraryLogs
from opentelemetry.proto.logs.v1.logs_pb2 import LogRecord as PB2LogRecord
from opentelemetry.proto.logs.v1.logs_pb2 import ResourceLogs, SeverityNumber
from opentelemetry.proto.logs.v1.logs_pb2 import ResourceLogs
from opentelemetry.proto.resource.v1.resource_pb2 import (
Resource as OTLPResource,
)
Expand Down Expand Up @@ -113,7 +113,7 @@ def setUp(self):
trace_id=2604504634922341076776623263868986797,
span_id=5213367945872657620,
trace_flags=TraceFlags(0x01),
severity_text="WARN",
severity_text="WARNING",
severity_number=SDKSeverityNumber.WARN,
name="name",
body="Zhengzhou, We have a heaviest rains in 1000 years",
Expand Down Expand Up @@ -291,13 +291,8 @@ def test_translate_log_data(self):
# pylint: disable=no-member
name="name",
time_unix_nano=self.log_data_1.log_record.timestamp,
severity_number=getattr(
SeverityNumber,
"SEVERITY_NUMBER_{}".format(
self.log_data_1.log_record.severity_text
),
),
severity_text="WARN",
severity_number=self.log_data_1.log_record.severity_number.value,
severity_text="WARNING",
span_id=int.to_bytes(
5213367945872657620, 8, "big"
),
Expand Down Expand Up @@ -356,13 +351,8 @@ def test_translate_multiple_logs(self):
# pylint: disable=no-member
name="name",
time_unix_nano=self.log_data_1.log_record.timestamp,
severity_number=getattr(
SeverityNumber,
"SEVERITY_NUMBER_{}".format(
self.log_data_1.log_record.severity_text
),
),
severity_text="WARN",
severity_number=self.log_data_1.log_record.severity_number.value,
severity_text="WARNING",
span_id=int.to_bytes(
5213367945872657620, 8, "big"
),
Expand Down Expand Up @@ -399,12 +389,7 @@ def test_translate_multiple_logs(self):
# pylint: disable=no-member
name="info name",
time_unix_nano=self.log_data_2.log_record.timestamp,
severity_number=getattr(
SeverityNumber,
"SEVERITY_NUMBER_{}".format(
self.log_data_2.log_record.severity_text
),
),
severity_number=self.log_data_2.log_record.severity_number.value,
severity_text="INFO",
span_id=int.to_bytes(
5213367945872657623, 8, "big"
Expand Down Expand Up @@ -450,12 +435,7 @@ def test_translate_multiple_logs(self):
# pylint: disable=no-member
name="error name",
time_unix_nano=self.log_data_3.log_record.timestamp,
severity_number=getattr(
SeverityNumber,
"SEVERITY_NUMBER_{}".format(
self.log_data_3.log_record.severity_text
),
),
severity_number=self.log_data_3.log_record.severity_number.value,
severity_text="ERROR",
span_id=int.to_bytes(
5213367945872657628, 8, "big"
Expand Down