use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
#[cfg(feature = "telemetry")]
mod otlp;
#[cfg(not(feature = "telemetry"))]
pub use disabled::{emit, init, record_usage, shutdown};
#[cfg(all(feature = "telemetry", test))]
pub use otlp::meter;
#[cfg(feature = "telemetry")]
pub use otlp::{emit, init, record_usage, shutdown};
const DEFAULT_SERVICE_NAME: &str = "blackship";
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct TelemetryConfig {
pub endpoint: Option<String>,
#[serde(default = "default_service_name")]
pub service_name: String,
pub timeout_secs: Option<u64>,
pub metrics_interval_secs: Option<u64>,
#[serde(default)]
pub headers: BTreeMap<String, String>,
}
fn default_service_name() -> String {
DEFAULT_SERVICE_NAME.to_string()
}
impl Default for TelemetryConfig {
fn default() -> Self {
Self {
endpoint: None,
service_name: default_service_name(),
timeout_secs: None,
metrics_interval_secs: None,
headers: BTreeMap::new(),
}
}
}
#[cfg(not(feature = "telemetry"))]
mod disabled {
#![allow(clippy::missing_const_for_fn)]
use super::TelemetryConfig;
use crate::audit::AuditRecord;
pub fn init(_config: Option<&TelemetryConfig>) {}
pub fn emit(_record: &AuditRecord) {}
pub fn record_usage(_jail: &str, _sample: &std::collections::HashMap<String, u64>) {}
pub fn shutdown() {}
}
#[cfg(test)]
mod tests;