Class MicrometerMetricsEmbeddingModelListener
- All Implemented Interfaces:
EmbeddingModelListener
EmbeddingModelListener that uses a Micrometer MeterRegistry to collect metrics
about embedding model interactions following OpenTelemetry Semantic Conventions for Generative AI.
This listener records token usage metrics when an embedding model response is received, using a
DistributionSummary consistent with the
OpenTelemetry Semantic Conventions for gen_ai.client.token.usage.
Embedding calls have no output tokens, so gen_ai.token.type is always input.
It also records the duration of every embedding operation as gen_ai.client.operation.duration using a
Timer, consistent with the
OpenTelemetry Semantic Conventions for gen_ai.client.operation.duration.
The duration is recorded for both successful and failed calls, with an outcome tag set to
SUCCESS or ERROR, and an error.type tag set to none or to the class name of the
exception. A failed call has no response, so its gen_ai.response.model is unknown.
Every duration carries the same set of tags, as some registries (e.g., Prometheus) require that.
Histogram publishing and bucket boundaries are not configured by this listener.
Users can enable histograms and set bucket boundaries through their MeterRegistry configuration
(e.g., via Spring Boot properties or MeterFilter).
Note: The MicrometerMetricsEmbeddingModelListener
must be instantiated separately (e.g., via Spring Boot auto-configuration or manual instantiation).
-
Constructor Summary
ConstructorsConstructorDescriptionMicrometerMetricsEmbeddingModelListener(io.micrometer.core.instrument.MeterRegistry meterRegistry) Creates a newMicrometerMetricsEmbeddingModelListener. -
Method Summary
Modifier and TypeMethodDescriptionvoidonError(EmbeddingModelErrorContext errorContext) This method is called when an error occurs during interaction with the embedding model.voidonRequest(EmbeddingModelRequestContext requestContext) This method is called before the request is executed against the embedding model.voidonResponse(EmbeddingModelResponseContext responseContext) This method is called after a successful embedding operation completes.
-
Constructor Details
-
MicrometerMetricsEmbeddingModelListener
public MicrometerMetricsEmbeddingModelListener(io.micrometer.core.instrument.MeterRegistry meterRegistry) Creates a newMicrometerMetricsEmbeddingModelListener.- Parameters:
meterRegistry- theMeterRegistryto register metrics with
-
-
Method Details
-
onRequest
Description copied from interface:EmbeddingModelListenerThis method is called before the request is executed against the embedding model.- Specified by:
onRequestin interfaceEmbeddingModelListener- Parameters:
requestContext- The request context. It contains the input and attributes. The attributes can be used to pass data between methods of this listener or between multiple listeners.
-
onResponse
Description copied from interface:EmbeddingModelListenerThis method is called after a successful embedding operation completes.- Specified by:
onResponsein interfaceEmbeddingModelListener- Parameters:
responseContext- The response context. It contains the response, corresponding request and attributes. The attributes can be used to pass data between methods of this listener or between multiple listeners.
-
onError
Description copied from interface:EmbeddingModelListenerThis method is called when an error occurs during interaction with the embedding model.- Specified by:
onErrorin interfaceEmbeddingModelListener- Parameters:
errorContext- The error context. It contains the error, corresponding request and attributes. The attributes can be used to pass data between methods of this listener or between multiple listeners.
-