kolofordjango / kolo

See everything happening in your running Django app. All without leaving VSCode
https://kolo.app
486 stars 14 forks source link

Make middleware handle ASGI (patch included) #57

Closed LucidDan closed 1 year ago

LucidDan commented 1 year ago

Currently, the middleware drops into compatibility mode when run under an ASGI server, which causes the profiler not to be properly enabled for the request/response lifecycle. As a result, Kolo doesn't correctly identify each request and response on an ASGI based django application.

Here's a patch to improve support for that, by explicitly handling ASGI and therefore not dropping into compatibility mode. I included a warning message since ASGI/async support is still not perfect, but with this, it is at least somewhat usable. https://gist.github.com/LucidDan/d260260436525c672adf1f4f04a4e29d

Mostly, it's just about making sure to "await" the response if in async mode. It's a very naive implementation so I fully expect there are some issues I haven't picked up! But it does provide a starting point.