Search code examples
jbossfusefuseesb

JBoss Fuse v6.2 - Tracing


What is the way to do message tracing for each request made to the JBoss Fuse 6.2 server? In my case most of the entry points are CXF REST service with the processing delegated to Camel routes in some cases. I would like to do end-to-end tracing with same message id that can correlate the request processing.


Solution

  • In my project, there was a similar requirement. Customer wanted to see all e2e log by executing grep command to system logs with a transaction id.

    I used CXF interceptors and MDC logging capability for this as below:

    1. Create a common CXF request and response interceptors. Add them to all your Camel's CXF Server/Client configuration
    2. With your request interceptor, extract transaction id from request (or generte it yourself) then put it into MDC map. MDC is a thread local variable that log4j, slf4j,.. uses.
    3. Print request, it'll have your transaction id as prefix thanks to MDC. Dont forget to add your MDC key in logging format configuration
    4. All logs you print until the end of operation with this transaction Id until the end.
      If you're always using direct-vm, direct for routing then it wont be problem. However as you may know using seda, multi processing, etc. your execution is handled by other threads. Since MDC is thread local variable, you need to manually handle the trouble by transferring it.
    5. With your response interceptor, log response message then clear MDC values.
    6. If you're using CXF as client, you should use same interceptor approach to be able to print client request/reponses with transaction id.

    See CXF-RS and MDC links as entry points