Skip to content

Commit

Permalink
Fix exception in severity number transformation (#2208)
Browse files Browse the repository at this point in the history
* Fix exception with warning message transformation

* Fix lint

* Fix lint
  • Loading branch information
srikanthccv authored and lzchen committed Nov 4, 2021
1 parent af3e553 commit bf98c6d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
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

0 comments on commit bf98c6d

Please sign in to comment.