オブザーバビリティ
オブザーバビリティ
Section titled “オブザーバビリティ”両ランタイムは本番デプロイメント向けのオブザーバビリティ機能を提供します。
Rust:構造化ログ
Section titled “Rust:構造化ログ”ai-lib-rust は tracing エコシステムを使用します:
use tracing_subscriber;
// ログを有効化tracing_subscriber::init();
// すべての AI-Lib 操作が構造化ログイベントを発行let client = AiClient::new("openai/gpt-4o").await?;ログレベル:
INFO— リクエスト/レスポンスサマリーDEBUG— プロトコル読み込み、パイプラインステージTRACE— 個々のフレーム、JSONPath マッチ
Rust:呼び出し統計
Section titled “Rust:呼び出し統計”すべてのリクエストが使用統計を返します:
let (response, stats) = client.chat() .user("Hello") .execute_with_stats() .await?;
println!("Model: {}", stats.model);println!("Provider: {}", stats.provider);println!("Prompt tokens: {}", stats.prompt_tokens);println!("Completion tokens: {}", stats.completion_tokens);println!("Total tokens: {}", stats.total_tokens);println!("Latency: {}ms", stats.latency_ms);Python:メトリクス(Prometheus)
Section titled “Python:メトリクス(Prometheus)”from ai_lib_python.telemetry import MetricsCollector
metrics = MetricsCollector()
client = await AiClient.builder() \ .model("openai/gpt-4o") \ .metrics(metrics) \ .build()
# いくつかのリクエストの後...prometheus_text = metrics.export_prometheus()追跡されるメトリクス:
ai_lib_requests_total— モデル/プロバイダー別リクエスト数ai_lib_request_duration_seconds— レイテンシヒストグラムai_lib_tokens_total— タイプ別トークン使用量ai_lib_errors_total— タイプ別エラー数
Python:分散トレーシング(OpenTelemetry)
Section titled “Python:分散トレーシング(OpenTelemetry)”from ai_lib_python.telemetry import Tracer
tracer = Tracer( service_name="my-app", endpoint="http://jaeger:4317",)
client = await AiClient.builder() \ .model("openai/gpt-4o") \ .tracer(tracer) \ .build()トレースには以下のスパンが含まれます:
- プロトコル読み込み
- リクエストコンパイル
- HTTP トランスポート
- パイプライン処理
- イベントマッピング
Python:ヘルス監視
Section titled “Python:ヘルス監視”from ai_lib_python.telemetry import HealthChecker
health = HealthChecker()status = await health.check()
print(f"Healthy: {status.is_healthy}")print(f"Details: {status.details}")Python:ユーザーフィードバック
Section titled “Python:ユーザーフィードバック”AI レスポンスへのフィードバックを収集します:
from ai_lib_python.telemetry import FeedbackCollector
feedback = FeedbackCollector()
# レスポンスを取得した後feedback.record( request_id=stats.request_id, rating=5, comment="Helpful response",)耐障害性のオブザーバビリティ
Section titled “耐障害性のオブザーバビリティ”サーキットブレーカーとレートリミッターの状態を監視します:
// Rustlet state = client.circuit_state(); // Closed, Open, HalfOpenlet inflight = client.current_inflight();# Pythonsignals = client.signals_snapshot()print(f"Circuit: {signals.circuit_state}")print(f"Inflight: {signals.current_inflight}")