liveBook · Manning

Chapter 9: Observing AI operations

What you will learn in chapter 9 of Spring AI in Action

The introduction explains why observing application metrics and tracing data helps reveal the health and behavior of a Spring AI application.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why observing application metrics and tracing data helps reveal the health and behavior of a Spring AI application.

Key terms: observability, metrics, tracing

9.1 Enabling Actuator metrics

This section shows how to expose Spring AI metrics through Spring Boot Actuator and interpret the metrics available after an application request.

Key terms: Actuator starter, health endpoint, metrics endpoint, application.properties, `/ask`, `/actuator/metrics`, vector store, generative AI APIs, token usage, Spring AI advisors

9.1.1 Inspecting vector store operations

This section shows how to read Actuator metrics for vector store operations and filter them by operation type.

Key terms: metrics endpoint, db.vector.client.operation, measurements, COUNT, TOTAL_TIME, MAX, availableTags, tag, db.operation.name, add

9.1.2 Examining AI model interaction

This section shows how Actuator metrics reveal the timing, types, and models involved in AI API operations, and how tags narrow the statistics to particular operations.

Key terms: gen_ai.client.operation, Actuator’s metrics endpoint, availableTags, embedding operations, gen_ai.operation.name, chat operations, vector store, gen_ai.request.model, gen_ai.response.model, gpt-4o-mini

9.1.3 Counting token usage

This subsection shows how to use Actuator token-usage metrics to estimate AI costs while avoiding a misleading unfiltered total.

Key terms: tokens, prompt tokens, generation tokens, gen_ai.client.token.usage, gen_ai.token.type, input, output, total, GPT-4o-mini, input tokens

9.1.4 Observing ChatClient operations

This section shows how to read ChatClient and advisor metrics, explains the limits of their filtering tags, and motivates viewing metrics through an observability tool.

Key terms: spring.ai.chat.client, spring.ai.chat.client.stream, streaming, spring.ai.advisor, BEFORE, AFTER, AROUND, spring.ai.advisor.type, observability tool, Micrometer

9.2 Viewing metrics in Prometheus

This section shows how to expose Spring AI metrics to Prometheus and inspect them as time-series data.

Key terms: Prometheus, Micrometer, Spring Boot Actuator, /actuator/prometheus, scrape, expression, Table, Graph, tag, gen_ai_client_operation_seconds_max

9.3 Creating AI dashboards

This section shows how to connect Grafana to the existing Prometheus metrics and create a dashboard for Spring AI operations.

Key terms: Grafana, Prometheus data source, Docker Compose, Prometheus server URL, dashboard, panel, gen_ai_client_operations_seconds_max, Label Filters, gen_ai_operation_name, chat

9.4 Tracing AI operations

This section configures Micrometer tracing for Board Game Buddy and uses Jaeger spans and tags to explain what happens during a question request.

Key terms: Micrometer Tracing, OpenTelemetry, OTLP exporter, Jaeger, management.tracing.sampling.probability, sampling probability, trace, span, ChatClient, VectorStoreChatMemoryAdvisor

9.5 Summary

Concepts explained in this chapter

← Chapter 8: Generating with voice and pictures Chapter 10: Safeguarding generative AI →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.