Hacker News new | ask | show | jobs
by andrewingram 1456 days ago
ContextVars are seemingly more robust and work with async. We use them quite extensively for adding context to logs.
2 comments

I was going to say the same, I combine ContextVars with LoggerAdapters[1].

[1] https://docs.python.org/3/library/logging.html#logging.Logge...

TIL that ContextVars can work in place of thread locals too. Thanks for pointing that out!

I had mistakenly assumed ContextVars only worked for async code.