Apache Camel: Trace control with Zipkin

Daniel S. Blanco
4 min readNov 1, 2021

--

Today we are going to see possibly one of the simplest posts we have done about Apache Camel. In it, we will see how to integrate it with Zipkin.

Zipkin is a distributed instrumentation and monitoring tool that will allow us to collect service information and perform searches on it. With the aim of finding problems in the latency of them, mainly through evaluating how long it has taken the execution of those services.

We already saw some time ago an example of Apache Camel with Jaeger, here. And this is another tool but with a similar objective. So it will help us to refresh concepts that we saw in the previous post:

  • Distributed Tracing: It is a method used to profile and monitor applications. It helps us to point out where the failures occur and what causes the malfunction.
  • Span: It is the main component of a distributed trace, representing an individual unit of work performed in a distributed system. They encapsulate application information.
  • Trace: It is an acyclic graph of Span.

Camel Zipkin is a component that will allow us to trace incoming and outgoing messages to Camel and their associated time. The spans will be captured and sent to Zipkin.

One of the important points is to create a mapping of Apache Camel endpoints so that improved searches can be performed in Zipkin. Associating each span to a specific service and not to the whole application.

The mapping of services can be done with the use of wildcards or regular expressions. If nothing is specified, Camel will send by default the URL of the invocations.

But let’s start with the example, which we can easily see in action. The first step will be to raise a docker with Zipkin. Which we can do in a single line.

docker run -d -p 9411:9411 openzipkin/zipkin

And the next step will be to configure our application. As a differentiating effect to any other Apache camel application, we will have to add the dependency to use Zipkin. As we use Apache Camel with Spring, we will only need the starter.

<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-zipkin-starter</artifactId>
</dependency>

Next, we will configure the application to send information to Zipkin through the @CamelZipkin annotation that we will put in the main startup class. And in the configuration file, we will indicate the URL where the spans will be sent, it’s mandatory.

camel.zipkin.endpoint=http://localhost:9411/api/v2/spans

Now we will be able to invoke the methods of our services and we will see these invocations in the Zipkin GUI.

As you can see in the screenshot, the execution time of the method executed is indicated. But as we have not configured anything, we simply see the URL of the invocation we have made.

If we click on the show button, we can see more detail of the span, the associated tags, and the trace associated with it.

The information that we see is a little scarce because of the simplicity of the microservice and because we have not made any type of configuration or mapping of the services. Now, we will see how we can customize the measurement of the invocations to the methods.

In the application.properties file we can indicate two types of configuration. They are incompatible, if the individual mapping is checked, the services that are not mapped will not be sent to Zipkin.

  • camel.zipkin.service-name: It allows us to indicate a name for the mapping of all the services of the application and not to show only the URL.
  • camel.zipkin.server-service-mappings.{serviceId}: This allows us to indicate a specific mapping to a specific service. This service can be identified by its routeId in Camel.

If we indicate the following configuration, we will have the output shown below.

camel.zipkin.server-service-mappings.mockClientGetAll=getAll
camel.zipkin.server-service-mappings.mockGetById=getById

As you can see, it has been really easy to communicate our Apache Camel services with a platform as useful as Zipkin and to instrument and monitor the performance of your micro-services.

As always, you can see all the code here.

--

--

Responses (1)