Nebo15 / logger_json

JSON logger formatter with support for Google Cloud, DataDog and other for Elixir.
https://nebo15.github.io/logger_json/
MIT License
237 stars 92 forks source link

Ensure custom metadata with PIDs do not crash #38

Closed tgrk closed 4 years ago

tgrk commented 4 years ago

While using default Google Stackdriver formater I was experiencing issues with UndefinedProtocol for PID when using jason encoder. This happened in crashes (:ancestors field) and resulted in errors. Using Jason.Encoder for PID fixes the problem.

Thanks for your logger_json as structured logging significantly improved our ability to find and identify issues.

coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.2%) to 74.269% when pulling e6a009c6995b310220fbbf8f9224d54e1b98c96c on tgrk:fix-pids-in-metadata into f60e1b750f24c8338d741e4307e7e68ae9a6212a on Nebo15:master.

AndrewDryga commented 4 years ago

Hello @tgrk,

I think it would be a generally bad idea to start implementing Jason.Encoder protocol in libraries (LoggerJSON or any other) because it would break some of the apps that already implement it and rely on their implementation to be valid. Eg. they encode using specific format or their tests rely on Jason.Encoder.NotImplemented exception for PID's.

A proper way to fix this would be to recursively iterate over metadata struct and use inspect on any value that does not have a Jason.Encoder protocol implemented for it.

tgrk commented 4 years ago

@AndrewDryga Very good point. 🤦 It sounds to me to have this part of a custom formatter (as there will be some performance overhead of this recursion check for metadata) and not everyone is probably having similar issues. Thank you!