What is Digital Commerce? A...
November 30, 2023
In today’s complex landscape of highly distributed microservices, monitoring, and tracing are essential tools for understanding application performance and effectively diagnosing issues. Distributed tracing allows us to track requests as they traverse multiple services, providing valuable insights into potential bottlenecks and latency problems. In this blog post, we will explore the process of setting up distributed tracing in a Spring Boot application, utilizing OpenTelemetry and Jaeger.
Distributed tracing is a technique that helps developers and operators track requests as they move across various microservices or components of an application. It provides end-to-end visibility into the path a request takes and the time it spends in each service. With this information, you can:
OpenTelemetry (OTel) is indeed an open-source project that offers a set of APIs, libraries, agents, and instrumentation to help you gain observability into your applications by collecting distributed traces, metrics, and logs. OpenTelemetry is designed to be vendor-neutral and can integrate with a range of tracing systems.
Jaeger is a popular open-source distributed tracing system that can act as a backend for collecting, storing, and visualizing trace data generated by applications instrumented with OpenTelemetry.
Together, OpenTelemetry and Jaeger can be used to collect, analyze, and visualize observability data from distributed systems, providing insights into system performance and helping to troubleshoot issues.
Let’s go to https://start.spring.io and create an application with the following dependencies.
The traces will be collected using the micrometer collector in the actuator dependence and exported using the OpenTelemetry requirement.
This would necessitate the addition of the following dependencies.
The Spring Boot parent will handle the dependency versions.
Following that, we will develop two applications.
To export the spans to Jaeger, we must first develop a span exporter bean, as seen below.
In addition, we will define the Jaeger URL where trace data will be recorded in the properties file.
Here, we set the probability of selecting the tracing to 1, which means that every trace and span is reported to Jaeger.
We will also provide a special logging format so that the spans and traces may be seen in the application logs.
Will also configure Bean for RestTemplate
in the Controller class
The idea is to call service2 /hello API from service1 /hello API by using RestTemplate.
To start Jaeger, we have the following docker cmd.
For Jaeger to support the OpenTelemetry input format, we need to set the COLLECTOR_OTLP_ENABLED to true
With this, I will start the applications.
Now, let’s visualize the traces in Jaeger UI.
To access the Jaeger UI, open the following URL.
When we choose the service and click search traces, the traces will be displayed in the UI.
Let’s open the trace and examine the request’s multiple spans.
You can find the complete code on my GitHub repository
Distributed tracing is a powerful tool for monitoring and diagnosing issues in microservices architectures. By integrating OpenTelemetry and Jaeger into your Spring Boot applications with the expertise of Inexture Solutions, you can gain valuable insights into the performance and behavior of your services. This setup provides end-to-end visibility, making it easier to identify and resolve issues in your distributed systems. Start using distributed tracing today to improve the observability of your Spring Boot applications.