rust_observer 0.2.2

Express telemetry rust SDK
Documentation
use serde::Deserialize;
use std::collections::HashMap;
use std::fs;
use toml;

#[derive(Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
pub enum ExporterType {
    Stdout,
    // Add other exporter types here as needed
}

#[derive(Deserialize)]
pub struct ObservabilityConfig {
    pub project: ProjectConfig,
    pub logging: LoggingConfig,
    pub tracing: TracingConfig,
    pub metrics: MetricsConfig,
}

#[derive(Deserialize)]
pub struct ProjectConfig {
    pub name: String,
    pub app_name: String,
    pub service_name: String,
}

#[derive(Deserialize)]
pub struct LoggingConfig {
    pub enabled: bool,
    pub level: String,
    pub exporter: ExporterConfig,
}

#[derive(Deserialize)]
pub struct TracingConfig {
    pub enabled: bool,
    pub exporter: ExporterConfig,
}

#[derive(Deserialize)]
pub struct MetricsConfig {
    pub enabled: bool,
    pub interval_secs: u64,
    pub exporter: ExporterConfig,
    pub http: MetricTypeConfig,
    pub grpc: MetricTypeConfig,
    pub websocket: MetricTypeConfig,
    pub system: MetricTypeConfig,
    pub process: MetricTypeConfig,
}

#[derive(Deserialize)]
pub struct ExporterConfig {
    pub r#type: ExporterType,
    #[serde(flatten)]
    pub properties: HashMap<String, toml::Value>,
}

#[derive(Deserialize)]
pub struct MetricTypeConfig {
    pub enabled: bool,
}

impl ObservabilityConfig {
    pub fn from_file(path: &str) -> Result<Self, Box<dyn std::error::Error>> {
        let config_str = fs::read_to_string(path)?;
        let config: ObservabilityConfig = toml::from_str(&config_str)?;
        Ok(config)
    }
}