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,prometheusToken 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.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
