axum-tracing-opentelemetry

crates license crate version

Project Status: Active – The project has reached a stable, usable state and is being actively developed.

Middlewares and tools to integrate axum + tracing + opentelemetry.

For examples, you can look at:

```rust //... use axumtracingopentelemetry::{ opentelemetrytracinglayer, // optional tools to init tracer (require features) CollectorKind, init_tracer };

fn init_tracing() {

let otel_tracer = init_tracer(CollectorKind::Otlp).expect("setup of Tracer");
let otel_layer = tracing_opentelemetry::layer().with_tracer(otel_tracer);

let subscriber = tracing_subscriber::registry()
    //...
    .with(otel_layer);
tracing::subscriber::set_global_default(subscriber).unwrap();

}

[tokio::main]

async fn main() -> Result<(), Box> { inittracing(); let app = app(); // run it let addr = &"0.0.0.0:3000".parse::()?; tracing::warn!("listening on {}", addr); axum::Server::bind(&addr) .serve(app.intomakeservice()) .withgracefulshutdown(shutdownsignal()) .await?; Ok(()) }

fn app() -> Router { // build our application with a route Router::new() .route("/health", get(health)) // opentelemetrytracinglayer setup TraceLayer, that is provided by tower-http so you have to add that as a dependency. .layer(opentelemetrytracinglayer()) }

async fn shutdownsignal() { //... opentelemetry::global::shutdowntracer_provider(); } ```

History

0.1.0