Observability = 3 trụ cột: Metrics, Traces, Logs.
- OpenTelemetry (OTel): chuẩn mở thống nhất 3 trụ cột — language-agnostic, vendor-neutral.
- Micrometer: abstraction layer giữa app Spring và OTel.
Spring Boot 3 auto-configure:
1. Distributed Tracing — mỗi request tự gán traceId/spanId, propagate qua HTTP header → theo dõi qua nhiều service.
2. Metrics — export Prometheus format, Grafana visualize.
3. Logs tự động inject traceId → filter log của 1 request qua 5+ service dễ dàng.
Setup nhanh:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>management:
tracing.sampling.probability: 1.0 # dev: 100%, prod: 0.1
otlp.tracing.endpoint: http://otel-collector:4317Tools tích hợp: Jaeger/Zipkin (UI trace), Prometheus + Grafana (metrics), Loki (logs).
Vì sao cần: debug microservice không có tracing như "mò kim đáy bể" — lỗi nằm ở service nào trong 10 service đều có thể.
Observability = three pillars: Metrics, Traces, Logs.
- OpenTelemetry (OTel): open standard unifying all three — language-agnostic, vendor-neutral.
- Micrometer: abstraction layer between Spring apps and OTel.
Spring Boot 3 auto-configures:
1. Distributed Tracing — every request gets a traceId/spanId, propagated via HTTP headers → traceable across services.
2. Metrics — exported in Prometheus format, visualised in Grafana.
3. Logs automatically include traceId → filtering one request's logs across 5+ services is easy.
Quick setup:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>management:
tracing.sampling.probability: 1.0 # dev: 100%, prod: 0.1
otlp.tracing.endpoint: http://otel-collector:4317Integrated tools: Jaeger/Zipkin (trace UI), Prometheus + Grafana (metrics), Loki (logs).
Why needed: debugging microservices without tracing is like searching for a needle in a haystack — the bug could be in any one of 10 services.