micromegas/lib.rs
1//! Micromegas is a unified and scalable observability stack.
2//! It can help you collect and query logs, metrics and traces.
3//!
4//! # Very high level architecture
5//!
6//!
7//! ```text
8//! ┌─────────────────┐
9//! │ rust application│──────▶
10//! └─────────────────┘ ┌─────────┐ ┌───────┐ ┌─────────┐ ┌──────────┐
11//! │ingestion│────▶│pg & S3│◀────│analytics│◀────│python API│
12//! ┌─────────────────┐ └─────────┘ └───────┘ └─────────┘ └──────────┘
13//! │ unreal engine │──────▶
14//! └─────────────────┘
15//!
16//! ```
17//! ## Cargo features
18//! - default: instrumentation only (`micromegas::tracing` and the telemetry sink).
19//! - `client`: the FlightSQL query client in `micromegas::client::flightsql_client` and its factory,
20//! without the service stack. Re-exports `arrow`, `arrow_flight` and `tonic`; `TimeRange` is at
21//! `micromegas::telemetry::time_range::TimeRange`.
22//! - `server`: everything (ingestion, analytics, auth, servers). Implies `client`.
23//!
24//! ## Rust Instrumentation
25//! For rust applications, use micromegas::tracing for minimal overhead. Interoperability with tokio tracing's logs is also enabled by default.
26//!
27//! ## Unreal instrumentation
28//! `MicromegasTracing` should be added to Unreal's Core module and `MicromegasTelemetrySink` can be added to a game or to a high level plugin. See <https://github.com/madesroches/micromegas/tree/main/unreal> for implementation. It has been tested in editor, client and server builds on multiple platforms.
29//!
30//! ## Telemetry ingestion server
31//! <https://github.com/madesroches/micromegas/blob/main/rust/telemetry-ingestion-srv/src/main.rs>
32//!
33//! ## FlightSQL server
34//! <https://github.com/madesroches/micromegas/blob/main/rust/flight-sql-srv/src/flight_sql_srv.rs>
35//!
36//! ## Lakehouse daemon
37//! <https://github.com/madesroches/micromegas/blob/main/rust/telemetry-maintenance-srv/src/main.rs>
38//!
39//! ## Python API
40//! <https://pypi.org/project/micromegas/>
41//!
42//!
43//! # Local developer configuration
44//!
45//! For testing purposes, you can run the entire stack on your local workstation.
46//!
47//! ## Environment variables
48//!
49//! - `MICROMEGAS_DB_USERNAME` and `MICROMEGAS_DB_PASSWD`: used by the database configuration script
50//! - `export MICROMEGAS_TELEMETRY_URL=http://localhost:9000`
51//! - `export MICROMEGAS_SQL_CONNECTION_STRING=postgres://{uname}:{passwd}@localhost:5432`
52//! - `export MICROMEGAS_OBJECT_STORE_URI=file:///some/local/path`
53//!
54//! 1. Clone the github repository
55//! ```text
56//! > git clone https://github.com/madesroches/micromegas.git
57//! ```
58//!
59//! 2. Start a local instance of postgresql (requires docker and python)
60//!
61//! ```text
62//! > cd micromegas/local_test_env/db
63//! > ./run.py
64//! ```
65//!
66//! 3. In a new shell, start the ingestion server
67//! ```text
68//! > cd micromegas/rust
69//! > cargo run -p telemetry-ingestion-srv -- --ingestion-listen-addr 127.0.0.1:9000
70//! ```
71//!
72//!
73//! 4. In a new shell, start the flightsql server
74//! ```text
75//! > cd micromegas/rust
76//! > cargo run -p flight-sql-srv -- --disable-auth
77//! ```
78//!
79//! 5. In a new shell, start the daemon
80//! ```text
81//! > cd micromegas/rust
82//! > cargo run -p telemetry-maintenance-srv
83//! ```
84//!
85//! 6. In a python interpreter, query the analytics service
86//! ```python
87//! # local connection test
88//! import datetime
89//! import micromegas
90//! client = micromegas.connect() #connects to localhost by default
91//! now = datetime.datetime.now(datetime.timezone.utc)
92//! begin = now - datetime.timedelta(days=1)
93//! end = now
94//! sql = """
95//! SELECT *
96//! FROM log_entries
97//! ORDER BY time DESC
98//! LIMIT 10
99//! ;"""
100//! df = client.query(sql, begin, end)
101//! df #dataframe containing the result of the query
102//! ```
103//!
104#![allow(missing_docs)]
105#![allow(clippy::new_without_default)]
106
107/// re-exports (always available)
108pub use chrono;
109pub use uuid;
110
111/// re-exports (client)
112#[cfg(feature = "client")]
113pub use arrow;
114#[cfg(feature = "client")]
115pub use arrow_flight;
116#[cfg(feature = "client")]
117pub use tonic;
118
119/// re-exports (server-only)
120#[cfg(feature = "server")]
121pub use axum;
122#[cfg(feature = "server")]
123pub use datafusion;
124#[cfg(feature = "server")]
125pub use object_store;
126#[cfg(feature = "server")]
127pub use prost;
128#[cfg(feature = "server")]
129pub use sqlx;
130
131/// telemetry protocol
132pub mod telemetry {
133 pub use micromegas_telemetry::*;
134}
135
136/// publication of the recorded events using http
137pub mod telemetry_sink {
138 pub use micromegas_telemetry_sink::*;
139}
140
141/// low level tracing - has minimal dependencies
142pub mod tracing {
143 pub use micromegas_tracing::*;
144}
145
146/// binary heterogeneous queue serialization, used by the tracing event blocks
147pub mod transit {
148 pub use micromegas_transit::*;
149}
150
151// Re-export proc macros at the top level for easy access
152pub use micromegas_proc_macros::*;
153
154/// re-export of `declare_jemalloc_conf!`, kept behind `jemalloc-metrics`
155/// (rather than always available) so an app depending on `micromegas` only
156/// for `TelemetryGuardBuilder` doesn't find a server-tuned allocator conf in
157/// its API surface. See `mkdocs/docs/admin/memory-allocator.md`.
158#[cfg(feature = "jemalloc-metrics")]
159pub use micromegas_telemetry_sink::declare_jemalloc_conf;
160
161/// authentication providers
162#[cfg(feature = "server")]
163pub mod auth {
164 pub use micromegas_auth::*;
165}
166
167/// records telemetry in data lake
168#[cfg(feature = "server")]
169pub mod ingestion {
170 pub use micromegas_ingestion::*;
171}
172
173/// makes the telemetry data lake accessible and useful
174#[cfg(feature = "server")]
175pub mod analytics {
176 pub use micromegas_analytics::*;
177}
178
179/// perfetto protobufs
180#[cfg(feature = "server")]
181pub mod perfetto {
182 pub use micromegas_perfetto::*;
183}
184
185/// shared object range cache
186#[cfg(feature = "server")]
187pub mod object_cache {
188 pub use micromegas_object_cache::*;
189}
190
191#[cfg(feature = "server")]
192pub mod config;
193
194#[cfg(feature = "server")]
195pub mod servers;
196
197#[cfg(feature = "client")]
198pub mod client;