/spring-boot-tracing-demo

Distributed tracing with Spring Boot and OpenTelemetry

Primary LanguageJavaApache License 2.0Apache-2.0

Distributed Tracing in Spring Boot 3 with Micrometer Tracing and OpenTelemetry Auto Instrumentation

This project is a quick example to showcase Distributed Tracing in a Spring Boot application using Micrometer and OpenTelemetry.

There are 2 tracing scenarios - HTTP and Apache Kafka

Services communicating over HTTP

image

  1. HTTP Service 1 makes a GET call to HTTP Service 2.
  2. HTTP Service 2 makes a GET call to whatthecommit.com.
  3. HTTP Service 2 returns the response from whatthecommit.com back to HTTP Service 1.

Observability with Micrometer Tracing

  1. Stay on the main branch.

  2. Change to otel-http folder:

    cd otel-http
  3. Compile and build the docker image of http services.

    mvn spring-boot:build-image
  4. Run the docker-compose setup. This will start Jaeger and the HTTP services.

    docker-compose up
  5. Call the httpservice1.

    curl http://localhost:8080
  6. Open Jaeger at http://localhost:16686 and check the traces.

image

Observability with OpenTelemetry Auto Instrumentation

  1. Switch to spring-boot-3-opentelemetry branch.

  2. Change to otel-http folder:

    cd otel-http
  3. Compile and build the docker image of http services.

    mvn spring-boot:build-image
  4. Run the docker-compose setup. This will start Jaeger and the HTTP services.

    docker-compose up
  5. Call the httpservice1.

    curl http://localhost:8080
  6. Open Jaeger at http://localhost:16686 and check the traces.

image

Services communicating over Apache Kafka

image

  1. Kafka Producer makes a GET call to whatthecommit.com.
  2. Kafka Producer produces the response from Step 1 to Apache Kafka.
  3. Kafka Consumer consumes the message from Apache Kafka.
  4. After consumption, Kafka Consumer store the record in H2 in-memory DB.

Observability with Micrometer Tracing

  1. Stay on the main branch.

  2. Change to otel-kafka folder:

    cd otel-kafka
  3. Compile and build the docker image of kafka services.

    mvn spring-boot:build-image
  4. Run the docker-compose setup. This will start a 1-node Kafka cluster, Jaeger and the Kafka producer/consumer services.

    docker-compose up
  5. Call the kafkaservice1.

    curl http://localhost:8080
  6. Open Jaeger at http://localhost:16686 and check the traces.

image

Observability with OpenTelemetry Auto Instrumentation

  1. Switch to spring-boot-3-opentelemetry branch.

  2. Change to otel-kafka folder:

    cd otel-kafka
  3. Compile and build the docker image of http services.

    mvn spring-boot:build-image
  4. Run the docker-compose setup. This will start a 1-node Kafka cluster, Jaeger and the Kafka producer/consumer services.

    docker-compose up
  5. Call the kafkaservice1.

    curl http://localhost:8080
  6. Open Jaeger at http://localhost:16686 and check the traces.

image