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).
-
Constructor Summary
ConstructorsConstructorDescriptionMicrometerMetricsChatModelListener(io.micrometer.core.instrument.MeterRegistry meterRegistry) Creates a newMicrometerMetricsChatModelListener. -
Method Summary
Modifier and TypeMethodDescriptionvoidonError(ChatModelErrorContext errorContext) voidonRequest(ChatModelRequestContext requestContext) voidonResponse(ChatModelResponseContext responseContext)
-
Constructor Details
-
MicrometerMetricsChatModelListener
public MicrometerMetricsChatModelListener(io.micrometer.core.instrument.MeterRegistry meterRegistry) Creates a newMicrometerMetricsChatModelListener.- Parameters:
meterRegistry- theMeterRegistryto register metrics with
-
-
Method Details
-
onRequest
- Specified by:
onRequestin interfaceChatModelListener
-
onResponse
- Specified by:
onResponsein interfaceChatModelListener
-
onError
- Specified by:
onErrorin interfaceChatModelListener
-