2828
2929class TestLogRecord (unittest .TestCase ):
3030 def test_log_record_to_json (self ):
31- expected = json .dumps (
32- {
33- "body" : "a log line" ,
34- "severity_number" : None ,
35- "severity_text" : None ,
36- "attributes" : {
37- "mapping" : {"key" : "value" },
38- "none" : None ,
39- "sequence" : [1 , 2 ],
40- "str" : "string" ,
41- },
42- "dropped_attributes" : 0 ,
43- "timestamp" : "1970-01-01T00:00:00.000000Z" ,
44- "observed_timestamp" : "1970-01-01T00:00:00.000000Z" ,
45- "trace_id" : "" ,
46- "span_id" : "" ,
47- "trace_flags" : None ,
48- "resource" : {
49- "attributes" : {"service.name" : "foo" },
50- "schema_url" : "" ,
51- },
52- },
53- indent = 4 ,
54- )
55- actual = LogRecord (
31+ log_record = LogRecord (
5632 timestamp = 0 ,
5733 observed_timestamp = 0 ,
58- body = "a log line" ,
34+ body = { "key" : "logLine" , "bytes" : b"123" } ,
5935 resource = Resource ({"service.name" : "foo" }),
6036 attributes = {
6137 "mapping" : {"key" : "value" },
@@ -65,10 +41,9 @@ def test_log_record_to_json(self):
6541 },
6642 )
6743
68- self .assertEqual (expected , actual .to_json (indent = 4 ))
6944 self .assertEqual (
70- actual .to_json (indent = None ),
71- '{"body": "a log line" , "severity_number": null, "severity_text": null, "attributes": {"mapping": {"key": "value"}, "none": null, "sequence": [1, 2], "str": "string"}, "dropped_attributes": 0, "timestamp": "1970-01-01T00:00:00.000000Z", "observed_timestamp": "1970-01-01T00:00:00.000000Z", "trace_id": "", "span_id": "", "trace_flags": null, "resource": {"attributes": {"service.name": "foo"}, "schema_url": ""}}' ,
45+ log_record .to_json (indent = None ),
46+ '{"body": {"key": "logLine", "bytes": "MTIz"} , "severity_number": null, "severity_text": null, "attributes": {"mapping": {"key": "value"}, "none": null, "sequence": [1, 2], "str": "string"}, "dropped_attributes": 0, "timestamp": "1970-01-01T00:00:00.000000Z", "observed_timestamp": "1970-01-01T00:00:00.000000Z", "trace_id": "", "span_id": "", "trace_flags": null, "resource": {"attributes": {"service.name": "foo"}, "schema_url": ""}}' ,
7247 )
7348
7449 def test_log_record_to_json_serializes_severity_number_as_int (self ):
0 commit comments