Focused a bit more on generating the event_data dict instead of updating the record object, and moved the byte and json encoding, as well as the event_data declaration to make the code more DRY.
The if's more directly check that the record has the log_props or args properties to save from checking if its an instance of StructuredLogRecord, and adding items directly to the dict, removing the need for log_props_shim.
This could potentially also have performance benefits, but they'd likely be fairly minimal.
Focused a bit more on generating the
event_data
dict instead of updating therecord
object, and moved the byte and json encoding, as well as theevent_data
declaration to make the code more DRY.The
if
's more directly check that therecord
has thelog_props
orargs
properties to save from checking if its an instance ofStructuredLogRecord
, and adding items directly to the dict, removing the need forlog_props_shim
.This could potentially also have performance benefits, but they'd likely be fairly minimal.