Skip to content

Compile-Time/demo-tracing-in-spring-boot-2-and-3

Repository files navigation

Spring Boot 2 & 3 Tracing Demo

This demo is a multi-project showcasing how to perform tracing in Spring Boot 2 with Spring Cloud Sleuth and Spring Boot 3 with Micrometer Tracing.

It was created to provide examples for the blog article Switching from Spring Cloud Sleuth to Micrometer Tracing / Micrometer Observation for Spring Boot 3.

The multi-project consists of the following subprojects:

  • common-interface: Project containing communication classes used between a server and a client.
  • spring-boot-2-server: A Spring Boot 2 server providing REST endpoints.
  • spring-boot-2-client: A Spring Boot 2 client using a RestTemplate to query the Spring Boot 2 server.
  • spring-boot-3-server: A Spring Boot 3 server providing REST endpoints.
  • spring-boot-3-client: A Spring Boot 3 client using a RestTemplate to query the Spring Boot 3 server.

Spring Sleuth API support in Spring Boot 3

Spring Boot 3.0.0 and Micrometer Tracing 1.0.0 do not support the Sleuth API annotations (@NewSpan, @ContinueSpan and @SpanTag). Support for these annotation was added in Spring Boot 3.1 and Micrometer Tracing 1.1.0.

For information about how to use these annotations, see 6.5. Aspect Oriented Programming (starting from Micrometer Tracing 1.1.0).

If you need support for the Sleuth annotations but can not use Spring Boot 3.1 or are waiting for a 3.1 GA release, see the branches sleuth-aspect-code-copy, sleuth-aspect-manual-implementation and feature/micrometer-1.1.0-spring-boot-3.0.0 of this repository for some alternative solutions.

Infrastructure

This project requires a tracing infrastructure with the following components to be present:

  • Grafana Loki
  • Zipkin or Zipkin compliant distributed tracing system
  • Prometheus

Inside the docker-compose folder two compose files exist to start a tracing infrastructure with the following components:

  • Grafana
  • Grafana Loki
  • Grafana Tempo
  • Prometheus

Database model

The domain is based on this model.

Database model

The model is documented as a PlantUML document here: database_model.puml

Observation documentation documents

To take a look at the generated observation documentation documents the folder observation-documentation-documents has been pushed into the git history.

Running the demo

Before starting the demo make sure that you started the infrastructure.

cd docker-desktop
docker-compose -f docker-desktop.yml up -d
# or
docker-compose -f colima.yml up -d

To start the demo for a specific Spring Boot version run the following gradle tasks.

# Spring Boot 2
gradlew :spring-boot-2-server:bootRun
gradlew :spring-boot-2-client:bootRun

# or

# Spring Boot 3
gradlew :spring-boot-3-server:bootRun
gradlew :spring-boot-3-client:bootRun

It is possible to start both Spring Boot 2 and Spring Boot 3 demos, since all services run on different ports.

The client projects contain http files in resources/http/ to run the demos.

If you want to clear the data in the docker postgres database you can run the following scripts for each Spring Boot version respectively.

spring-boot-2-server/src/main/resources/db/cleanup/wipe-tables.sql
spring-boot-3-server/src/main/resources/db/cleanup/wipe-tables.sql

Resources used to build this demo

Code:

Infrastructure:

About

Demo project for tracing in Spring Boot 2 and Spring Boot 3.

Topics

Resources

License

Stars

Watchers

Forks

Languages