Chapter 351. Example
To enable camel-zipkin you need to configure first
ZipkinTracer zipkin = new ZipkinTracer();
// Configure a reporter, which controls how often spans are sent
// (the dependency is io.zipkin.reporter2:zipkin-sender-okhttp3)
sender = OkHttpSender.create("http://127.0.0.1:9411/api/v2/spans");
zipkin.setSpanReporter(AsyncReporter.create(sender));
// and then add zipkin to the CamelContext
zipkin.init(camelContext);
The configuration above will trace all incoming and outgoing messages in Camel routes.
To use ZipkinTracer in XML, all you need to do is to define scribe and zipkin tracer beans. Camel will automatically discover and use them.
<!-- configure how to reporter spans to a Zipkin collector
(the dependency is io.zipkin.reporter2:zipkin-reporter-spring-beans) -->
<bean id="http" class="zipkin2.reporter.beans.AsyncReporterFactoryBean">
<property name="sender">
<bean id="sender" class="zipkin2.reporter.beans.OkHttpSenderFactoryBean">
<property name="endpoint" value="http://localhost:9411/api/v2/spans"/>
</bean>
</property>
<!-- wait up to half a second for any in-flight spans on close -->
<property name="closeTimeout" value="500"/>
</bean>
<!-- setup zipkin tracer -->
<bean id="zipkinTracer" class="org.apache.camel.zipkin.ZipkinTracer">
<property name="serviceName" value="dude"/>
<property name="spanReporter" ref="http"/>
</bean>
351.1. ServiceName Copy linkLink copied to clipboard!
However, if you want to map Camel endpoints to human friendly logical names, you can add mappings
- ServiceName *
You can configure a global service name that all events will fallback and use, such as:
zipkin.setServiceName("invoices");
This will use the same service name for all incoming and outgoing zipkin traces. If your application uses different services, you should map them to more finely grained client / server service mappings
351.2. Client and Server Service Mappings Copy linkLink copied to clipboard!
- ClientServiceMappings
- ServerServiceMappings
If your application hosts a service that others can call, you can map the Camel route endpoint to a server service mapping. For example, suppose your Camel application has the following route:
from("activemq:queue:inbox")
.to("http:someserver/somepath");
And you want to make that as a server service, you can add the following mapping:
zipkin.addServerServiceMapping("activemq:queue:inbox", "orders");
Then when a message is consumed from that inbox queue, it becomes a zipkin server event with the service name 'orders'.
Now suppose that the call to http:someserver/somepath is also a service, which you want to map to a client service name, which can be done as:
zipkin.addClientServiceMapping("http:someserver/somepath", "audit");
Then in the same Camel application you have mapped incoming and outgoing endpoints to different zipkin service names.
You can use wildcards in the service mapping. To match all outgoing calls to the same HTTP server you can do:
zipkin.addClientServiceMapping("http:someserver*", "audit");