1

I am having issues with debugging multiple requests going through same piece of code, so there is a need of context information. And using this stackoverflow's answer Django logging with user/ip

Logging each request with a unique request_id, able to see each request flow easily. But the issue is when there is group_send inside django rest framework views using async_to_sync.

  1. Thread local storage won't work in this case due to the code running on a different thread, is there any possible way of propagating thread local storage onto the subthread?

  2. Also I found in the docs about async_to_sync that "Threadlocals and contextvars values are preserved across the boundary in both directions.". Does this mean that the thread local variables are shared in some way?, If it's so, why isn't the logger not able to pick up this thread local variable?

  3. Anyway to properly log django views, channels with all request information without having to give extra on every log message?

Thank you!

Link for that async_to_sync line: https://docs.djangoproject.com/en/3.0/topics/async/

A100
  • 11
  • 1
  • 5

0 Answers0