Skip to main content

torrust_tracker_deployer_lib/presentation/cli/views/sinks/
telemetry.rs

1//! Telemetry output sink implementation
2
3use super::super::{OutputMessage, OutputSink};
4
5pub struct TelemetrySink {
6    endpoint: String,
7}
8
9impl TelemetrySink {
10    /// Create a new telemetry sink
11    ///
12    /// # Examples
13    ///
14    /// ```rust,ignore
15    /// use torrust_tracker_deployer_lib::presentation::cli::views::TelemetrySink;
16    ///
17    /// let sink = TelemetrySink::new("https://telemetry.example.com".to_string());
18    /// ```
19    #[must_use]
20    pub fn new(endpoint: String) -> Self {
21        Self { endpoint }
22    }
23
24    /// Get the endpoint URL
25    #[cfg(test)]
26    #[must_use]
27    pub fn endpoint(&self) -> &str {
28        &self.endpoint
29    }
30}
31
32impl OutputSink for TelemetrySink {
33    fn write_message(&mut self, message: &dyn OutputMessage, formatted: &str) {
34        // In real implementation, send to telemetry service
35        tracing::debug!(
36            endpoint = %self.endpoint,
37            message_type = message.type_name(),
38            channel = ?message.channel(),
39            content = formatted,
40            "Telemetry event"
41        );
42    }
43}
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn telemetry_sink_should_create_with_endpoint() {
51        let sink = TelemetrySink::new("https://example.com".to_string());
52        assert_eq!(sink.endpoint(), "https://example.com");
53    }
54}