InfoSphere/Spring AI 1.1.9-SNAPSHOT/ 返回书籍
Reference

Observability

qianmoQqianmoQ· 更新于 2026-09-20· 阅读 69 分钟· 0 次阅读

登录后可跨设备保存划线和私人笔记登录
This version is still in development and is not considered stable yet. For the latest stable version, please use Spring AI 2.0.1!

Observability

Spring AI builds upon the observability features in the Spring ecosystem to provide insights into AI-related operations.

The spring-boot-actuator module is required for enabling observability. Add the Spring Boot Actuator dependency to your project’s Maven pom.xml build file:

<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

or to your Gradle build.gradle build file.

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
}

Spring AI provides metrics and tracing capabilities for its core components: ChatClient (including Advisor), ChatModel, EmbeddingModel, ImageModel, and VectorStore.

Low cardinality keys will be added to metrics and traces, while high cardinality keys will only be added to traces.

1.0.0-RC1 Breaking Changes

Following configuration properties have been renamed to better reflect their purpose:

  • spring.ai.chat.client.observations.include-prompt → spring.ai.chat.client.observations.log-prompt
  • spring.ai.chat.observations.include-prompt → spring.ai.chat.observations.log-prompt
  • spring.ai.chat.observations.include-completion → spring.ai.chat.observations.log-completion
  • spring.ai.image.observations.include-prompt → spring.ai.image.observations.log-prompt
  • spring.ai.vectorstore.observations.include-query-response → spring.ai.vectorstore.observations.log-query-response

Chat Client

The spring.ai.chat.client observations are recorded when a ChatClient call() or stream() operations are invoked. They measure the time spent performing the invocation and propagate the related tracing information.

NameDescription
gen_ai.operation.nameAlways framework.
gen_ai.systemAlways spring_ai.
spring.ai.chat.client.streamIs the chat model response a stream - true or false
spring.ai.kindThe kind of framework API in Spring AI: chat_client.

Table 1. Low Cardinality Keys

NameDescription
gen_ai.promptThe content of the prompt sent via the chat client. Optional.
spring.ai.chat.client.advisor.params (deprecated)Map of advisor parameters. The conversation ID is now included in spring.ai.chat.client.conversation.id.
spring.ai.chat.client.advisorsList of configured chat client advisors.
spring.ai.chat.client.conversation.idIdentifier of the conversation when using the chat memory.
spring.ai.chat.client.system.params (deprecated)Chat client system parameters. Optional. Superseded by gen_ai.prompt.
spring.ai.chat.client.system.text (deprecated)Chat client system text. Optional. Superseded by gen_ai.prompt.
spring.ai.chat.client.tool.function.names (deprecated)Enabled tool function names. Superseded by spring.ai.chat.client.tool.names.
spring.ai.chat.client.tool.function.callbacks (deprecated)List of configured chat client function callbacks. Superseded by spring.ai.chat.client.tool.names.
spring.ai.chat.client.tool.namesNames of the tools passed to the chat client.
spring.ai.chat.client.user.params (deprecated)Chat client user parameters. Optional. Superseded by gen_ai.prompt.
spring.ai.chat.client.user.text (deprecated)Chat client user text. Optional. Superseded by gen_ai.prompt.

Table 2. High Cardinality Keys

Prompt and Completion Data

The ChatClient prompt and completion data is typically big and possibly containing sensitive information. For those reasons, it is not exported by default.

Spring AI supports logging the prompt and completion data to help with debugging and troubleshooting.

PropertyDescriptionDefault
spring.ai.chat.client.observations.log-promptWhether to log the chat client prompt content.false
spring.ai.chat.client.observations.log-completionWhether to log the chat client completion content.false
If you enable logging of the chat client prompt and completion data, there’s a risk of exposing sensitive or private information. Please, be careful!

Input Data (Deprecated)

The spring.ai.chat.client.observations.include-input property is deprecated, replaced by spring.ai.chat.client.observations.log-prompt. See Prompt Content.

The ChatClient input data is typically big and possibly containing sensitive information. For those reasons, it is not exported by default.

Spring AI supports logging input data to help with debugging and troubleshooting.

PropertyDescriptionDefault
spring.ai.chat.client.observations.include-inputWhether to include the input content in the observations.false
If you enable the inclusion of the input content in the observations, there’s a risk of exposing sensitive or private information. Please, be careful!

Chat Client Advisors

The spring.ai.advisor observations are recorded when an advisor is executed. They measure the time spent in the advisor (including the time spend on the inner advisors) and propagate the related tracing information.

NameDescription
gen_ai.operation.nameAlways framework.
gen_ai.systemAlways spring_ai.
spring.ai.advisor.type (deprecated)Where the advisor applies it’s logic in the request processing, one of BEFORE, AFTER, or AROUND. This distinction doesn’t apply anymore since all Advisors are always of the same type.
spring.ai.kindThe kind of framework API in Spring AI: advisor.

Table 3. Low Cardinality Keys

NameDescription
spring.ai.advisor.nameName of the advisor.
spring.ai.advisor.orderAdvisor order in the advisor chain.

Table 4. High Cardinality Keys

Chat Model

Observability features are currently supported only for ChatModel implementations from the following AI model providers: Anthropic, Azure OpenAI, Mistral AI, Ollama, OpenAI, Vertex AI, MiniMax, Moonshot, QianFan, Zhipu AI. Additional AI model providers will be supported in a future release.

The gen_ai.client.operation observations are recorded when calling the ChatModel call or stream methods. They measure the time spent on method completion and propagate the related tracing information.

The gen_ai.client.token.usage metrics measures number of input and output tokens used by a single model call.
NameDescription
gen_ai.operation.nameThe name of the operation being performed.
gen_ai.systemThe model provider as identified by the client instrumentation.
gen_ai.request.modelThe name of the model a request is being made to.
gen_ai.response.modelThe name of the model that generated the response.

Table 5. Low Cardinality Keys

NameDescription
gen_ai.request.frequency_penaltyThe frequency penalty setting for the model request.
gen_ai.request.max_tokensThe maximum number of tokens the model generates for a request.
gen_ai.request.presence_penaltyThe presence penalty setting for the model request.
gen_ai.request.stop_sequencesList of sequences that the model will use to stop generating further tokens.
gen_ai.request.temperatureThe temperature setting for the model request.
gen_ai.request.top_kThe top_k sampling setting for the model request.
gen_ai.request.top_pThe top_p sampling setting for the model request.
gen_ai.response.finish_reasonsReasons the model stopped generating tokens, corresponding to each generation received.
gen_ai.response.idThe unique identifier for the AI response.
gen_ai.usage.input_tokensThe number of tokens used in the model input (prompt).
gen_ai.usage.output_tokensThe number of tokens used in the model output (completion).
gen_ai.usage.total_tokensThe total number of tokens used in the model exchange.
gen_ai.promptThe full prompt sent to the model. Optional.
gen_ai.completionThe full response received from the model. Optional.
spring.ai.model.request.tool.namesList of tool definitions provided to the model in the request.

Table 6. High Cardinality Keys

For measuring user tokens, the previous table lists the values present in an observation trace. Use the metric name gen_ai.client.token.usage that is provided by the ChatModel.

Chat Prompt and Completion Data

The chat prompt and completion data is typically big and possibly containing sensitive information. For those reasons, it is not exported by default.

Spring AI supports logging chat prompt and completion data, useful for troubleshooting scenarios. When tracing is available, the logs will include trace information for better correlation.

PropertyDescriptionDefault
spring.ai.chat.observations.log-promptLog the prompt content. true or falsefalse
spring.ai.chat.observations.log-completionLog the completion content. true or falsefalse
spring.ai.chat.observations.include-error-loggingInclude error logging in observations. true or falsefalse
If you enable logging of the chat prompt and completion data, there’s a risk of exposing sensitive or private information. Please, be careful!

Tool Calling

The spring.ai.tool observations are recorded when performing tool calling in the context of a chat model interaction. They measure the time spent on toll call completion and propagate the related tracing information.

NameDescription
gen_ai.operation.nameThe name of the operation being performed. It’s always framework.
gen_ai.systemThe provider responsible for the operation. It’s always spring_ai.
spring.ai.kindThe kind of operation performed by Spring AI. It’s always tool_call.
spring.ai.tool.definition.nameThe name of the tool.

Table 7. Low Cardinality Keys

NameDescription
spring.ai.tool.definition.descriptionDescription of the tool.
spring.ai.tool.definition.schemaSchema of the parameters used to call the tool.
spring.ai.tool.call.argumentsThe input arguments to the tool call. (Only when enabled)
spring.ai.tool.call.resultSchema of the parameters used to call the tool. (Only when enabled)

Table 8. High Cardinality Keys

Tool Call Arguments and Result Data

The input arguments and result from the tool call are not exported by default, as they can be potentially sensitive.

Spring AI supports exporting tool call arguments and result data as span attributes.

PropertyDescriptionDefault
spring.ai.tools.observations.include-contentInclude the tool call content in observations. true or falsefalse
If you enable the inclusion of the tool call arguments and result in the observations, there’s a risk of exposing sensitive or private information. Please, be careful!

EmbeddingModel

Observability features are currently supported only for EmbeddingModel implementations from the following AI model providers: Azure OpenAI, Mistral AI, Ollama, and OpenAI. Additional AI model providers will be supported in a future release.

The gen_ai.client.operation observations are recorded on embedding model method calls. They measure the time spent on method completion and propagate the related tracing information.

The gen_ai.client.token.usage metrics measures number of input and output tokens used by a single model call.
NameDescription
gen_ai.operation.nameThe name of the operation being performed.
gen_ai.systemThe model provider as identified by the client instrumentation.
gen_ai.request.modelThe name of the model a request is being made to.
gen_ai.response.modelThe name of the model that generated the response.

Table 9. Low Cardinality Keys

NameDescription
gen_ai.request.embedding.dimensionsThe number of dimensions the resulting output embeddings have.
gen_ai.usage.input_tokensThe number of tokens used in the model input.
gen_ai.usage.total_tokensThe total number of tokens used in the model exchange.

Table 10. High Cardinality Keys

For measuring user tokens, the previous table lists the values present in an observation trace. Use the metric name gen_ai.client.token.usage that is provided by the EmbeddingModel.

Image Model

Observability features are currently supported only for ImageModel implementations from the following AI model providers: OpenAI. Additional AI model providers will be supported in a future release.

The gen_ai.client.operation observations are recorded on image model method calls. They measure the time spent on method completion and propagate the related tracing information.

The gen_ai.client.token.usage metrics measures number of input and output tokens used by a single model call.
NameDescription
gen_ai.operation.nameThe name of the operation being performed.
gen_ai.systemThe model provider as identified by the client instrumentation.
gen_ai.request.modelThe name of the model a request is being made to.

Table 11. Low Cardinality Keys

NameDescription
gen_ai.request.image.response_formatThe format in which the generated image is returned.
gen_ai.request.image.sizeThe size of the image to generate.
gen_ai.request.image.styleThe style of the image to generate.
gen_ai.response.idThe unique identifier for the AI response.
gen_ai.response.modelThe name of the model that generated the response.
gen_ai.usage.input_tokensThe number of tokens used in the model input (prompt).
gen_ai.usage.output_tokensThe number of tokens used in the model output (generation).
gen_ai.usage.total_tokensThe total number of tokens used in the model exchange.
gen_ai.promptThe full prompt sent to the model. Optional.

Table 12. High Cardinality Keys

For measuring user tokens, the previous table lists the values present in an observation trace. Use the metric name gen_ai.client.token.usage that is provided by the ImageModel.

Image Prompt Data

The image prompt data is typically big and possibly containing sensitive information. For those reasons, it is not exported by default.

Spring AI supports logging image prompt data, useful for troubleshooting scenarios. When tracing is available, the logs will include trace information for better correlation.

PropertyDescriptionDefault
spring.ai.image.observations.log-promptLog the image prompt content. true or falsefalse
If you enable logging of the image prompt data, there’s a risk of exposing sensitive or private information. Please, be careful!

Vector Stores

All vector store implementations in Spring AI are instrumented to provide metrics and distributed tracing data through Micrometer.

The db.vector.client.operation observations are recorded when interacting with the Vector Store. They measure the time spent on the query, add and remove operations and propagate the related tracing information.

NameDescription
db.operation.nameThe name of the operation or command being executed. One of add, delete, or query.
db.systemThe database management system (DBMS) product as identified by the client instrumentation. One of pg_vector, azure, cassandra, chroma, elasticsearch, milvus, neo4j, opensearch, qdrant, redis, typesense, weaviate, pinecone, oracle, mongodb, gemfire, hana, simple.
spring.ai.kindThe kind of framework API in Spring AI: vector_store.

Table 13. Low Cardinality Keys

NameDescription
db.collection.nameThe name of a collection (table, container) within the database.
db.namespaceThe name of the database, fully qualified within the server address and port.
db.record.idThe record identifier if present.
db.search.similarity_metricThe metric used in similarity search.
db.vector.dimension_countThe dimension of the vector.
db.vector.field_nameThe name field as of the vector (e.g. a field name).
db.vector.query.contentThe content of the search query being executed.
db.vector.query.filterThe metadata filters used in the search query.
db.vector.query.response.documentsReturned documents from a similarity search query. Optional.
db.vector.query.similarity_thresholdSimilarity threshold that accepts all search scores. A threshold value of 0.0 means any similarity is accepted or disable the similarity threshold filtering. A threshold value of 1.0 means an exact match is required.
db.vector.query.top_kThe top-k most similar vectors returned by a query.

Table 14. High Cardinality Keys

Response Data

The vector search response data is typically big and possibly containing sensitive information. For those reasons, it is not exported by default.

Spring AI supports logging vector search response data, useful for troubleshooting scenarios. When tracing is available, the logs will include trace information for better correlation.

PropertyDescriptionDefault
spring.ai.vectorstore.observations.log-query-responseLog the vector store query response content. true or falsefalse
If you enable logging of the vector search response data, there’s a risk of exposing sensitive or private information. Please, be careful!

More Metrics Reference

This section documents the metrics emitted by Spring AI components as they appear in Prometheus.

Metric Naming Conventions

Spring AI uses Micrometer. Base metric names use dots (e.g., gen_ai.client.operation), which Prometheus exports with underscores and standard suffixes:

  • Timers → <base>_seconds_count, <base>_seconds_sum, <base>_seconds_max, and (when supported) <base>_active_count
  • Counters → <base>_total (monotonic)

The following shows how base metric names expand to Prometheus time series.

Base metric name Exported time series

gen_ai.client.operation

gen_ai_client_operation_seconds_count
gen_ai_client_operation_seconds_sum
gen_ai_client_operation_seconds_max
gen_ai_client_operation_active_count

db.vector.client.operation

db_vector_client_operation_seconds_count
db_vector_client_operation_seconds_sum
db_vector_client_operation_seconds_max
db_vector_client_operation_active_count

References

Chat Client Metrics

Metric NameTypeUnitDescription
gen_ai_chat_client_operation_seconds_sumTimersecondsTotal time spent in ChatClient operations (call/stream)
gen_ai_chat_client_operation_seconds_countCountercountNumber of completed ChatClient operations
gen_ai_chat_client_operation_seconds_maxGaugesecondsMaximum observed duration of ChatClient operations
gen_ai_chat_client_operation_active_countGaugecountNumber of ChatClient operations currently in flight

Active vs Completed: active_count shows in-flight calls; the _seconds series reflect only completed calls.

Chat Model Metrics (Model provider execution)

Metric NameTypeUnitDescription
gen_ai_client_operation_seconds_sumTimersecondsTotal time executing chat model operations
gen_ai_client_operation_seconds_countCountercountNumber of completed chat model operations
gen_ai_client_operation_seconds_maxGaugesecondsMaximum observed duration for chat model operations
gen_ai_client_operation_active_countGaugecountNumber of chat model operations currently in flight

Token Usage

Metric NameTypeUnitDescription
gen_ai_client_token_usage_totalCountertokensTotal tokens consumed, labeled by token type

Labels

LabelMeaning
gen_ai_token_type=inputPrompt tokens sent to the model
gen_ai_token_type=outputCompletion tokens returned by the model
gen_ai_token_type=totalInput + output

Vector Store Metrics

Metric NameTypeUnitDescription
db_vector_client_operation_seconds_sumTimersecondsTotal time spent in vector store operations (add/delete/query)
db_vector_client_operation_seconds_countCountercountNumber of completed vector store operations
db_vector_client_operation_seconds_maxGaugesecondsMaximum observed duration for vector store operations
db_vector_client_operation_active_countGaugecountNumber of vector store operations currently in flight

Labels

LabelMeaning
db_operation_nameOperation type (add, delete, query)
db_systemVector DB/provider (redis, chroma, pgvector, …)
spring_ai_kindvector_store

Understanding Active vs Completed

  • Active (*_active_count) — instantaneous gauge of in-progress operations (concurrency/load).
  • Completed (*_seconds_sum|count|max) — statistics for operations that have finished:
  • _seconds_sum / _seconds_count → average latency
  • _seconds_max → high-water mark since last scrape (subject to registry behavior)

评论

登录后参与评论

正在加载评论…