Skip to main content
Metrics plugins for recording telemetry data via hooks. This module contains plugins that hook into the generation pipeline to automatically record metrics when enabled. Currently includes:
  • TokenMetricsPlugin: Records token usage statistics from ModelOutputThunk.usage

Classes

CLASS TokenMetricsPlugin

Records token usage metrics from generation outputs. This plugin hooks into the generation_post_call event to automatically record token usage metrics when the usage field is populated on ModelOutputThunk instances. The plugin reads the standardized usage field (OpenAI-compatible format) and records metrics following OpenTelemetry Gen-AI semantic conventions.
Methods:

FUNC record_token_metrics

record_token_metrics(self, payload: GenerationPostCallPayload, context: dict[str, Any]) -> None
Record token metrics after generation completes. Args:
  • payload: Contains the model_output (ModelOutputThunk) with usage data
  • context: Plugin context (unused)