o_sfu_telemetry/
config.rs1use 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>,
16}
17
18impl Default for TelemetryConfig {
19 fn default() -> Self {
20 Self {
21 log_format: TelemetryLogFormat::default(),
22 resource: TelemetryResource::default(),
23 trace_export: TraceExportConfig::default(),
24 media_quality_interval: Some(DEFAULT_MEDIA_QUALITY_INTERVAL),
25 }
26 }
27}
28
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
30pub enum TelemetryLogFormat {
31 #[default]
32 Compact,
33 Json,
34}
35
36impl TelemetryLogFormat {
37 #[must_use]
38 pub const fn as_str(self) -> &'static str {
39 match self {
40 Self::Compact => "compact",
41 Self::Json => "json",
42 }
43 }
44}
45
46#[derive(Debug, Clone, PartialEq, Eq)]
47pub struct TelemetryResource {
48 pub service_name: String,
49 pub deployment_environment: String,
50 pub service_instance_id: Option<String>,
51}
52
53impl TelemetryResource {
54 #[must_use]
55 pub fn resolved_instance_id(&self, process_id: u32) -> String {
56 self.service_instance_id
57 .clone()
58 .unwrap_or_else(|| format!("pid-{process_id}"))
59 }
60}
61
62impl Default for TelemetryResource {
63 fn default() -> Self {
64 Self {
65 service_name: DEFAULT_TELEMETRY_SERVICE_NAME.to_owned(),
66 deployment_environment: DEFAULT_TELEMETRY_DEPLOYMENT_ENVIRONMENT.to_owned(),
67 service_instance_id: None,
68 }
69 }
70}
71
72#[derive(Debug, Clone, PartialEq, Eq, Default)]
73pub struct TraceExportConfig {
74 pub otlp_endpoint: Option<String>,
75}