greentic_telemetry/
context.rs

1/// Tenant-aware telemetry context propagated to spans and exporters.
2#[derive(Clone, Debug, Default, PartialEq, Eq)]
3pub struct TelemetryCtx {
4    pub tenant: String,
5    pub session: Option<String>,
6    pub flow: Option<String>,
7    pub node: Option<String>,
8    pub provider: Option<String>,
9}
10
11impl TelemetryCtx {
12    pub fn new<T: Into<String>>(tenant: T) -> Self {
13        Self {
14            tenant: tenant.into(),
15            ..Self::default()
16        }
17    }
18
19    pub fn with_session(mut self, v: impl Into<String>) -> Self {
20        self.session = Some(v.into());
21        self
22    }
23
24    pub fn with_flow(mut self, v: impl Into<String>) -> Self {
25        self.flow = Some(v.into());
26        self
27    }
28
29    pub fn with_node(mut self, v: impl Into<String>) -> Self {
30        self.node = Some(v.into());
31        self
32    }
33
34    pub fn with_provider(mut self, v: impl Into<String>) -> Self {
35        self.provider = Some(v.into());
36        self
37    }
38
39    pub fn kv(&self) -> [(&'static str, Option<&str>); 5] {
40        [
41            ("gt.tenant", Some(self.tenant.as_str())),
42            ("gt.session", self.session.as_deref()),
43            ("gt.flow", self.flow.as_deref()),
44            ("gt.node", self.node.as_deref()),
45            ("gt.provider", self.provider.as_deref()),
46        ]
47    }
48}