Skip to content

Spring boot application for distributed tracing and logging using Grafana, Tempo and Loki

License

Notifications You must be signed in to change notification settings

Ravi-Asgr/distributed-tracing-logging

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

distributed-tracing-logging

Spring boot application for distributed tracing and logging using Grafana, Tempo and Loki

distributed-tracing-logging is a multi-module spring boot application to integrate distributed tracing and distributed logging features to Spring Boot microservices. This maven based project has two modules: user-service and address-service each representing an microservice.

user-service

A simple service which retrieves user details, calls address-service for user's address details. This is a dummy service returns same response on each call.

GET: http://localhost:7000/user/123
Response: {"name":"123","address":{"field":"123"}}

address-service

A simple service which retrieves an user's address, called by user-service for user's address details. This is a dummy service returns same response on each call.

Build steps

Build user-service and address-service as war artifacts.

 mvn clean install

Logging configuration

Loki and Promtail are required for distributed logging.
 -> Start Loki followed by Promtail
 -> Start Promtail: promtail-windows-amd64.exe --config.file=promtail-local-config.yml
 -> Promtail config file: config_files\promtail-local-config.yml
 -> Start Loki: loki-windows-amds64.exe --config.file=loki-local-config.yml
 -> Loki config file: config_files\loki-local-config.yml

Tracing configuration

Download Tempo for windows:
 -> Go to: https://github.com/grafana/tempo/releases
 -> Expand "Assests" section to find binary for windows
 -> Link to binary: https://github.com/grafana/tempo/releases/download/v2.3.0/tempo_2.3.0_windows_amd64.tar.gz
 -> Start Tempo: tempo.exe -config.file=tempo.yml
 -> Tempo config file: config_files\tempo.yml

Grafana configure Loki and Tempo as datasource

Start Grafana: grafana-server.exe
 -> Configure Loki datasource: Give URL as : http://localhost:3100


 -> Configure Tempo datasource: Give URL as : http://localhost:9000


Create spring boot services with dependencies and configuration

Create two service: user-service and address-service
 -> user-service calls address-service for address related information

Endpoint exposed by user-service
 ->GET: http://localhost:7000/user/123
 ->Response: {"name":"123","address":{"field":"123"}}

Maven dependencies added:
 ->spring-cloud-starter-sleuth :
 ->spring-cloud-sleuth-otel-autoconfigure
 ->opentelemetry-exporter-otlp

application.properties
 ->spring.application.name=user-service
 ->spring.sleuth.otel.config.trace-id-ratio-based=1.0
 ->spring.sleuth.otel.exporter.otlp.endpoint=http://localhost:4317

logback.xml

  %d{yyyy-MM-dd HH:mm:ss.SSS, GMT} %p [ traceid=%X{traceId} spanid=%X{spanId} ] %c{1.} [%t] %m%n

Log and Trace snapshots

Logs with Trace ID and Span ID seen in Grafana - Loki





Traces with Trace ID and Span ID seen in Grafana - Tempo



Releases

No releases published

Packages

 
 
 

Languages