1#[derive(Debug, Clone)]
2pub struct TelemetryLabels {
3 pub tenant: String,
4 pub platform: Option<String>,
5 pub chat_id: Option<String>,
6 pub msg_id: Option<String>,
7 pub extra: Vec<(String, String)>,
8}
9
10impl TelemetryLabels {
11 pub fn new(tenant: impl Into<String>) -> Self {
12 Self {
13 tenant: tenant.into(),
14 platform: None,
15 chat_id: None,
16 msg_id: None,
17 extra: Vec::new(),
18 }
19 }
20
21 pub fn tags(&self) -> Vec<(String, String)> {
22 let mut tags = Vec::with_capacity(4 + self.extra.len());
23 tags.push(("tenant".into(), self.tenant.clone()));
24 if let Some(p) = &self.platform {
25 tags.push(("platform".into(), p.clone()));
26 }
27 if let Some(chat) = &self.chat_id {
28 tags.push(("chat_id".into(), chat.clone()));
29 }
30 if let Some(msg) = &self.msg_id {
31 tags.push(("msg_id".into(), msg.clone()));
32 }
33 for (key, value) in &self.extra {
34 tags.push((key.clone(), value.clone()));
35 }
36 tags
37 }
38}
39
40#[derive(Debug, Clone)]
41pub struct MessageContext {
42 pub labels: TelemetryLabels,
43}
44
45impl MessageContext {
46 pub fn new(labels: TelemetryLabels) -> Self {
47 Self { labels }
48 }
49}