我需要在所有日志中提供跟踪ID和跨度ID。但是我观察到,在骆驼路线的第一个分离器之后,我再也无法在日志中看到跟踪ID和跨度ID。
[traceId: spanId:] INFO ---
是否有任何方法可以回溯跟踪信息?
在Camel Documentation中,我尝试使用分割后开始跟踪
context.setTracing(true)
但是看起来这不起作用。
我错过了什么吗,请帮忙。
答案 0 :(得分:0)
您可能在交换消息头中存储了traceId和spanId,它们在拆分后会丢失。
一种解决方案是将它们存储在交换属性中(在拆分之前),这些属性是为交换的整个处理而存储的(请参见Passing values between processors in apache camel)。
如果您正在使用Java DSL,则可以使用:
.setProperty("traceId ", constant("traceIdValue"))
.setProperty("spanId", constant("spanIdValue"))
您可以在 exchangeProperty.property_name 中使用简单表达式语言(https://camel.apache.org/manual/latest/simple-language.html)来访问属性。 示例:
.log(LoggingLevel.INFO, "[traceId:${exchangeProperty.traceId} spanId:${exchangeProperty.spanId}]")
答案 1 :(得分:0)
使用split时,将创建一个新旧交换,并向下游传递交换属性,您需要使用聚合器来这样做。
示例:
.split().tokenize(System.lineSeparator()).aggregationStrategy(new YourAggregationStrategyClass())