Skip to main content

langgraph_tracing/
event_bus.rs

1use crate::types::*;
2use serde::{Deserialize, Serialize};
3use tokio::sync::broadcast;
4
5/// Events emitted by the tracing system for real-time updates
6#[derive(Debug, Clone, Serialize, Deserialize)]
7#[serde(tag = "type", rename_all = "snake_case")]
8pub enum TracingEvent {
9    TraceCreated { trace: TraceSummary },
10    TraceUpdated { trace: TraceSummary },
11    SpanCreated { span: Span },
12    SpanUpdated { span: Span },
13}
14
15/// Event bus for real-time WebSocket push
16#[derive(Clone)]
17pub struct EventBus {
18    sender: broadcast::Sender<TracingEvent>,
19}
20
21impl EventBus {
22    pub fn new() -> Self {
23        let (sender, _) = broadcast::channel(256);
24        Self { sender }
25    }
26
27    pub fn publish(&self, event: TracingEvent) {
28        // Ignore send errors (no receivers)
29        let _ = self.sender.send(event);
30    }
31
32    pub fn subscribe(&self) -> broadcast::Receiver<TracingEvent> {
33        self.sender.subscribe()
34    }
35}
36
37impl Default for EventBus {
38    fn default() -> Self {
39        Self::new()
40    }
41}