use crate::telemetry::{ContextTags, Properties};
#[derive(Clone)]
pub struct TelemetryContext {
pub(crate) i_key: String,
pub(crate) tags: ContextTags,
pub(crate) properties: Properties,
}
impl TelemetryContext {
pub fn with_i_key(i_key: String) -> Self {
Self::new(i_key, ContextTags::default(), Properties::default())
}
pub fn new(i_key: String, tags: ContextTags, properties: Properties) -> Self {
Self {
i_key,
tags,
properties,
}
}
pub fn properties_mut(&mut self) -> &mut Properties {
&mut self.properties
}
pub fn properties(&self) -> &Properties {
&self.properties
}
pub fn tags_mut(&mut self) -> &mut ContextTags {
&mut self.tags
}
pub fn tags(&self) -> &ContextTags {
&self.tags
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_updates_common_properties() {
let mut context = TelemetryContext::with_i_key("intrumentation".to_string());
context.properties_mut().insert("Resource Group".into(), "my-rg".into());
assert_eq!(context.properties().len(), 1);
assert_eq!(context.properties().get("Resource Group"), Some(&"my-rg".to_string()));
}
}