go-grpc-middleware
go-grpc-middleware copied to clipboard
grpc_logrus multithreading concerns
In the sample code it is encouraged to create a log entry, store it in the context and use it in the rest of the request to log. As far as I can tell this is not thread safe. What is thought process behind this example? I would like to use this issue as a place to have a discussion on logging in this manner.
The log entry is then cloned every time on new request and the clone is put inside the Context variable of the request. That request is then handled by the dispatching goroutine. Most request handling is done in a single synchronous block, and unless someone dispatches more goroutines from it, it is safe.
Any concerns around that?
Has this been a conscious decision? It is not uncommon to open new goroutines in a single request. Like you said most request handling is done in a single synchronous block. Logging in this way would force you to adopt two logging approaches, one for in the main request thread and one for the child threads.
Yes, this was a concious decision. In our codebase, whenever we fan out to sub to go routines (rare) we make sure that we clone the relevant objects and pass them explicitly.
Would you like to contribute documentation clarification around this?
This is pretty old and we know have v2 code with different structure. Let us know if this is still important, we can reopen.