1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! Tracing system for recording session traces.
//!
//! This module provides a comprehensive tracing system for recording
//! LLM calls, environment interactions, and other events during
//! agent execution sessions.
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────┐
//! │ User Code │
//! └────────────────────────┬────────────────────────────────┘
//! │
//! ┌──────────▼──────────┐
//! │ SessionTracer │ ◄── HookManager (callbacks)
//! │ - start_session() │
//! │ - start_timestep()│
//! │ - record_event() │
//! │ - record_message()│
//! └──────────┬──────────┘
//! │
//! ┌──────────▼──────────┐
//! │ TraceStorage │ (trait)
//! └──────────┬──────────┘
//! │
//! ┌──────────▼──────────┐
//! │ LibsqlTraceStorage │ ◄── SQLite / Turso
//! └─────────────────────┘
//! ```
//!
//! # Example
//!
//! ```ignore
//! use synth_ai_core::tracing::{SessionTracer, LibsqlTraceStorage, TracingEvent, LMCAISEvent, BaseEventFields};
//! use std::sync::Arc;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create storage (in-memory for testing)
//! let storage = Arc::new(LibsqlTraceStorage::new_memory().await?);
//!
//! // Create tracer
//! let tracer = SessionTracer::new(storage);
//!
//! // Start session
//! let session_id = tracer.start_session(None, Default::default()).await?;
//!
//! // Record a timestep with an LLM call
//! tracer.start_timestep("step1", Some(1), Default::default()).await?;
//!
//! let event = TracingEvent::Cais(LMCAISEvent {
//! base: BaseEventFields::new("llm-agent"),
//! model_name: "gpt-4".to_string(),
//! provider: Some("openai".to_string()),
//! input_tokens: Some(150),
//! output_tokens: Some(50),
//! cost_usd: Some(0.006),
//! latency_ms: Some(1200),
//! ..Default::default()
//! });
//!
//! tracer.record_event(event).await?;
//! tracer.end_timestep().await?;
//!
//! // End session
//! let trace = tracer.end_session(true).await?;
//! println!("Session complete: {} events", trace.event_history.len());
//!
//! Ok(())
//! }
//! ```
// Re-export main types for convenience
pub use TracingError;
pub use ;
pub use LibsqlTraceStorage;
pub use ;
pub use ;
pub use SessionTracer;
pub use ;