ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • How to Set Up Jaeger on Spring Boot Java Application
    IT.en_US/Cloud_OuterArchitecture 2023. 3. 9. 22:26
    반응형

    How to Set Up Jaeger on Spring Boot Java Application

    Jaeger is an open-source distributed tracing system that can be used to monitor and troubleshoot microservices-based distributed systems. In this article, we will see how to set up Jaeger on a Spring Boot Java application.

    Prerequisites

    Before we start, make sure that you have the following prerequisites:

    • A Java Development Kit (JDK) version 8 or higher installed
    • A Spring Boot application
    • Docker installed on your machine

    Step 1: Add Jaeger Dependencies

    To get started with Jaeger, we need to add the following dependencies to our pom.xml file:

    <dependency>
        <groupId>io.opentracing.contrib</groupId>
        <artifactId>opentracing-spring-jaeger-cloud-starter</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>io.jaegertracing</groupId>
        <artifactId>jaeger-client</artifactId>
        <version>1.7.0</version>
    </dependency>
    

    The opentracing-spring-jaeger-cloud-starter dependency provides the necessary Spring Boot auto-configuration classes to set up Jaeger. The jaeger-client dependency provides the Jaeger client library.

    Step 2: Configure Jaeger

    Next, we need to configure Jaeger in our application. We can do this by adding the following properties to the application.properties file:

    opentracing.jaeger.service-name=your-service-name
    opentracing.jaeger.udp-sender.host=jaeger
    opentracing.jaeger.udp-sender.port=6831
    opentracing.jaeger.enabled=true
    

    Here, your-service-name is the name of your Spring Boot application. We also specify the host and port of the Jaeger agent, which is running as a Docker container. Note that we have enabled Jaeger by setting the opentracing.jaeger.enabled property to true.

    Step 3: Start Jaeger Agent

    Before we run our Spring Boot application, we need to start the Jaeger agent as a Docker container. We can do this by running the following command:

    docker run -d -p 5775:5775/udp -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p 16686:16686 -p 14268:14268 jaegertracing/all-in-one:1.7

    This will start the Jaeger agent as a Docker container and expose the necessary ports.

    Step 4: Run Spring Boot Application

    Finally, we can run our Spring Boot application using the following command:

    ./mvnw spring-boot:run

    Once the application is running, we can navigate to the Jaeger UI at http://localhost:16686 to view the traces.

    Conclusion

    In this article, we have seen how to set up Jaeger on a Spring Boot Java application. We added the necessary dependencies, configured Jaeger, started the Jaeger agent as a Docker container, and ran our Spring Boot application. With Jaeger, we can monitor and troubleshoot our microservices-based distributed systems.

    반응형
Designed by Tistory.