41 releases (21 breaking)

new 0.25.0 Jan 2, 2025
0.24.1 Nov 24, 2024
0.19.0 Jun 30, 2024
0.18.0 Mar 9, 2024
0.2.1 Jun 11, 2022

#223 in Debugging

Download history 48706/week @ 2024-09-19 58023/week @ 2024-09-26 44191/week @ 2024-10-03 41234/week @ 2024-10-10 51697/week @ 2024-10-17 45608/week @ 2024-10-24 51540/week @ 2024-10-31 42331/week @ 2024-11-07 86890/week @ 2024-11-14 69681/week @ 2024-11-21 54842/week @ 2024-11-28 80865/week @ 2024-12-05 110112/week @ 2024-12-12 48835/week @ 2024-12-19 24528/week @ 2024-12-26 65502/week @ 2025-01-02

266,170 downloads per month
Used in 10 crates (9 directly)

CC0 license

50KB
722 lines

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.

  • Read OpenTelemetry header from incoming request
  • Start a new trace if no trace found in the incoming request
  • Trace is attached into tracing'span
  • OpenTelemetry Span is created on close of the tracing's span (behavior from [tracing-opentelemetry])

For examples, you can look at the examples folder.

//...
use axum_tracing_opentelemetry::opentelemetry_tracing_layer;

#[tokio::main]
async fn main() -> Result<(), axum::BoxError> {
    // very opinionated init of tracing, look at the source to make your own
    let _guard = init_tracing_opentelemetry::tracing_subscriber_ext::init_subscribers()?;

    let app = app();
    // run it
    let addr = &"0.0.0.0:3000".parse::<SocketAddr>()?;
    tracing::warn!("listening on {}", addr);
    let listener = tokio::net::TcpListener::bind(addr).await?;
    axum::serve(listener, app.into_make_service()).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
}

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

Changelog - History

CHANGELOG.md

Dependencies

~8.5MB
~147K SLoC