Moving from thread-local storage / logging to tokio task-level, with 0.5 #2160
Unanswered
mgumbley-resilient
asked this question in
Questions
Replies: 1 comment 6 replies
-
The correct solution for this in Rocket is to use request-local cache. This is the same across 0.4 and 0.5. |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Thank you for all the work that's gone into 0.5! I wonder if there's already a solution to this problem we've encountered after upgrading from 0.4 to 0.5?
On each incoming request, our microservice receives a request id (and other data). We extract this id in a request fairing, and use log-mdc and log4rs to add this to the mapped diagnostic context, so that all our processing, and logging from 3rd party libraries is logged with this request id - this allows us to easily isolate everything that happened during processing each request. log-mdc uses thread_local! storage to record the id; we remove the id in a response fairing.
This worked fine in 0.4, but with the change to tokio and async in 0.5, the task handling each incoming request can migrate between threads, and so will be logged with the wrong id (that of the thread's first incoming request).
If there's no existing solution to this, I'm considering enhancing log-mdc and log4rs to use tokio task_local! storage - does anyone have any thoughts on this? Is there a better way?
Kind regards,
Matt Gumbley
Beta Was this translation helpful? Give feedback.
All reactions