I was planning to use slf4j MDC in my rest application which is using vertx framework. I read somewhere that you shouldn't use MDC in vertx as MDC is thread specific and vertx is thread agnostic. But I am setting MDC variables at the start of a service which is called from one of the verticles and calling MDC.clear() at the end. Do you see any issues with this. I think it will be within one thread - end to end event processing for one verticle.
Asked
Active
Viewed 2,132 times
2
-
I know MDC, but I don't know Vert.X framework. My guess is that it would work, but what is stopping you from just testing this? It should not be too much work, and you'll quickly notice if something is off. – Tim Biegeleisen Feb 22 '19 at 10:16
-
I tested it and no issues on local. I am more worried about in production. We will have correlationid in the logs and logs will be in ELK and correlationid will be vital for performance, troubleshooting. – Sammy Pawar Feb 22 '19 at 10:24
-
With vert.x a thread can be used by many requests, but a request will generally stay on the same thread. If you run a test with 1 request, or a few requests serially, there will be only 1 request being handled at time, so it will give you a positive result. A proper test is to have multiple log lines, with delay between them, and have many requests going in parallel, forcing the production scenario of many requests being handled by a thread. You should observe then a context-leak. – Renato Sep 16 '22 at 20:25
1 Answers
0
As said, MDC relies on ThreadLocal
, so asynchronous frameworks can't use it.
There's a duplicate question here with some suggestions, but it seems there's no generic equivalent mechanism for MDC in async frameworks.