diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/log_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/log_exporter/__init__.py index cd548f15c8c..ecf9e16e8f7 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/log_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/log_exporter/__init__.py @@ -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 @@ -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) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/logs/test_otlp_logs_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/logs/test_otlp_logs_exporter.py index 4a898cb1bb5..866d1a03b7e 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/logs/test_otlp_logs_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/logs/test_otlp_logs_exporter.py @@ -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, ) @@ -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", @@ -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" ), @@ -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" ), @@ -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" @@ -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"