#axum #tracing #open-telemetry #tracing-layer

axum-tracing-opentelemetry

用于集成axum + 跟踪 + opentelemetry的中间件和工具

33个版本 (17个重大更改)

0.19.0 2024年6月30日
0.18.0 2024年3月9日
0.16.0 2023年12月30日
0.15.0 2023年11月25日
0.2.1 2022年6月11日

#379 in 性能分析

Download history 12585/week @ 2024-05-01 10566/week @ 2024-05-08 16370/week @ 2024-05-15 21128/week @ 2024-05-22 13499/week @ 2024-05-29 20401/week @ 2024-06-05 17258/week @ 2024-06-12 14969/week @ 2024-06-19 20706/week @ 2024-06-26 14433/week @ 2024-07-03 13567/week @ 2024-07-10 14508/week @ 2024-07-17 16235/week @ 2024-07-24 53244/week @ 2024-07-31 54587/week @ 2024-08-07 30644/week @ 2024-08-14

每月下载量159,168
用于 8 个crate(7个直接使用)

CC0 许可

50KB
721

axum-tracing-opentelemetry

crates license crate version

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

集成axum + 跟踪 + opentelemetry的中间件。

  • 从传入请求中读取OpenTelemetry头部
  • 如果传入请求中没有找到跟踪,则开始一个新的跟踪
  • 跟踪附加到跟踪的span上
  • 在跟踪的span关闭时创建OpenTelemetry Span(从[tracing-opentelemetry]的行为)

有关示例,您可以查看示例文件夹

//...
use axum_tracing_opentelemetry::opentelemetry_tracing_layer;

#[tokio::main]
async fn main() -> Result<(), axum::BoxError> {
    // very opinionated init of tracing, look as is source to make your own
    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())
        //FIXME .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 shutdown_signal() {
    //...
    opentelemetry::global::shutdown_tracer_provider();
}

有关初始化的更多信息,您可以查看crate init-tracing-opentelemetrytracing-opentelemetry

变更日志 - 历史

CHANGELOG.md

依赖关系

~9–11MB
~195K SLoC