0

I need to have trace id and span id available in all my logs. However I am observing that after the first splitter in my camel route, I can no longer see the trace id and span id in my logs.

[traceId: spanId:] INFO ---

Is there any way to enable back the tracing information?

From the Camel Documentation I have tried to start the tracing after the split by using

context.setTracing(true)

But looks like this is not working.

Am I missing anything, please help.

2 Answers2

-1

You probably have the traceId and spanId stored in the exchange message headers which are lost after the split.

A solution is to store them in the exchange properties(before the split) which are stored for the entire processing of the exchange(see Passing values between processors in apache camel).

If you are using the Java DSL you can use:

.setProperty("traceId ", constant("traceIdValue"))
.setProperty("spanId", constant("spanIdValue"))

You can use the Simple Expression Language(https://camel.apache.org/manual/latest/simple-language.html) to access the properties after the split using exchangeProperty.property_name. Example:

.log(LoggingLevel.INFO, "[traceId:${exchangeProperty.traceId}  spanId:${exchangeProperty.spanId}]")
RaduP
  • 119
  • 1
  • 5
  • 1
    Hey Radu, I'm not convinced with this approach. I'm using Zipkin for tracing in my project. Setting the trace information manually in the logs defeats the purpose of using Zipkin. – Subham Sarkar Mar 06 '20 at 15:45
-1

When you use split, a new and old exchange will be created and to pass exchange properties downstream, you would need to use an aggregator to do so.

Example:

.split().tokenize(System.lineSeparator()).aggregationStrategy(new YourAggregationStrategyClass())

Camel Dev
  • 139
  • 3