コンテンツにスキップ

エージェントの可観測性

ADKでサポートPython v0.1.0Go v0.1.0Kotlin v0.1.0

エージェントの可観測性は、外部テレメトリと構造化ログを分析することで、 推論トレース、ツール呼び出し、潜在モデル出力 (latent model outputs) を含む システムの内部状態を測定できるようにします。エージェントを構築する際、 実行中の挙動をデバッグ・診断するためにこれらの機能が必要になる場合があります。 一定以上の複雑さを持つエージェントでは、基本的な入出力モニタリングだけでは 通常不十分です。

Agent Development Kit (ADK) は、エージェントの監視とデバッグのために、 ロギングメトリクストレース を組み込みで提供します。ただし、監視と 分析には、より高度な 可観測性 ADK 連携 を検討する必要がある場合があります。

クイックスタート: Kotlinで可観測性を有効にする

Kotlinでは、トレース用にOpenTelemetryを構成し、詳細なコンソール出力にLoggingPluginを使用することで、包括的な可観測性を有効にできます。

// 1. Configure OpenTelemetry (Traces)
// ADK Kotlin uses GlobalOpenTelemetry to resolve its tracer on the JVM.
val spanExporter = OtlpGrpcSpanExporter.builder().setEndpoint("http://localhost:4317").build()

val resource =
    Resource.getDefault()
        .merge(
            Resource.create(
                Attributes.of(AttributeKey.stringKey("service.name"), "my-kotlin-agent"),
            ),
        )

val tracerProvider =
    SdkTracerProvider.builder()
        .addSpanProcessor(BatchSpanProcessor.builder(spanExporter).build())
        .setResource(resource)
        .build()

OpenTelemetrySdk.builder().setTracerProvider(tracerProvider).buildAndRegisterGlobal()

// 2. Optional: Configure ADK Telemetry behavior
// Enable capturing full message content in traces (use with caution in production)
TelemetryConfig.captureMessageContent = true

// 3. Initialize Agent and Runner with LoggingPlugin for console output
val agent = LlmAgent(name = "my_agent", model = Gemini(name = "gemini-flash-latest"))

val runner =
    InMemoryRunner(agent = agent, pluginManager = PluginManager(listOf(LoggingPlugin())))

// The runner will now automatically emit traces via GlobalOpenTelemetry
// and log activity to the console via the LoggingPlugin.
runner.run(
    userId = "user123",
    sessionId = "session456",
    newMessage = Content.fromText(Role.USER, "Hello!"),
)

可観測性向け ADK 連携

ADK 向けの事前構築済み可観測性ライブラリの一覧は ツールと統合 を参照してください。