Skip to main content

lellm_graph/
ids.rs

1//! TraceId / SpanId — 执行追踪标识符。
2//!
3//! 从 lellm-core 迁移到 lellm-graph,作为执行引擎的一部分。
4
5use uuid::Uuid;
6
7/// Trace ID — 唯一标识一次完整的图执行。
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
9pub struct TraceId(pub Uuid);
10
11impl Default for TraceId {
12    fn default() -> Self {
13        Self::new()
14    }
15}
16
17impl TraceId {
18    pub fn new() -> Self {
19        Self(Uuid::new_v4())
20    }
21}
22
23impl std::fmt::Display for TraceId {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        write!(f, "{}", self.0)
26    }
27}
28
29/// Span ID — 标识一次节点执行的唯一 ID。
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
31pub struct SpanId(pub Uuid);
32
33impl Default for SpanId {
34    fn default() -> Self {
35        Self::new()
36    }
37}
38
39impl SpanId {
40    pub fn new() -> Self {
41        Self(Uuid::new_v4())
42    }
43}
44
45impl std::fmt::Display for SpanId {
46    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47        write!(f, "{}", self.0)
48    }
49}