org.llm4s.metrics
Members list
Type members
Classlikes
Stable categorization of LLM errors for metrics.
Stable categorization of LLM errors for metrics.
These are stable labels safe for use in metrics dimensions. Do not use exception class names as they may change.
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object Authenticationobject Networkobject RateLimitobject Timeoutobject Unknownobject ValidationShow all
Minimal algebra for collecting metrics about LLM operations.
Minimal algebra for collecting metrics about LLM operations.
Implementations should be safe: failures must not propagate to callers. All methods should catch and log errors internally without throwing.
Example usage:
val startNanos = System.nanoTime()
client.complete(conversation) match {
case Right(completion) =>
val duration = FiniteDuration(System.nanoTime() - startNanos, NANOSECONDS)
metrics.observeRequest(provider, model, Outcome.Success, duration)
completion.usage.foreach { u =>
metrics.addTokens(provider, model, u.promptTokens, u.completionTokens)
}
case Left(error) =>
val duration = FiniteDuration(System.nanoTime() - startNanos, NANOSECONDS)
val errorKind = ErrorKind.fromLLMError(error)
metrics.observeRequest(provider, model, Outcome.Error(errorKind), duration)
}
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class PrometheusMetrics
Attributes
- Companion
- trait
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
MetricsCollector.type
HTTP endpoint for exposing Prometheus metrics.
HTTP endpoint for exposing Prometheus metrics.
Wraps the Prometheus HTTPServer and provides lifecycle management. Use this to expose metrics at /metrics for Prometheus scraping.
Example:
val registry = new PrometheusRegistry()
val endpointResult = PrometheusEndpoint.start(9090, registry)
endpointResult match {
case Right(endpoint) =>
println(s"Metrics at: ${endpoint.url}")
// ... application runs ...
endpoint.stop()
case Left(error) =>
println(s"Failed to start: ${error.message}")
}
Value parameters
- port
-
Port the server is listening on
- server
-
Underlying HTTP server
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
PrometheusEndpoint.type
Prometheus implementation of MetricsCollector.
Prometheus implementation of MetricsCollector.
Tracks request volumes, token usage, errors, and latency across different providers and models using Prometheus metrics.
All operations are wrapped in try-catch to ensure metric failures never propagate to callers. This implementation is thread-safe.
Example usage:
val registry = new PrometheusRegistry()
val metrics = new PrometheusMetrics(registry)
// Use with endpoint
PrometheusEndpoint.start(9090, registry).foreach { endpoint =>
// ... use metrics ...
endpoint.stop()
}
Value parameters
- registry
-
Prometheus collector registry
Attributes
- Companion
- object
- Supertypes
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
PrometheusMetrics.type