Spring / Spring AI interview questions
How does Spring AI handle observability and what metrics does it expose?
Spring AI integrates with Spring Boot's Micrometer-based observability stack out of the box. When spring-ai-*-spring-boot-starter is on the classpath alongside spring-boot-starter-actuator and a Micrometer registry (Prometheus, OpenTelemetry, Zipkin, etc.), Spring AI auto-configures instrumentation for every AI model call.
What Spring AI instruments by default:
- spring.ai.chat.client — a timer and counter around ChatClient calls, tagged with model name, operation type, and provider.
- spring.ai.chat.model — metrics at the ChatModel level with latency histograms.
- Token usage — counters for
input.tokens,output.tokens, andtotal.tokensextracted from the provider response metadata. Critical for cost tracking. - Distributed traces — each AI call creates a span with prompt content (configurable), model name, and token counts as attributes.
# application.properties â enable full prompt content in traces (use carefully â PII risk) spring.ai.chat.client.observations.include-prompt=true spring.ai.chat.model.observations.include-completion=false # Enable AI metrics endpoint management.endpoints.web.exposure.include=metrics,prometheus
Token usage metrics are especially valuable in production because they directly correlate to cost. Setting up a Grafana dashboard on spring.ai.chat.model.input.tokens per service lets you attribute spend to specific features and spot runaway prompt sizes before they cause invoice surprises.
More Related questions...