logo

Get in touch

Awesome Image Awesome Image

Java Spring Boot October 30, 2023

Jaeger Integration with Spring Cloud

Writen by Mahipalsinh Rana

10,474

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.

Understanding Distributed Tracing

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:

  • Identify bottlenecks: Find out which parts of your application are causing delays or performance issues.
  • Optimize performance: Analyze the trace data to identify opportunities for optimizing the performance of your application.
  • Troubleshoot errors: Quickly pinpoint the source of errors or exceptions in your system, making debugging much easier.

Introducing OpenTelemetry and Jaeger

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.

Setting Up OpenTelemetry and Jaeger in Spring Boot

Creating an application

Let’s go to https://start.spring.io and create an application with the following dependencies.

  • Spring Web (required to create REST endpoints)
  • Spring Boot Actuator

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.

Service1
Service 2

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

Service-2

in the Controller class

The idea is to call service2 /hello API from service1 /hello API by using RestTemplate.

Starting Jaeger with Docker

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.

http://localhost:16686/

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

https://gitlab.inexture.com/inexture/jaeger

Conclusion

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.

Bringing Software Development Expertise to Every
Corner of the World

United States

India

Germany

United Kingdom

Canada

Singapore

Australia

New Zealand

Dubai

Qatar

Kuwait

Finland

Brazil

Netherlands

Ireland

Japan

Kenya

South Africa