axum-tracing-opentelemetry

crates license crate version

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

Middlewares to integrate axum + tracing + opentelemetry.

For examples, you can look at the examples folder.

```txt //... use axumtracingopentelemetry::opentelemetrytracinglayer;

[tokio::main]

async fn main() -> Result<(), axum::BoxError> { // very opinionated init of tracing, look as is source to make your own inittracingopentelemetry::tracingsubscriberext::init_subscribers()?;

let app = app();
// run it
let addr = &"0.0.0.0:3000".parse::<SocketAddr>()?;
tracing::warn!("listening on {}", addr);
axum::Server::bind(&addr)
    .serve(app.into_make_service())
    .with_graceful_shutdown(shutdown_signal())
    .await?;
Ok(())

}

fn app() -> Router { Router::new() .route("/", get(index)) // request processed inside span // include trace context as header into the response .layer(OtelInResponseLayer::default()) //start OpenTelemetry trace on incoming request .layer(OtelAxumLayer::default()) .route("/health", get(health)) // request processed without span / trace }

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

For more info about how to initialize, you can look at crate [init-tracing-opentelemetry] or [tracing-opentelemetry].

Compatibility

| axum | axum-tracing-opentelemetry | |------|----------------------------| | 0.6 | latest - 0.6 | | 0.5 | 0.1 - 0.5 |

Changelog - History

0.12

0.11

0.10

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1