Created
June 10, 2023 08:28
-
-
Save srikanthccv/b3cf9d70247d5e6b3b92539168f1dcbd to your computer and use it in GitHub Desktop.
Patch to fix the test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/exporter/opentelemetry-exporter-otlp-proto-common/tests/test_log_encoder.py b/exporter/opentelemetry-exporter-otlp-proto-common/tests/test_log_encoder.py | |
index c35ced93b..825950a0a 100644 | |
--- a/exporter/opentelemetry-exporter-otlp-proto-common/tests/test_log_encoder.py | |
+++ b/exporter/opentelemetry-exporter-otlp-proto-common/tests/test_log_encoder.py | |
@@ -41,6 +41,7 @@ from opentelemetry.proto.resource.v1.resource_pb2 import ( | |
) | |
from opentelemetry.sdk._logs import LogData | |
from opentelemetry.sdk._logs import LogRecord as SDKLogRecord | |
+from opentelemetry.sdk._logs import LogLimits | |
from opentelemetry.sdk.resources import Resource as SDKResource | |
from opentelemetry.sdk.util.instrumentation import InstrumentationScope | |
from opentelemetry.trace import TraceFlags | |
@@ -52,11 +53,12 @@ class TestOTLPLogEncoder(unittest.TestCase): | |
self.assertEqual(encode_logs(sdk_logs), expected_encoding) | |
def test_dropped_attributes_count(self): | |
- sdk_logs, _ = self.get_test_logs() | |
- self.assertTrue(hasattr(sdk_logs[0].log_record, "dropped_attributes")) | |
- encoded_logs = str(encode_logs(sdk_logs)) | |
- self.assertTrue("dropped_attributes_count" in encoded_logs) | |
- | |
+ sdk_logs = self._get_test_logs_dropped_attribues() | |
+ encoded_logs = encode_logs(sdk_logs) | |
+ self.assertEqual( | |
+ encoded_logs.resource_logs[0].scope_logs[0].log_records[0].dropped_attributes_count, | |
+ 2 | |
+ ) | |
@staticmethod | |
def _get_sdk_log_data() -> List[LogData]: | |
log1 = LogData( | |
@@ -127,6 +129,46 @@ class TestOTLPLogEncoder(unittest.TestCase): | |
return [log1, log2, log3, log4] | |
+ @staticmethod | |
+ def _get_test_logs_dropped_attribues() -> List[LogData]: | |
+ log1 = LogData( | |
+ log_record=SDKLogRecord( | |
+ timestamp=1644650195189786880, | |
+ trace_id=89564621134313219400156819398935297684, | |
+ span_id=1312458408527513268, | |
+ trace_flags=TraceFlags(0x01), | |
+ severity_text="WARN", | |
+ severity_number=SeverityNumber.WARN, | |
+ body="Do not go gentle into that good night. Rage, rage against the dying of the light", | |
+ resource=SDKResource({"first_resource": "value"}), | |
+ attributes={"a": 1, "b": "c", "user_id": "B121092"}, | |
+ limits=LogLimits(max_attributes=1), | |
+ ), | |
+ instrumentation_scope=InstrumentationScope( | |
+ "first_name", "first_version" | |
+ ), | |
+ ) | |
+ | |
+ log2 = LogData( | |
+ log_record=SDKLogRecord( | |
+ timestamp=1644650249738562048, | |
+ trace_id=0, | |
+ span_id=0, | |
+ trace_flags=TraceFlags.DEFAULT, | |
+ severity_text="WARN", | |
+ severity_number=SeverityNumber.WARN, | |
+ body="Cooper, this is no time for caution!", | |
+ resource=SDKResource({"second_resource": "CASE"}), | |
+ attributes={}, | |
+ ), | |
+ instrumentation_scope=InstrumentationScope( | |
+ "second_name", "second_version" | |
+ ), | |
+ ) | |
+ | |
+ return [log1, log2] | |
+ | |
+ | |
def get_test_logs( | |
self, | |
) -> Tuple[List[SDKLogRecord], ExportLogsServiceRequest]: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment