Tracer
Camel’s tracer is used for logging message details during routing, where you can see the route path of each message as they happen. Details of the message is also logged such as the message body, and headers.
| There is an alternative tracer that captures the messages in a Backlog Tracer for on-demand tracing. For example tools, Camel JBang, Hawtio and others are using this. |
Enabling Tracing
The logging tracing is easily enabled by setting a single flag.
-
Java
-
Spring XML
-
Application Properties
You enable tracing on the CamelContext:
context.setTracing(true); <camelContext trace="true" xmlns="http://activemq.apache.org/camel/schema/spring">
...
</camelContext> For example when using Spring Boot or Quarkus
camel.main.tracing = true Setting Tracing in Standby mode
By default, Camel optimizes and opt-out tracing. Therefore, you would either have to enable tracing from the startup, or turn on standby mode, to allow tracing to be enabled later during runtime.
To set tracing in standby mode you can do:
-
Java
-
Spring XML
-
Application Properties
context.setTracingStandby(true); <camelContext trace="standby" xmlns="http://activemq.apache.org/camel/schema/spring">
...
</camelContext> For example when using Spring Boot or Quarkus
camel.main.tracing-standby = true If tracer is in standby mode, then tracing is made available, and can be enabled later during runtime. This requires to either use JMX or Java to turn on the tracing:
For example in Java:
Tracer tracer = context.getTracer();
tracer.setEnabled(true); Trace Logging Formatting
The tracer formats the execution of exchanges to log lines. They are logged at INFO level in the log category: org.apache.camel.Tracing.
The message information from the Exchange is formatted using ExchangeFormatter and the default implementation has many options you can configure accordingly to the javadoc.
The tracer outputs the logging with a prefix with the following information:
-
arrow - (direction whether input or output)
-
routeId - the current route
-
label - the current EIP node
This output is assembled using the following default format:
%-4.4s [%-12.12s] [%-33.33s] The default format can be customized using, for example to use wider columns:
-
Java
-
Spring XML
-
Application Properties
context.setTracingLoggingFormat("%-4.4s [%-30.30s] [%-50.50s]"); <camelContext trace="true" traceLoggingFormat="%-4.4s [%-30.30s] [%-50.50s]">
...
</camelContext> camel.main.tracing-logging-format = %-4.4s [%-30.30s] [%-50.50s]