Uncorp
Log In
Java & Full Stack3 min readUpdated 2026-11-11

Spring Boot 3 Observability in Production: Distributed Tracing with OpenTelemetry, Micrometer, Prometheus & Grafana

Why `System.out.println` and scattered log files fail across 15 microservices—and how to wire `traceId`, `spanId`, RED metrics, and Spring AI token telemetry.

Naitik Tailor & Uncorp Engineering Faculty
Spring Boot 3 Observability with OpenTelemetry Distributed Tracing, Prometheus & Grafana
TL;DR — Key Engineering & Career Takeaways
  • When a customer reports a 9-second checkout delay across 8 microservices, grepping unindexed text logs on 20 containers is impossible without Distributed Tracing (`traceId` + `spanId`).
  • Spring Boot 3 replaced legacy Spring Cloud Sleuth with the unified **Micrometer Observation API** (`ObservationRegistry`) and **OpenTelemetry (OTel)** exporter—allowing you to write instrumentation once and emit both Prometheus metrics and Tempo/Jaeger traces automatically.
  • Modern Java + Gen AI services also track LLM-specific observability: prompt/completion token counts (`gen_ai.usage.input_tokens`), vector retrieval latency, and model fallback rates.

1. The 3 Pillars of Microservice Observability: Metrics, Logs & Traces

In production engineering, Metrics tell you *that* something is broken (e.g., P99 latency spiked above 3s), Distributed Traces tell you *where* it broke (e.g., `InventoryService -> PostgreSQL query` took 2.8s of the 3s), and Structured Correlated Logs tell you *why* it broke (e.g., `DeadlockDetectedException` for `sku_id=9941`).

Spring Boot 3 Observability Stack & Production Tooling
Observability PillarSpring Boot 3 / Java 21 APICollection & Storage BackendWhat You Alert & Debug On
1. Metrics (RED + JVM)Micrometer + `/actuator/prometheus`Prometheus + Grafana DashboardsRequest Rate, Error % (5xx), P95/P99 Latency Histograms, HikariCP pool exhaustion, JVM GC pauses
2. Distributed Traces`micrometer-tracing-bridge-otel` + W3C `traceparent` HTTP/Kafka headersOpenTelemetry Collector → Grafana Tempo / Jaeger / ZipkinEnd-to-end waterfall timeline across API Gateway → Spring Boot → Kafka → Postgres → Spring AI
3. Structured JSON LogsSLF4J + Logback JSON encoder with automatic MDC `[traceId, spanId]` injectionGrafana Loki / ELK (Elasticsearch, Logstash, Kibana)Instant filtering of all log lines across 10 microservices for a single failing `traceId`

2. How W3C `traceparent` Context Propagation Works Across HTTP & Kafka

When you use Spring Boot 3's auto-configured `RestClient.Builder`, `WebClient.Builder`, and `KafkaTemplate`, Micrometer Tracing automatically injects the W3C standard `traceparent` header into every outbound call:

Distributed Trace Propagation Across Spring Boot 3 + Spring AI
[React Client] ──► [API Gateway: Generates traceId = 4bf92f3577b34da6...]
   ├─► [OrderService (spanId=a1): 12ms] -> Logs JSON with { traceId: '4bf9...', spanId: 'a1' }
   ├─► [PaymentService (spanId=b2): 85ms] -> Calls PostgreSQL (spanId=b3: 18ms)
   └─► [Spring AI Assistant (spanId=c4): 640ms]
          ├─► [pgvector Similarity Search (spanId=c5): 22ms]
          └─► [LLM ChatModel Call (spanId=c6): 610ms | input_tokens=1420, output_tokens=185]

3. Bonus Differentiator: Monitoring Spring AI & Vector Store Telemetry

Spring AI natively integrates with Micrometer's `ObservationRegistry`! Out of the box, every `ChatClient` and `VectorStore` call records high-value metrics including model name, temperature, input/output token consumption, and vector search latency—letting you build a real-time Grafana dashboard showing token cost per endpoint alongside standard JVM and HTTP metrics.

Frequently Asked Questions

Why did Spring Boot 3 replace Spring Cloud Sleuth with Micrometer Tracing?

Previously, developers had to write separate code for metrics (Micrometer) and tracing (Sleuth). Spring Boot 3 unified both into the Micrometer Observation API (`@Observed`), where a single observation automatically starts a timer metric AND creates an OpenTelemetry trace span.

Why must you instantiate `RestClient` via injected `RestClient.Builder` for tracing?

If you call `RestClient.create()` manually with `new`, Spring Boot cannot attach its Micrometer observation interceptors, breaking `traceId` propagation to downstream microservices. Always inject the Spring-managed `RestClient.Builder`.

Written & Reviewed By Uncorp Engineering Faculty

Naitik Tailor & Uncorp Engineering Faculty

Founder & Principal Engineering Mentors (12+ Yrs Enterprise Experience) · VIT CSE '21 · Symbiosis MBA '24 · Ex-Delhivery & Ex-Aditya Birla Capital

About Uncorp

Continue Reading in This Topic Cluster

All 73 Guides