1515import unittest
1616from typing import List , Tuple
1717
18- from opentelemetry ._logs import SeverityNumber
18+ from opentelemetry ._logs import LogRecord , SeverityNumber
1919from opentelemetry .exporter .otlp .proto .common ._internal import (
2020 _encode_attributes ,
2121 _encode_span_id ,
@@ -64,7 +64,7 @@ def test_encode(self):
6464 def test_encode_no_body (self ):
6565 sdk_logs , expected_encoding = self .get_test_logs ()
6666 for log in sdk_logs :
67- log .body = None
67+ log .log_record . body = None
6868
6969 for resource_log in expected_encoding .resource_logs :
7070 for scope_log in resource_log .scope_logs :
@@ -99,30 +99,34 @@ def _get_sdk_log_data() -> List[SDKLogRecord]:
9999 )
100100 )
101101 log1 = SDKLogRecord (
102- timestamp = 1644650195189786880 ,
103- observed_timestamp = 1644650195189786881 ,
104- context = ctx_log1 ,
105- severity_text = "WARN" ,
106- severity_number = SeverityNumber .WARN ,
107- body = "Do not go gentle into that good night. Rage, rage against the dying of the light" ,
102+ LogRecord (
103+ timestamp = 1644650195189786880 ,
104+ observed_timestamp = 1644650195189786881 ,
105+ context = ctx_log1 ,
106+ severity_text = "WARN" ,
107+ severity_number = SeverityNumber .WARN ,
108+ body = "Do not go gentle into that good night. Rage, rage against the dying of the light" ,
109+ attributes = {"a" : 1 , "b" : "c" },
110+ ),
108111 resource = SDKResource (
109112 {"first_resource" : "value" },
110113 "resource_schema_url" ,
111114 ),
112- attributes = {"a" : 1 , "b" : "c" },
113115 instrumentation_scope = InstrumentationScope (
114116 "first_name" , "first_version"
115117 ),
116118 )
117119
118120 log2 = SDKLogRecord (
119- timestamp = 1644650249738562048 ,
120- observed_timestamp = 1644650249738562049 ,
121- severity_text = "WARN" ,
122- severity_number = SeverityNumber .WARN ,
123- body = "Cooper, this is no time for caution!" ,
121+ LogRecord (
122+ timestamp = 1644650249738562048 ,
123+ observed_timestamp = 1644650249738562049 ,
124+ severity_text = "WARN" ,
125+ severity_number = SeverityNumber .WARN ,
126+ body = "Cooper, this is no time for caution!" ,
127+ attributes = {},
128+ ),
124129 resource = SDKResource ({"second_resource" : "CASE" }),
125- attributes = {},
126130 instrumentation_scope = InstrumentationScope (
127131 "second_name" , "second_version"
128132 ),
@@ -139,14 +143,16 @@ def _get_sdk_log_data() -> List[SDKLogRecord]:
139143 )
140144 )
141145 log3 = SDKLogRecord (
142- timestamp = 1644650427658989056 ,
143- observed_timestamp = 1644650427658989057 ,
144- context = ctx_log3 ,
145- severity_text = "DEBUG" ,
146- severity_number = SeverityNumber .DEBUG ,
147- body = "To our galaxy" ,
146+ LogRecord (
147+ timestamp = 1644650427658989056 ,
148+ observed_timestamp = 1644650427658989057 ,
149+ context = ctx_log3 ,
150+ severity_text = "DEBUG" ,
151+ severity_number = SeverityNumber .DEBUG ,
152+ body = "To our galaxy" ,
153+ attributes = {"a" : 1 , "b" : "c" },
154+ ),
148155 resource = SDKResource ({"second_resource" : "CASE" }),
149- attributes = {"a" : 1 , "b" : "c" },
150156 instrumentation_scope = None ,
151157 )
152158
@@ -161,17 +167,19 @@ def _get_sdk_log_data() -> List[SDKLogRecord]:
161167 )
162168 )
163169 log4 = SDKLogRecord (
164- timestamp = 1644650584292683008 ,
165- observed_timestamp = 1644650584292683009 ,
166- context = ctx_log4 ,
167- severity_text = "INFO" ,
168- severity_number = SeverityNumber .INFO ,
169- body = "Love is the one thing that transcends time and space" ,
170+ LogRecord (
171+ timestamp = 1644650584292683008 ,
172+ observed_timestamp = 1644650584292683009 ,
173+ context = ctx_log4 ,
174+ severity_text = "INFO" ,
175+ severity_number = SeverityNumber .INFO ,
176+ body = "Love is the one thing that transcends time and space" ,
177+ attributes = {"filename" : "model.py" , "func_name" : "run_method" },
178+ ),
170179 resource = SDKResource (
171180 {"first_resource" : "value" },
172181 "resource_schema_url" ,
173182 ),
174- attributes = {"filename" : "model.py" , "func_name" : "run_method" },
175183 instrumentation_scope = InstrumentationScope (
176184 "another_name" , "another_version"
177185 ),
@@ -188,14 +196,16 @@ def _get_sdk_log_data() -> List[SDKLogRecord]:
188196 )
189197 )
190198 log5 = SDKLogRecord (
191- timestamp = 1644650584292683009 ,
192- observed_timestamp = 1644650584292683010 ,
193- context = ctx_log5 ,
194- severity_text = "INFO" ,
195- severity_number = SeverityNumber .INFO ,
196- body = {"error" : None , "array_with_nones" : [1 , None , 2 ]},
199+ LogRecord (
200+ timestamp = 1644650584292683009 ,
201+ observed_timestamp = 1644650584292683010 ,
202+ context = ctx_log5 ,
203+ severity_text = "INFO" ,
204+ severity_number = SeverityNumber .INFO ,
205+ body = {"error" : None , "array_with_nones" : [1 , None , 2 ]},
206+ attributes = {},
207+ ),
197208 resource = SDKResource ({}),
198- attributes = {},
199209 instrumentation_scope = InstrumentationScope (
200210 "last_name" , "last_version"
201211 ),
@@ -212,17 +222,19 @@ def _get_sdk_log_data() -> List[SDKLogRecord]:
212222 )
213223 )
214224 log6 = SDKLogRecord (
215- timestamp = 1644650584292683022 ,
216- observed_timestamp = 1644650584292683022 ,
217- context = ctx_log6 ,
218- severity_text = "ERROR" ,
219- severity_number = SeverityNumber .ERROR ,
220- body = "This instrumentation scope has a schema url" ,
225+ LogRecord (
226+ timestamp = 1644650584292683022 ,
227+ observed_timestamp = 1644650584292683022 ,
228+ context = ctx_log6 ,
229+ severity_text = "ERROR" ,
230+ severity_number = SeverityNumber .ERROR ,
231+ body = "This instrumentation scope has a schema url" ,
232+ attributes = {"filename" : "model.py" , "func_name" : "run_method" },
233+ ),
221234 resource = SDKResource (
222235 {"first_resource" : "value" },
223236 "resource_schema_url" ,
224237 ),
225- attributes = {"filename" : "model.py" , "func_name" : "run_method" },
226238 instrumentation_scope = InstrumentationScope (
227239 "scope_with_url" ,
228240 "scope_with_url_version" ,
@@ -241,17 +253,19 @@ def _get_sdk_log_data() -> List[SDKLogRecord]:
241253 )
242254 )
243255 log7 = SDKLogRecord (
244- timestamp = 1644650584292683033 ,
245- observed_timestamp = 1644650584292683033 ,
246- context = ctx_log7 ,
247- severity_text = "FATAL" ,
248- severity_number = SeverityNumber .FATAL ,
249- body = "This instrumentation scope has a schema url and attributes" ,
256+ LogRecord (
257+ timestamp = 1644650584292683033 ,
258+ observed_timestamp = 1644650584292683033 ,
259+ context = ctx_log7 ,
260+ severity_text = "FATAL" ,
261+ severity_number = SeverityNumber .FATAL ,
262+ body = "This instrumentation scope has a schema url and attributes" ,
263+ attributes = {"filename" : "model.py" , "func_name" : "run_method" },
264+ ),
250265 resource = SDKResource (
251266 {"first_resource" : "value" },
252267 "resource_schema_url" ,
253268 ),
254- attributes = {"filename" : "model.py" , "func_name" : "run_method" },
255269 instrumentation_scope = InstrumentationScope (
256270 "scope_with_attributes" ,
257271 "scope_with_attributes_version" ,
@@ -271,16 +285,20 @@ def _get_sdk_log_data() -> List[SDKLogRecord]:
271285 )
272286 )
273287 log8 = SDKLogRecord (
274- timestamp = 1644650584292683044 ,
275- observed_timestamp = 1644650584292683044 ,
276- context = ctx_log8 ,
277- severity_text = "INFO" ,
278- severity_number = SeverityNumber .INFO ,
279- body = "Test export of extended attributes" ,
288+ LogRecord (
289+ timestamp = 1644650584292683044 ,
290+ observed_timestamp = 1644650584292683044 ,
291+ context = ctx_log8 ,
292+ severity_text = "INFO" ,
293+ severity_number = SeverityNumber .INFO ,
294+ body = "Test export of extended attributes" ,
295+ attributes = {
296+ "extended" : {
297+ "sequence" : [{"inner" : "mapping" , "none" : None }]
298+ }
299+ },
300+ ),
280301 resource = SDKResource ({}),
281- attributes = {
282- "extended" : {"sequence" : [{"inner" : "mapping" , "none" : None }]}
283- },
284302 instrumentation_scope = InstrumentationScope (
285303 "extended_name" , "extended_version"
286304 ),
@@ -594,13 +612,15 @@ def _get_test_logs_dropped_attributes() -> List[SDKLogRecord]:
594612 )
595613 )
596614 log1 = SDKLogRecord (
597- timestamp = 1644650195189786880 ,
598- context = ctx_log1 ,
599- severity_text = "WARN" ,
600- severity_number = SeverityNumber .WARN ,
601- body = "Do not go gentle into that good night. Rage, rage against the dying of the light" ,
615+ LogRecord (
616+ timestamp = 1644650195189786880 ,
617+ context = ctx_log1 ,
618+ severity_text = "WARN" ,
619+ severity_number = SeverityNumber .WARN ,
620+ body = "Do not go gentle into that good night. Rage, rage against the dying of the light" ,
621+ attributes = {"a" : 1 , "b" : "c" , "user_id" : "B121092" },
622+ ),
602623 resource = SDKResource ({"first_resource" : "value" }),
603- attributes = {"a" : 1 , "b" : "c" , "user_id" : "B121092" },
604624 limits = LogLimits (max_attributes = 1 ),
605625 instrumentation_scope = InstrumentationScope (
606626 "first_name" , "first_version"
@@ -610,13 +630,15 @@ def _get_test_logs_dropped_attributes() -> List[SDKLogRecord]:
610630 NonRecordingSpan (SpanContext (0 , 0 , False ))
611631 )
612632 log2 = SDKLogRecord (
613- timestamp = 1644650249738562048 ,
614- context = ctx_log2 ,
615- severity_text = "WARN" ,
616- severity_number = SeverityNumber .WARN ,
617- body = "Cooper, this is no time for caution!" ,
633+ LogRecord (
634+ timestamp = 1644650249738562048 ,
635+ context = ctx_log2 ,
636+ severity_text = "WARN" ,
637+ severity_number = SeverityNumber .WARN ,
638+ body = "Cooper, this is no time for caution!" ,
639+ attributes = {},
640+ ),
618641 resource = SDKResource ({"second_resource" : "CASE" }),
619- attributes = {},
620642 instrumentation_scope = InstrumentationScope (
621643 "second_name" , "second_version"
622644 ),
0 commit comments