JSONRenderer and not serializable dict keys
This code
import uuid
import structlog
structlog.configure(processors=[structlog.processors.JSONRenderer()])
structlog.get_logger().info({uuid.uuid4(): 1})
fails with TypeError
TypeError: keys must be str, int, float, bool or None, not UUID
In my setup, I can fix this issue by using a custom json encoder, passed to json.dums using cls argument.
What do you suggest, fix the issue in structlog code or mention this case in the docs?
This seems a very fringe use-case. Ultimately, if you want to pass non-standard datatypes into your log entries, you have to customize dumps anyway. If you want to have non-standard keys, that's even more true. I would recommend to do it via default argument if possible though.
I didn't manage to make it work via default argument, as far as I understood, default is applied to values, not keys.
I think that is quite a fringe use-case, sure, but it can be useful for someony If it is mentioned in the docs. Will you accept a PR with such change?
Yes, because it’s rather unexpected that someone uses anything else than strings as keys. 😅
This use-case by itself is nothing I would want to add to the docs, since they are quite extensive already.
What I could imagine is an isolated chapter specifically on JSON logs that explains some beste practices and logging of custom types.