#[micromegas_main]Expand description
micromegas_main: Creates a tokio runtime with proper micromegas tracing callbacks and telemetry setup
This is a drop-in replacement for #[tokio::main] that automatically configures:
- Tokio runtime with proper micromegas tracing thread lifecycle callbacks
- Telemetry guard with sensible defaults (ctrl-c handling, debug level)
- Automatic authentication configuration from environment variables
§Authentication
The macro automatically configures telemetry authentication based on environment variables:
- API Key: Set
MICROMEGAS_INGESTION_API_KEY=your-key - OIDC Client Credentials: Set
MICROMEGAS_OIDC_TOKEN_ENDPOINT,MICROMEGAS_OIDC_CLIENT_ID,MICROMEGAS_OIDC_CLIENT_SECRET - No auth: If no env vars are set, telemetry is sent unauthenticated (requires
--disable-authon ingestion server)
§Parameters
ctrlc_handling: bool (default:true) — enable Ctrl-C graceful shutdowninstall_log_capture: bool (default:false) — capturelogcrate outputinterop_max_level: string (e.g.,"info") — interop max level overridelocal_sink_enabled: bool (default:true) — enable local stderr sinklocal_sink_max_level: string (default:"debug") — max level for local sinkmax_level_override: string (e.g.,"warn") — global max level overridesystem_metrics: bool (default:true) — collect system metricstelemetry_url: string — override the telemetry ingestion URLapi_key: string — embed a literal API key (takes precedence over env-var auth)
§Examples
ⓘ
use micromegas::tracing::prelude::*;
#[micromegas_main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
info!("Server starting - telemetry already configured!");
Ok(())
}
#[micromegas_main(interop_max_level = "info")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
info!("Server starting with info interop level!");
Ok(())
}
#[micromegas_main(max_level_override = "warn", interop_max_level = "info")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
info!("Server starting with both level overrides!");
Ok(())
}
#[micromegas_main(telemetry_url = "http://localhost:9000", api_key = "my-secret-key")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
info!("Server with explicit URL and embedded API key!");
Ok(())
}