Skip to main content

micromegas_main

Attribute Macro micromegas_main 

Source
#[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-auth on ingestion server)

§Parameters

  • ctrlc_handling: bool (default: true) — enable Ctrl-C graceful shutdown
  • install_log_capture: bool (default: false) — capture log crate output
  • interop_max_level: string (e.g., "info") — interop max level override
  • local_sink_enabled: bool (default: true) — enable local stderr sink
  • local_sink_max_level: string (default: "debug") — max level for local sink
  • max_level_override: string (e.g., "warn") — global max level override
  • system_metrics: bool (default: true) — collect system metrics
  • telemetry_url: string — override the telemetry ingestion URL
  • api_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(())
}