Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Div
classconfluenceTableSmall

Option

Default

Description

breadCrumbLength

0

Fixed length of the bread crumb. 

0 = no fixed length.

Setting a value to e.g. 80 allows the tracer logs to be aligned for easier reading.

maxChars

 

Limits the number of chars logged per line.

From Camel 2.9: the default value is 10000.

multiline

false

Camel 2.18: If true each piece of information is logged on a new line.

nodeLength

0

Fixed length of the node. 

0 = no fixed length.

Setting a value to e.g. 40 allows the tracer logs to be aligned for easier reading.

showBody

true

Output the IN body.

showBodyType

true

Output the IN body Java type.

showBreadCrumb

true

Outputs the unique UnitOfWork for the exchange.

Can be used for correlation to identify a particular Exchange.

showException

true

Output the exception if the processing of an Exchange has failed.

showExchangeId

false

Enable/disable the output of an Exchange's unique id.

Currently the breadcrumb is sufficient.

showExchangePattern

true

Output the Message Exchange Pattern (MEP).

showHeaders

true

Output the IN message headers.

showNode

true

Previous and destination node.

Displayed as: from -> to.

showOutBody

false

Output the OUT (if any) body.

showOutBodyType

false

Output the OUT (if any) body Java type.

showOutHeaders

false

Output the OUT (if any) message headers.

showProperties

false

Output the Exchange's properties.

showRouteId

true

Camel 2.8: output the id of the route.

showShortExchangeId

false

To output the Exchange's unique id in short form, without the hostname.

...

Code Block
java org.apache.camel.spring.Main -trace

and the tracer will be activeactivated.

Enabling in Java

Code Block
languagejava
context.setTracing(true);

...

Code Block
INFO  TraceInterceptor     - ID-davsclaus-local-54403-1246038742624-0-0 >>> from(direct:start) --> MyProcessor     , Pattern:InOnly, Headers:{to=James}, BodyType:String, Body:Hello London
INFO  TraceInterceptor     - ID-davsclaus-local-54403-1246038742624-0-0 >>> MyProcessor --> mock:a                 , Pattern:InOnly, Headers:{to=James}, BodyType:String, Body:Hello London
INFO  TraceInterceptor     - ID-davsclaus-local-54403-1246038742624-0-0 >>> mock:a --> mock:b                      , Pattern:InOnly, Headers:{to=James}, BodyType:String, Body:Hello London
...
INFO  TraceInterceptor     - ID-davsclaus-local-54403-1246038742624-0-1 >>> from(direct:start) --> MyProcessor     , Pattern:InOnly, Headers:{from=Claus}, BodyType:String, Body:This is Copenhagen calling
INFO  TraceInterceptor     - ID-davsclaus-local-54403-1246038742624-0-1 >>> MyProcessor --> mock:a                 , Pattern:InOnly, Headers:{from=Claus}, BodyType:String, Body:This is Copenhagen calling
INFO  TraceInterceptor     - ID-davsclaus-local-54403-1246038742624-0-1 >>> mock:a --> mock:b                      , Pattern:InOnly, Headers:{from=Claus}, BodyType:String, Body:This is Copenhagen calling

Configuring in Java

The tracer Tracer options can be configured from the Java DSL like thisin Java as follows:

Code Block
languagejava
    public void configure() throws Exception {
        // add tracer as an interceptor so it will log the exchange executions at runtime
        // this can aid us to understand/see how the exchanges is routed etc.
        Tracer tracer = new Tracer();
        formatter.getDefaultTraceFormatter().setShowBreadCrumb(false);
        formatter.getDefaultTraceFormatter().setShowNode(false);
        ...
        getContext().addInterceptStrategy(tracer);

...

You can configure the tracer as a Spring bean. Just add a bean with the bean class org.apache.camel.processor.interceptor.Tracer and Camel will use it as the tracer.

Wiki Markup
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/tracerConfigurationTest.xml}
 

You can configure the formatting of tracer as a Spring bean. Just add a bean with the id="traceFormatter" and Camel will lookup this id and use the associated formatter.

Example:

Wiki Markup
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/traceFormatterTest.xml}

Enable Tracing of 

...

OUT Messages

To trace the messages coming out of processing steps configure the tracer as follows:

Wiki Markup
{snippet:id=tracingOutExchanges|title=Java DSL|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceInterceptorWithOutBodyTraceTest.java}
 

or

Wiki Markup
{snippet:id=tracingOutExchanges|title=Spring DSL|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/traceInterceptorWithOutBodyTrace.xml}
 

With these options the output will look like:

...

Example:

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/TraceFormatterTest.java}
 

And here we have our custom logger that implements the TraceFormatter interface where we can construct the log message how we like:

Wiki Markup
{snippet:id=e2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/TraceFormatterTest.java}

...

The sample below demonstrates this feature, where we route traced Exchanges to the direct:traced route:

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/TraceInterceptorDestinationTest.java}
 

 

Then we can configure a route for the traced messages:

...