How to get Correlation ID inside the view function in FastAPI?
See original GitHub issueHey author, thanks for the amazing work! Our team is planning to onboard this library in our projects.
I have been trying to retrieve the created correlation ID inside a view function in FastAPI but I am not able to query it somehow. I have tried querying the request.headers
and request.body()
, and am still not able to find it.
How can I get that?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to access request_id defined in fastapi middleware in ...
Another 2 solutions: Store data in request.state in your middleware, and then access request.state in the view functions. More info in ...
Read more >Observability Best Practices when running FastAPI in a Lambda
The correlation ID can then be added to requests towards downstream services (if any), to be able to get a complete view of...
Read more >How can I implement a Correlation ID middleware? #397
I have had a look in Starlette middleware docs but I have no idea how I can add an extra field for logging...
Read more >tiangolo/fastapi - Gitter
Hello everyone. I got one question about logging.. I need to add context in logs (request_id, or how do you call that correlated_id)....
Read more >Identifying FastAPI requests in logs | by David Lorenzo - Medium
Our pseudo-logging function (“debug()”) acquires the Request ID set on the context variable (L12) and appends it to the printed log records.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Done, sure. My Bad!
No worries, happy to see others using the package 👏
Feel free to star the repo if you find it helpful, as it will help raise our visibility a little 🙂