Is there a reason Elixir doesn’t support charlists as values in the Logger metadata? Here’s a list of things it supports today:
I noticed this while adding opentelemetry-erlang integration to the project. opentelemetry-erlang uses values of type charlist to add span context info to log metadata, and they weren’t showing up in the logs in place where the metadata should be printed:
There are some ways to work around the problem of charlist not showing up in the logs, but I got curious if there’s a reason Elixir couldn’t support charlists
I guess the reason is because Elixir uses binaries and charlists are only for interoperability with Erlang. You’re integrating with an Erlang library which expects charlists. Elixir got you covered there. A similar question could be asked to the developers of the library: why aren’t they accepting binaries.
This is a bit of a tricky problem given elixir uses :logger nowadays. Idealy one wouldn’t need to care if the host system is an elixir or erlang system to use a logger handler and with some configuration effort you can get there, but it’s not (yet) possible with elixir ootb.
Yes, I noticed this too and had a similar question.
I thought charlists are skipped because validating their contents is not easy / performant enough for such a critical area as logging: e.g. that lists do not contain values other than characters, or that all characters are printable, etc.
But maybe I am wrong an Elixir could indeed implement support for charlists in metadata?
I think the main problem there is checking whether given list is charlist or not, as that may require deep traversal. Also, if we support chartists, then should we also support IO lists? What about charlists with non-ASCII characters in them? Unfortunately, this is place where static typing would be useful, but without that, it may be computationally expensive to check given list on each log message.