Adds str fallback to envelope serialization#1196
Adds str fallback to envelope serialization#1196lzchen merged 2 commits intocensus-instrumentation:masterfrom
Conversation
When serialization fails (e.g. when a non-JSON-serializable value is added to the properties) the entire batch that envelope belongs to does not get sent. Falling back to to str as a means of serialization when JSON serialization fails seems like a sane default that greatly reduces the risk of missed telemetry.
|
resolves #1197 |
|
I'm curious if you ran into a case in which the envelope was not serializable? |
@lzchen I did: App Insights supports adding an additional "property bag", which is called customDimensions and which can be filled by adding a key "custom_dimensions" to the dictionary that can be provided to the "extra" argument, e.g: logger.log(
level,
message,
extra={
'custom_dimensions'=my_additional_info
}
)If any of the values of the dict my_additional_info is not JSON-serializable, serializing the envelope fails. this happens for example with things as trivial as a datetime. The workaround of course, is to only add properties that are either JSON-serializable, or serialize them to string manually, but I think this minor addition makes life a lot easier, while also preventing lost telemetry. |
|
@ddeschepper |
|
@lzchen I've added the CHANGELOG entry. |
When serialization fails (e.g. when a non-JSON-serializable value is added to the properties) the entire batch that envelope belongs to does not get sent. Falling back to to str as a means of serialization when JSON serialization fails seems like a sane default that greatly reduces the risk of missed telemetry.