How to use MDC to log the transaction in a multithreaded environment ?
Issue
- I currently using camel-cxf to expose my web service and also consuming my provider web service, as part of the process for tracing in log, I use cxf interceptor to generate UUID as transaction Id and place it in MDC, but when I use cxf-ws-client sent the message to client, the MDC information is lost, are you able to help to advice how can I use MDC to log the transaction?
- MDC behavior is erratic in identifying a unique request.
- We are running Fuse 6.1.0 r2p6 and have noticed some issues around MDC logging on CXF HTTP endpoints used as consumers on Camel routes.
- An outline of the issue:
- early in the CXF interceptor chain we setup some MDC state for our logging
- the standard CXF request logging occurs and the MDC state is as expected
- the Camel route executes
- the standard CXF response logging occurs and sometimes the MDC state is NOT as expected
- Because of Jetty continuations are used (4) will not necessarily execute on the same thread as (1) and (2) when the request is resumed.
- It seems that around the time the underlying Jetty continuation is resumed the MDC state needs to be resurrected from a previously preserved copy.
Environment
- Red Hat JBoss Fuse
- 6.1.0
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.