MetricsRecording

org.llm4s.llmconnect.provider.MetricsRecording

Helper trait for recording metrics consistently across all provider clients.

Extracts the common pattern of timing requests, observing outcomes, recording tokens, and calculating costs.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

protected def metrics: MetricsCollector

Concrete methods

protected def withMetrics[A](provider: String, model: String)(f: => Result[A])(extractUsage: A => Option[TokenUsage], estimateCost: TokenUsage => Option[Double]): Result[A]

Execute a block of code while recording metrics for the operation.

Execute a block of code while recording metrics for the operation.

Type parameters

A

Result type

Value parameters

estimateCost

Optional function to estimate cost from usage

extractUsage

Function to extract usage from successful result

f

The operation to execute

model

Model name

provider

Provider name (e.g., "openai", "anthropic")

Attributes

Returns

The result of the operation