/distributed-tracing

Using distributed tracing with OpenTelemetry, Sleuth, Kafka, Jaeger and Spring boot

Primary LanguageJava

Using Distributed Tracing With OpenTelemetry, Sleuth, Kafka, Jaeger and Spring boot

Distributed tracing gives you insight into how a particular service is performing as part of the whole in a distributed software system. It tracks and records requests from their point of origin to their destination and the systems through which they pass.

Let’s first take a look at some basic terms in distributed tracing.

Span

The "span" is the primary building block of a distributed trace, representing an individual unit of work done in a distributed system.

Trace

The collection of Spans that have the same root is considered to create a group called trace.

πŸ“ Requirements

  • Git
  • JDK 17
  • Apache Maven

πŸš€ How to Run Local

Execute the docker-compose and then execute all services (email-service, user-service and report-service)

# Start kafka, kafka-ui, zookeeper, jaeger and sleuth
docker-compose up -d

# Clean and compile all projects
mvn clean install

# Runing user-service
cd user-service
mvn spring-boot:run

# Runing email-service
cd email-service
mvn spring-boot:run

# Runing report-service
cd email-service
mvn spring-boot:run

πŸ“– Local Dependencies

  • OpenTelemetry: also known as OTel for short, is an open source observability framework with ready-to-use implementations to enable the effective creation and collection of telemetry data (metrics, logs, and traces) and to forward them to external tools.
  • Spring Cloud Sleuth: is a project managed and maintained by Spring Cloud team that provides Spring Boot autoconfiguration for distributed tracing.
  • Jaeger: is an open source project with end-to-end distributed tracing to Monitor and troubleshoot transactions in complex distributed systems
  • Maven: Build and dependency control
  • H2 Database: is a relational database management system written in Java. It can be embedded in Java applications or run in client-server mode. The software is available as open source software Mozilla
  • Actuator: is mainly used to expose operational information about the running application β€” health, metrics, info, dump, env, etc.

πŸ—Ό System Design Architecture

Let’s design three Spring Boot microservices:

  • user-service: a simple user CRUD service. In addition to persisting data to its database, it providing HTTP API to calls the backend report service via REST API calls.
  • report-service: a simple report CRUD service, it providing HTTP API to the user-service and also publishes events to Kafka when generating a new report record.
  • email-service: Providing KafkaConsumer, listening to the topic reports.

Package Structure
Figure 1: System design architecture for this project

πŸ“¦ Package Structure

Using a monorepo, we have the project structure as follows:

Package Structure
Figure 2: Project structure using monorepo

βœ… Tests Coverage With Jacoco

Report Service

report-service jacoco
Figure 3: Jacoco report-service test coverage

User Service

user-service jacoco
Figure 4: Jacoco user-service test coverage

Email Service

email-service jacoco
Figure 5: Jacoco email-service test coverage