harden json encoder against circular references

Change-Id: I3670ee1a3fdb5fa4fd6a4c9b2087cbe6fc5d9dfa
if there is trouble writing one trace item, continue

Change-Id: I7583c7b2c41b39f2428ff32ecf6896b84d038748
assume source files are in utf-8

Change-Id: Ie294e830850fddbbe529858559eba7faa5fe782c
allow missing attributes of classes

some classes (old style?) don't have __class__ set, so ignore the
missing value for that and for __module__

Change-Id: I66fc660780b56048c94fa024f698dfa82297ee46