adk_telemetry/lib.rs
1//! # ADK Telemetry
2//!
3//! Production-grade observability for ADK using structured logging and distributed tracing.
4//!
5//! ## Features
6//! - Structured logging with `tracing`
7//! - OpenTelemetry integration for distributed tracing
8//! - OTLP export for observability backends (Jaeger, Datadog, etc.)
9//! - Automatic context propagation
10//! - OTel GenAI Semantic Conventions (v1.41.0) via `genai-semconv` feature (enabled by default)
11//!
12//! ## Usage
13//!
14//! ```rust
15//! use adk_telemetry::{init_telemetry, info, instrument};
16//!
17//! fn main() -> Result<(), adk_telemetry::TelemetryError> {
18//! // Initialize telemetry in your main
19//! init_telemetry("my-service")?;
20//!
21//! // Use logging macros
22//! #[instrument]
23//! async fn my_function() {
24//! info!("Function called");
25//! }
26//! Ok(())
27//! }
28//! ```
29
30pub mod init;
31pub mod span_exporter;
32pub mod spans;
33
34// Direct span export to a local SQLite file (feature-gated)
35#[cfg(feature = "sqlite")]
36pub mod sqlite;
37
38// Telemetry to Google Cloud (feature-gated)
39#[cfg(feature = "gcp")]
40pub mod gcp;
41
42// GenAI Semantic Conventions module (feature-gated)
43#[cfg(feature = "genai-semconv")]
44pub mod semconv;
45
46// Content event configuration (feature-gated)
47#[cfg(feature = "genai-semconv")]
48pub mod config;
49
50// Content event emitter (feature-gated)
51#[cfg(feature = "genai-semconv")]
52pub mod events;
53
54// Re-export tracing macros for convenience
55pub use tracing::{Span, debug, error, info, instrument, trace, warn};
56
57// Re-export span helpers
58pub use spans::*;
59
60// Re-export span exporter (ADK-Go style)
61pub use span_exporter::*;
62
63// Re-export init functions and error type
64#[cfg(feature = "gcp")]
65pub use gcp::{
66 CloudLoggingJsonFormat, GCP_OTLP_ENDPOINT, GcpHeaderSupplier, gcp_resource_attributes,
67 init_json_logging, init_with_gcp,
68};
69#[cfg(feature = "sqlite")]
70pub use init::init_with_sqlite;
71pub use init::{TelemetryError, init_telemetry, init_with_adk_exporter, shutdown_telemetry};
72#[cfg(feature = "otlp")]
73pub use init::{build_otlp_layer, init_with_otlp};
74#[cfg(feature = "sqlite")]
75pub use sqlite::{SessionSummary, SpanRow, SqliteSpanExporter, SqliteTraceReader};
76
77// Re-export metrics
78#[cfg(feature = "otlp")]
79pub use opentelemetry::global;
80#[cfg(feature = "otlp")]
81pub use opentelemetry::metrics::{Meter, MeterProvider};
82
83// Re-export key semconv types for convenience
84#[cfg(feature = "genai-semconv")]
85pub use semconv::{GenAiOperation, GenAiProvider, GenAiResponseRecorder, GenAiSpanBuilder};