How to access incoming requests at Uvicorn level in a FastAPI app? #1314
-
Hey, community! I have a FastAPI application that I have deployed using the UVICORN server. My requirement is such that I have to log every incoming request at the UVICORN level and also decode JWT Token that the header of incoming request contains, log that too, at the UVICORN level. I have been trying to understand the UVICORN library and understanding the code. So far, this is what I have found: uvicorn/uvicorn/protocols/http/httptools_impl.py Lines 128 to 138 in df8b49f With some hit & trial, I found that the data parameter this function receives contains all the incoming request payload as a byte string. Where can I find all incoming requests and go about my logging? I don't want to monkey-patch the UVICORN code, I am looking for a sane way to achieve the purpose. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
The best way to achieve that, right now, is to create a middleware. Check https://github.com/Kludex/asgi-logger internal code for more details. |
Beta Was this translation helpful? Give feedback.
The best way to achieve that, right now, is to create a middleware. Check https://github.com/Kludex/asgi-logger internal code for more details.