Skip to main content

o_sfu_telemetry/
config.rs

1use std::time::Duration;
2
3pub const DEFAULT_TELEMETRY_SERVICE_NAME: &str = "o-sfu";
4pub const DEFAULT_TELEMETRY_DEPLOYMENT_ENVIRONMENT: &str = "local";
5pub const DEFAULT_MEDIA_QUALITY_INTERVAL: Duration = Duration::from_secs(5);
6
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct TelemetryConfig {
9    pub log_format: TelemetryLogFormat,
10    pub resource: TelemetryResource,
11    pub trace_export: TraceExportConfig,
12    pub media_quality_interval: Option<Duration>,
13}
14
15impl Default for TelemetryConfig {
16    fn default() -> Self {
17        Self {
18            log_format: TelemetryLogFormat::default(),
19            resource: TelemetryResource::default(),
20            trace_export: TraceExportConfig::default(),
21            media_quality_interval: Some(DEFAULT_MEDIA_QUALITY_INTERVAL),
22        }
23    }
24}
25
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
27pub enum TelemetryLogFormat {
28    #[default]
29    Compact,
30    Json,
31}
32
33impl TelemetryLogFormat {
34    #[must_use]
35    pub const fn as_str(self) -> &'static str {
36        match self {
37            Self::Compact => "compact",
38            Self::Json => "json",
39        }
40    }
41}
42
43#[derive(Debug, Clone, PartialEq, Eq)]
44pub struct TelemetryResource {
45    pub service_name: String,
46    pub deployment_environment: String,
47    pub service_instance_id: Option<String>,
48}
49
50impl TelemetryResource {
51    #[must_use]
52    pub fn resolved_instance_id(&self, process_id: u32) -> String {
53        self.service_instance_id
54            .clone()
55            .unwrap_or_else(|| format!("pid-{process_id}"))
56    }
57}
58
59impl Default for TelemetryResource {
60    fn default() -> Self {
61        Self {
62            service_name: DEFAULT_TELEMETRY_SERVICE_NAME.to_owned(),
63            deployment_environment: DEFAULT_TELEMETRY_DEPLOYMENT_ENVIRONMENT.to_owned(),
64            service_instance_id: None,
65        }
66    }
67}
68
69#[derive(Debug, Clone, PartialEq, Eq, Default)]
70pub struct TraceExportConfig {
71    pub otlp_endpoint: Option<String>,
72}