Spring / Spring Boot 4 Basics Interview Questions
What is Spring Boot's observability stack in Boot 4 with Micrometer and OpenTelemetry?
Spring Boot 4 builds observability around Micrometer (metrics), Micrometer Tracing (distributed tracing), and OpenTelemetry (standard telemetry export). The management.opentelemetry.* property namespace is new in Boot 4.
| Pillar | Library | What it tracks |
|---|---|---|
| Metrics | Micrometer | HTTP request rates, JVM heap, GC, custom counters/gauges |
| Tracing | Micrometer Tracing + OTel | Distributed request traces across services |
| Logging | SLF4J + Logback/Log4j2 | Structured application logs |
| Health | Spring Boot Actuator | Component health and readiness |
// Custom metrics with Micrometer: @Service public class OrderService { private final Counter orderCounter; private final Timer orderTimer; public OrderService(MeterRegistry registry) { this.orderCounter = Counter.builder("orders.created") .description("Total orders created") .tag("environment", "prod") .register(registry); this.orderTimer = Timer.builder("orders.processing.time") .description("Time to process order") .register(registry); } public Order placeOrder(CreateOrderRequest request) { return orderTimer.record(() -> { Order order = doCreateOrder(request); orderCounter.increment(); return order; }); } } # application.yml: OpenTelemetry configuration (Boot 4) management: opentelemetry: resource-attributes: service.name: order-service service.version: "2.1.0" deployment.environment: production tracing: sampling: probability: 0.1 # 10% sampling in production metrics: export: prometheus: enabled: true # expose /actuator/prometheus # Export traces to Jaeger / Zipkin / OTel Collector: management.otlp.tracing.endpoint=http://otel-collector:4317/v1/traces
More Related questions...