langsmith_rust/observability/
observer.rs

1use serde_json::Value;
2
3/// Observer trait for observing node execution events
4pub trait Observer: Send + Sync {
5    /// Called when a node starts execution
6    fn on_node_start(&self, node_name: &str, inputs: &Value);
7    
8    /// Called when a node completes successfully
9    fn on_node_end(&self, node_name: &str, outputs: &Value);
10    
11    /// Called when a node encounters an error
12    fn on_node_error(&self, node_name: &str, error: &str);
13}
14
15/// LangSmith observer that traces to LangSmith
16pub struct LangSmithObserver {
17    // Can hold tracer or client
18}
19
20impl LangSmithObserver {
21    pub fn new() -> Self {
22        Self {}
23    }
24}
25
26impl Observer for LangSmithObserver {
27    fn on_node_start(&self, node_name: &str, _inputs: &Value) {
28        // Implementation would create a tracer and post the run
29        // This is a simplified version - actual implementation would use Tracer
30        eprintln!("LangSmithObserver: Node '{}' started", node_name);
31    }
32
33    fn on_node_end(&self, node_name: &str, _outputs: &Value) {
34        // Implementation would patch the run with outputs
35        eprintln!("LangSmithObserver: Node '{}' completed", node_name);
36    }
37
38    fn on_node_error(&self, node_name: &str, error: &str) {
39        // Implementation would patch the run with error
40        eprintln!("LangSmithObserver: Node '{}' error: {}", node_name, error);
41    }
42}
43
44impl Default for LangSmithObserver {
45    fn default() -> Self {
46        Self::new()
47    }
48}
49