How to use MDC to log the transaction in a multithreaded environment ?

Solution Unverified - Updated -

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:
    1. early in the CXF interceptor chain we setup some MDC state for our logging
    2. the standard CXF request logging occurs and the MDC state is as expected
    3. the Camel route executes
    4. 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.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content