@@ -44,7 +44,7 @@ def func(*_args, **_kwargs):
44
44
45
45
class NotSerializeableClass :
46
46
def __str__ (self ) -> str :
47
- "This class is not serializeable"
47
+ return "This class is not serializeable"
48
48
49
49
50
50
# pylint: disable=import-error
@@ -184,6 +184,23 @@ def setUpClass(cls):
184
184
),
185
185
InstrumentationScope ("test_name" ),
186
186
)
187
+ cls ._log_data_event_complex_body_not_serializeable = _logs .LogData (
188
+ _logs .LogRecord (
189
+ timestamp = 1646865018558419456 ,
190
+ trace_id = 125960616039069540489478540494783893221 ,
191
+ span_id = 2909973987304607650 ,
192
+ severity_text = "INFO" ,
193
+ trace_flags = None ,
194
+ severity_number = SeverityNumber .INFO ,
195
+ body = NotSerializeableClass (),
196
+ resource = Resource .create (attributes = {"asd" :"test_resource" }),
197
+ attributes = {
198
+ "event_key" : "event_attribute" ,
199
+ _APPLICATION_INSIGHTS_EVENT_MARKER_ATTRIBUTE : True ,
200
+ },
201
+ ),
202
+ InstrumentationScope ("test_name" ),
203
+ )
187
204
cls ._exc_data = _logs .LogData (
188
205
_logs .LogRecord (
189
206
timestamp = 1646865018558419456 ,
@@ -415,6 +432,13 @@ def test_log_to_envelope_log_complex_body(self):
415
432
self .assertEqual (envelope .data .base_type , 'MessageData' )
416
433
self .assertEqual (envelope .data .base_data .message , json .dumps (self ._log_data_complex_body .log_record .body ))
417
434
435
+ def test_log_to_envelope_log_complex_body_not_serializeable (self ):
436
+ exporter = self ._exporter
437
+ envelope = exporter ._log_to_envelope (self ._log_data_complex_body_not_serializeable )
438
+ self .assertEqual (envelope .name , 'Microsoft.ApplicationInsights.Message' )
439
+ self .assertEqual (envelope .data .base_type , 'MessageData' )
440
+ self .assertEqual (envelope .data .base_data .message , str (self ._log_data_complex_body_not_serializeable .log_record .body ))
441
+
418
442
def test_log_to_envelope_exception_with_string_message (self ):
419
443
exporter = self ._exporter
420
444
envelope = exporter ._log_to_envelope (self ._exc_data )
@@ -497,8 +521,8 @@ def test_log_to_envelope_event_complex_body(self):
497
521
498
522
def test_log_to_envelope_event_complex_body_not_serializeable (self ):
499
523
exporter = self ._exporter
500
- envelope = exporter ._log_to_envelope (self ._log_data_complex_body_not_serializeable )
501
- record = self ._log_data_complex_body_not_serializeable .log_record
524
+ envelope = exporter ._log_to_envelope (self ._log_data_event_complex_body_not_serializeable )
525
+ record = self ._log_data_event_complex_body_not_serializeable .log_record
502
526
self .assertEqual (envelope .name , 'Microsoft.ApplicationInsights.Event' )
503
527
self .assertEqual (envelope .time , ns_to_iso_str (record .timestamp ))
504
528
self .assertEqual (envelope .data .base_type , 'EventData' )
0 commit comments