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;

[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 { // build our application with a route Router::new() .route("/", get(health)) // request processed inside span // opentelemetrytracinglayer setup TraceLayer, that is provided by tower-http so you have to add that as a dependency. .layer(opentelemetrytracinglayer()) .route("/health", get(health)) // request processed without span / trace }

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

To also inject the trace id into the response (could be useful for debugging) uses the layer response_with_trace_layer

rust // build our application with a route Router::new() ... // include trace context as header into the response .layer(response_with_trace_layer())

For more info about how to setup, 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