108.6. 将 RouteID 属性添加到范围
要识别 Route 的原始卷,需要将 RouteID 属性添加到 span 中。解决办法是使用 Camel 中的 Span decorator。为此,为您要增强路由 ID 的每个组件添加一个自定义 decorator。例如,如果要在直接组件中打印路由 ID,其实现如下:
import org.apache.camel.Endpoint; import org.apache.camel.Exchange; import org.apache.camel.tracing.SpanAdapter; import org.apache.camel.tracing.decorators.DirectSpanDecorator; public class RouteIDSpanDecorator extends DirectSpanDecorator { @Override public void pre(SpanAdapter span, Exchange exchange, Endpoint endpoint) { super.pre(span, exchange, endpoint); span.setTag("camel.route.id", exchange.getFromRouteId()); } }
将名为 org.apache.camel.tracing.SpanDecorator
的文件添加到 src/main/resources/META-INF/services
文件夹,其中包含类 .. (例如 com.redhat.xxxx.RouteIDSpanDecorator)。这允许 Camel 追踪功能使用 trace 中应用的标签加载自定义 Span decorator。