telemetry_kit/lib.rs
1//! # telemetry-kit
2//!
3//! Privacy-first, batteries-included telemetry for Rust applications.
4//!
5//! ## Quick Start
6//!
7//! ```rust,no_run
8//! use telemetry_kit::prelude::*;
9//!
10//! #[tokio::main]
11//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
12//! // Initialize telemetry with sensible defaults
13//! let _guard = telemetry_kit::init()
14//! .service_name("my-app")
15//! .init()?;
16//!
17//! // Your application code here
18//!
19//! Ok(())
20//! }
21//! ```
22//!
23//! ## Features
24//!
25//! - **Zero-config**: Sensible defaults, minimal boilerplate
26//! - **Privacy-first**: Built-in anonymization and GDPR compliance
27//! - **CLI-optimized**: Perfect for command-line applications
28//! - **Self-hostable**: Simple collection server included
29//!
30//! ## Current Status
31//!
32//! **⚠️ This is version 0.0.1 - a placeholder release for crate reservation.**
33//!
34//! The actual implementation is under development. See the
35//! [GitHub repository](https://github.com/ibrahimcesar/telemetry-kit) for progress.
36//!
37//! First usable release (v0.1.0) is planned for Q1 2025.
38
39#![warn(missing_docs)]
40#![warn(rustdoc::missing_crate_level_docs)]
41
42/// Prelude module for convenient imports
43pub mod prelude {
44 //! Commonly used imports for telemetry-kit
45 //!
46 //! ```rust
47 //! use telemetry_kit::prelude::*;
48 //! ```
49}
50
51/// Initialize telemetry for your application
52///
53/// # Example
54///
55/// ```rust,no_run
56/// use telemetry_kit::prelude::*;
57///
58/// let _guard = telemetry_kit::init()
59/// .service_name("my-app")
60/// .init();
61/// ```
62pub fn init() -> TelemetryBuilder {
63 TelemetryBuilder::new()
64}
65
66/// Builder for configuring telemetry
67pub struct TelemetryBuilder {
68 // Configuration will be added in future versions
69}
70
71impl TelemetryBuilder {
72 /// Create a new telemetry builder
73 pub fn new() -> Self {
74 Self {}
75 }
76
77 /// Set the service name
78 pub fn service_name(self, _name: impl Into<String>) -> Self {
79 self
80 }
81
82 /// Initialize telemetry (placeholder)
83 ///
84 /// # Errors
85 ///
86 /// Currently returns Ok(()), but will return errors for invalid configuration
87 /// in future versions.
88 pub fn init(self) -> Result<TelemetryGuard, TelemetryError> {
89 Ok(TelemetryGuard {})
90 }
91}
92
93impl Default for TelemetryBuilder {
94 fn default() -> Self {
95 Self::new()
96 }
97}
98
99/// Guard that ensures telemetry is properly shut down
100///
101/// Dropping this guard will flush any pending telemetry data.
102pub struct TelemetryGuard {
103 // Will contain shutdown logic in future versions
104}
105
106/// Errors that can occur during telemetry operations
107#[derive(Debug)]
108pub enum TelemetryError {
109 /// Placeholder error variant
110 NotImplemented,
111}
112
113impl std::fmt::Display for TelemetryError {
114 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
115 match self {
116 TelemetryError::NotImplemented => {
117 write!(f, "This feature is not yet implemented in version 0.0.1")
118 }
119 }
120 }
121}
122
123impl std::error::Error for TelemetryError {}
124
125#[cfg(test)]
126mod tests {
127 use super::*;
128
129 #[test]
130 fn test_basic_initialization() {
131 let _guard = init().service_name("test").init();
132 assert!(_guard.is_ok());
133 }
134}