Class MicrometerMetricsChatModelListener

java.lang.Object
dev.langchain4j.micrometer.metrics.listeners.MicrometerMetricsChatModelListener
All Implemented Interfaces:
ChatModelListener

@Experimental public class MicrometerMetricsChatModelListener extends Object implements ChatModelListener
A ChatModelListener that uses a Micrometer MeterRegistry to collect metrics about chat model interactions following OpenTelemetry Semantic Conventions for Generative AI.

This listener records token usage metrics (input and output tokens) when a chat model response is received, using a DistributionSummary consistent with the OpenTelemetry Semantic Conventions for gen_ai.client.token.usage.

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 MicrometerMetricsChatModelListener must be instantiated separately (e.g., via Spring Boot auto-configuration or manual instantiation).