File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
opentelemetry-sdk/tests/logs Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 4040
4141
4242class TestLogRecord (unittest .TestCase ):
43+ def test_serialized_context_none (self ):
44+ record = LogRecord (context = None )
45+ self .assertEqual (None , record .serialized_context ())
46+
47+ def test_serialized_context_serializable (self ):
48+ context = {
49+ "test-string" : "value" ,
50+ "test-number" : 42 ,
51+ "test-list" : [1 , 2 , 3 ],
52+ "test-dict" : {"key" : "value" },
53+ "test-null" : None ,
54+ "test-bool" : True ,
55+ }
56+ record = LogRecord (context = context )
57+ self .assertEqual (context , record .serialized_context ())
58+
59+ def test_serialized_context_non_serializable (self ):
60+ class MyTestObject :
61+ def __str__ (self ):
62+ return "foo-bar"
63+
64+ context = {"test-string" : "value" , "test-object" : MyTestObject ()}
65+ record = LogRecord (context = context )
66+ expected = {"test-string" : "value" , "test-object" : "foo-bar" }
67+ self .assertEqual (expected , record .serialized_context ())
68+
4369 def test_log_record_to_json (self ):
4470 expected = json .dumps (
4571 {
You can’t perform that action at this time.
0 commit comments