veecle_telemetry/collector/mod.rs
1//! Telemetry data collection and export infrastructure.
2//!
3//! This module provides the core infrastructure for collecting telemetry data and exporting it
4//! to various backends.
5//! It includes the global collector singleton, export trait, and various
6//! built-in exporters.
7//!
8//! # Global Collector
9//!
10//! The collector uses a global singleton pattern to ensure telemetry data is collected
11//! consistently across the entire application.
12//! The collector must be initialized once
13//! using [`build`] before any telemetry data can be collected.
14//!
15//! # Export Trait
16//!
17//! The [`Export`] trait defines the interface for exporting telemetry data.
18//! Custom exporters can be implemented by providing an implementation of this trait.
19//!
20//! # Built-in Exporters
21//!
22//! - [`ConsoleJsonExporter`] - Exports telemetry data as JSON to stdout
23//! - [`TestExporter`] - Collects telemetry data in memory for testing purposes
24
25mod collector;
26mod global;
27
28mod builder;
29#[cfg(feature = "std")]
30mod json_exporter;
31#[cfg(feature = "std")]
32mod pretty_exporter;
33#[cfg(feature = "std")]
34mod test_exporter;
35
36use core::fmt::Debug;
37
38pub use builder::{Builder, build};
39#[cfg(feature = "std")]
40pub use json_exporter::ConsoleJsonExporter;
41#[cfg(feature = "std")]
42pub use pretty_exporter::ConsolePrettyExporter;
43#[cfg(feature = "std")]
44#[doc(hidden)]
45pub use test_exporter::TestExporter;
46
47pub use self::collector::Collector;
48pub use self::global::get_collector;
49
50pub use crate::protocol::base::ProcessId;
51use crate::protocol::transient::InstanceMessage;
52
53/// Trait for exporting telemetry data to external systems.
54///
55/// Implementers of this trait define how telemetry data should be exported,
56/// whether to files, network endpoints, or other destinations.
57///
58/// # Examples
59///
60/// ```rust
61/// use veecle_telemetry::collector::Export;
62/// use veecle_telemetry::protocol::transient::InstanceMessage;
63///
64/// #[derive(Debug)]
65/// struct CustomExporter;
66///
67/// impl Export for CustomExporter {
68/// fn export(&self, message: InstanceMessage<'_>) {
69/// // Custom export logic here
70/// println!("Exporting: {:?}", message);
71/// }
72/// }
73/// ```
74pub trait Export: Debug {
75 /// Exports a telemetry message.
76 ///
77 /// This method is called for each telemetry message that needs to be exported.
78 /// The implementation should handle the message appropriately based on its type.
79 fn export(&self, message: InstanceMessage<'_>);
80}