The Eclipse MicroProfile OpenTracing API

Distributed tracing plays a key role in the era of microservices as it lets you trace the flow of a request across different services. In order to accomplish microservice tracing, we can instrument our services to log messages to a distributed tracing server that can collect, store, and display this information in various formats.

The OpenTracing specification does not address which distributed system is in charge of collecting the tracing data, but a widely adopted end-to-end open source solution is Jaeger (https://www.jaegertracing.io/),which fully implements the OpenTracing standard.

Let's see OpenTracing in action by switching to the Chapter06/opentracing example. First off, in order to use the opentracing extension, the following dependency must be added to your project:

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>io.quarkus:quarkus-smallrye-opentracing</artifactId>
</dependency>
As a matter of fact, when adding this extension, an implementation of an io.opentracing.Tracer object will be made available to your application. This means that all your HTTP requests will be automatically traced.

In terms of configuration, we need to provide some details about the Jaeger endpoint. This can be done either with the application.properties file or using environment variables. The following shows how we have configured the application.properties file to emit a tracing notification to a Jaeger endpoint running on localhost and listening to port 14268:

quarkus.jaeger.service-name=quarkus-service
quarkus.jaeger.sampler-type=const
quarkus.jaeger.sampler-param=1
quarkus.jaeger.endpoint=http://localhost:14268/api/traces

Within the preceding configuration, we have also defined the service name (quarkus-service) and the sampler type. In the sampler type definition, " always makes the same decision for all traces. It either samples all the traces (sampler-param=1) or none of them (sampler-param=2).

Now, we can start the Jaeger service. The simplest way to do this is by running it as a Docker container. The following command will start the jaegertracing/all-in-one container image, forwarding the UDP/TCP port of the Docker container to localhost: 

docker run -e COLLECTOR_ZIPKIN_HTTP_PORT=9411 -p 5775:5775/udp -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p 16686:16686 -p 14268:14268 -p 9411:9411 jaegertracing/all-in-one:latest

Now, we can start using our customer service application and execute some operations with it. Then, we can log into the Jaeger console, which is available at http://localhost:16686:

As shown in the preceding screenshot, in the left panel of the Jaeger UI you can see a combo box named Service, which contains a list of the services that are available for tracing. You should see in it the default jaeger query service, which allows us to trace the query service. Provided that you have configured your Quarkus application to emit notifications, you should be able to see quarkus-service enlisted. Select it and then check the next combo box, which is Operation. This combo box contains all the operations that have been traced for that particular service. Here is a partial view of the UI that contains the combo box:

If you select all, on the screen you should be able to see all the traces for all the HTTP requests to quarkus-service, as shown in the following screenshot:

From there, you can choose to gather more details about a single trace by clicking on it. You will see a comprehensive timeline with details such as the execution time, remote caller, and errors reported:

If you want to download and elaborate on the trace file, you can also choose to trace your operation as JSON by selecting Trace JSON in the top-right corner.

There are quite a lot of possibilities for tracing your application with Jaeger. We advise referring to https://www.jaegertracing.io/ if you want to become a ninja at tracing your microservices!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.70.60