Setting Up Observability in Spring Boot Apps on Azure Kubernetes Service (AKS) with Logging, Tracing, and Metrics (Loki, Jaeger, Prometheus, Grafana, Azure Monitor): Complete Guide
This Cloud Component Diagram represents the observability architecture for a Spring Boot Microservice running on Azure Kubernetes Service (AKS) with logging, tracing, and metrics monitoring.
Key Components
1️⃣ Spring Boot Microservice (App) on AKS
- Sends logs to Loki (Logging)
- Sends traces to Jaeger via OpenTelemetry
- Exposes metrics to Prometheus
- Sends data to Azure Monitor
2️⃣ Observability Stack
- Loki collects logs → Grafana visualizes them
- Jaeger receives traces → Allows trace viewing
- Prometheus scrapes metrics → Grafana visualizes them
3️⃣ User Interaction
- Grafana provides real-time monitoring
- Azure Monitor collects logs & metrics for deeper analysis
This architecture ensures full observability in a cloud-native microservices environment.
Here is a complete guide to implement Observability in Spring Boot Apps on Azure Kubernetes Service (AKS) from scratch. This setup will cover logging, tracing, and metrics using tools like Loki, Jaeger, Prometheus, Grafana, and Azure Monitor.
1. Prerequisites
Before starting, ensure you have the following:
- Azure Subscription with an active AKS Cluster (Azure Kubernetes Service).
- kubectl & Helm installed.
- Docker installed to build the container images.
- Azure CLI for managing Azure resources.
- Spring Boot Microservice project set up (you can use any Spring Boot app).
2. Setting Up Azure Kubernetes Service (AKS)
2.1 Create AKS Cluster
- Log in to Azure using the Azure CLI:
- Create a resource group for the AKS cluster:
- Create the AKS cluster:
- Connect to the AKS cluster using kubectl:
3. Spring Boot Microservice Setup
3.1 Create a Spring Boot Application
Add Actuator & Prometheus Dependencies in
pom.xml
:Configure Prometheus Metrics in
application.yml
:Configure Jaeger Tracing in
application.yml
:Build your Spring Boot application:
4. Dockerize Spring Boot App
Create a Dockerfile in the project root:
Build Docker image:
Push the image to Azure Container Registry (ACR):
5. Install Loki, Prometheus, Grafana, and Jaeger on AKS
5.1 Install Helm
- Add Helm repositories for Prometheus, Loki, and Jaeger:
5.2 Deploy Loki (Logging)
Install Loki using Helm:
Check the logs:
5.3 Deploy Prometheus (Metrics)
Install Prometheus:
Expose Prometheus for testing:
5.4 Deploy Jaeger (Tracing)
Install Jaeger:
Expose Jaeger UI:
6. Deploy Spring Boot Application on AKS
Create Kubernetes Deployment YAML for Spring Boot App (
deployment.yml
):Apply the deployment:
Expose the Spring Boot application:
7. Verify Observability Setup
Logs in Grafana:
- Open Grafana and configure Loki as a data source.
- View logs from your Spring Boot app in the Logs tab.
Metrics in Prometheus:
- Access Prometheus at
http://localhost:9090
. - Verify metrics scraping by querying
http_requests_total
and others.
- Access Prometheus at
Traces in Jaeger:
- Access Jaeger at
http://localhost:16686
. - Verify traces and transactions for requests made to your Spring Boot app.
- Access Jaeger at
8. Azure Monitor Integration
Enable Azure Monitor on AKS:
View Logs and Metrics in Azure Portal:
- Go to Azure Monitor → Logs and Metrics to see the real-time data from your Spring Boot app.
9. Conclusion
You have now set up full observability for your Spring Boot App on Azure Kubernetes Service (AKS) using Prometheus (Metrics), Loki (Logging), Jaeger (Tracing), and Azure Monitor.
This architecture allows you to easily monitor, trace, and log your microservices, ensuring better performance, troubleshooting, and scalability in the cloud.