#ai-agent #adk #telemetry #tracing #api-bindings

adk-telemetry

OpenTelemetry integration for Rust Agent Development Kit (ADK-Rust) agent observability

21 releases (7 breaking)

Uses new Rust 2024

new 0.8.1 May 13, 2026
0.7.0 Apr 26, 2026
0.5.0 Mar 29, 2026
0.1.8 Dec 28, 2025
0.1.1 Nov 30, 2025

#192 in Debugging

Download history 72/week @ 2026-01-22 63/week @ 2026-01-29 23/week @ 2026-02-05 78/week @ 2026-02-12 85/week @ 2026-02-19 74/week @ 2026-02-26 195/week @ 2026-03-05 506/week @ 2026-03-12 490/week @ 2026-03-19 429/week @ 2026-03-26 396/week @ 2026-04-02 352/week @ 2026-04-09 416/week @ 2026-04-16 746/week @ 2026-04-23 551/week @ 2026-04-30 506/week @ 2026-05-07

2,280 downloads per month
Used in 14 crates (6 directly)

Apache-2.0

37KB
460 lines

adk-telemetry

OpenTelemetry integration for Rust Agent Development Kit (ADK-Rust) agent observability.

Crates.io Documentation License

Overview

adk-telemetry provides observability infrastructure for the Rust Agent Development Kit (ADK-Rust), built on OpenTelemetry 0.31 and tracing-opentelemetry 0.32:

  • Tracing - Distributed tracing with OpenTelemetry 0.31
  • Logging - Structured logging with tracing-subscriber
  • Metrics - Performance metrics export via OTLP (tonic 0.12 / gRPC)
  • Span Context - Propagation across agent boundaries

Installation

[dependencies]
adk-telemetry = "0.8.1"

Or use the meta-crate:

[dependencies]
adk-rust = { version = "0.8.1", features = ["telemetry"] }

Quick Start

use adk_telemetry::init_telemetry;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize with service name
    init_telemetry("my-agent")?;

    // Your agent code here...
    Ok(())
}

Configuration

Set the RUST_LOG environment variable:

# Debug logging for ADK
RUST_LOG=adk=debug cargo run

# Trace level for specific modules
RUST_LOG=adk_agent=trace,adk_model=debug cargo run

OpenTelemetry Export

Configure OTLP export for distributed tracing:

use adk_telemetry::init_with_otlp;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    init_with_otlp("my-agent", "http://localhost:4317")?;
    
    // Your agent code here...
    Ok(())
}

Available Functions

Function Description
init_telemetry(service_name) Basic console logging
init_with_otlp(service_name, endpoint) OTLP export to collectors
init_with_adk_exporter(service_name) ADK-style span exporter
shutdown_telemetry() Flush and shutdown

Span Helpers

Pre-configured spans for instrumenting ADK operations:

Function Description
agent_run_span(name, invocation_id) Agent execution span
model_call_span(model_name) Model API call span
llm_generate_span(provider, model, stream) LLM generation span with gen_ai.usage.* fields
tool_execute_span(tool_name) Tool execution span
callback_span(callback_type) Callback execution span
record_llm_usage(&usage) Record token counts on the current span

Token Usage Tracking

llm_generate_span pre-declares OpenTelemetry GenAI semantic convention fields. After receiving a response, call record_llm_usage to populate them:

use adk_telemetry::{llm_generate_span, record_llm_usage, LlmUsage};

let span = llm_generate_span("openai", "gpt-5-mini", true);
let _enter = span.enter();

// After receiving the LLM response:
record_llm_usage(&LlmUsage {
    input_tokens: 100,
    output_tokens: 50,
    total_tokens: 150,
    cache_read_tokens: Some(80),
    ..Default::default()
});

Recorded fields: gen_ai.usage.input_tokens, output_tokens, total_tokens, cache_read_tokens, cache_creation_tokens, thinking_tokens, audio_input_tokens, audio_output_tokens.

Re-exports

Convenience re-exports from tracing:

use adk_telemetry::{info, debug, warn, error, trace, instrument, Span};

Features

  • Zero-config defaults with sensible logging
  • OpenTelemetry 0.31 compatible span export
  • OTLP export via tonic 0.12 (gRPC), aligned with adk-server's hyper 1.x / http 1.x stack
  • Automatic context propagation
  • JSON or pretty-print log formats

OpenTelemetry Dependency Versions

Crate Version
opentelemetry 0.31
opentelemetry_sdk 0.31
opentelemetry-otlp 0.31
tracing-opentelemetry 0.32

License

Apache-2.0

Part of ADK-Rust

This crate is part of the ADK-Rust framework for building AI agents in Rust.

Dependencies

~8–16MB
~204K SLoC