use opentelemetry::KeyValue; use opentelemetry_sdk::Resource; use crate::config::TelemetryConfig; pub fn build(config: &TelemetryConfig) -> Resource { let mut attributes = Vec::with_capacity(config.attributes.len() + 4); attributes.push(KeyValue::new("service.name", config.service_name.clone())); if let Some(version) = &config.service_version { attributes.push(KeyValue::new("service.version", version.clone())); } if let Some(environment) = &config.environment { attributes.push(KeyValue::new("deployment.environment", environment.clone())); } for (key, value) in &config.attributes { if key == "service.name" { continue; } attributes.push(KeyValue::new(key.clone(), value.clone())); } if let Some(host) = { std::env::var("HOSTNAME") .ok() .filter(|value| !value.is_empty()) .or_else(|| { std::env::var("COMPUTERNAME") .ok() .filter(|value| !value.is_empty()) }) } { attributes.push(KeyValue::new("host.name", host)); } Resource::builder_empty() .with_attributes(attributes) .build() }