Lesson 21 / 25
Metrics, Logs and Traces
Micrometer and OpenTelemetry.
The three signals
Spring Boot instruments HTTP requests, database pools and JVM internals with Micrometer; export metrics to Prometheus, Datadog or other backends by adding a registry dependency. Tracing (Micrometer Tracing with OpenTelemetry) follows requests across services and puts trace ids into logs. Use structured (JSON) logging, which Spring Boot supports natively, so logs, metrics and traces can be correlated.
Enabling Prometheus metrics (sketch)
Not part of the built demo; check the Spring documentation for your version.
# pom.xml: add io.micrometer:micrometer-registry-prometheus
management.endpoints.web.exposure.include=health,info,prometheus
management.metrics.tags.application=${spring.application.name}
logging.structured.format.console=ecs # structured JSON logsTag metrics with the application name
Common tags (application, environment, region) make dashboards across many services usable.
Quick check: Which library does Spring Boot use for metrics instrumentation?
- JUnit
- Micrometer
- Hibernate
- Thymeleaf
Answer
Micrometer — Vendor-neutral metrics.