Crates.io | axum-tracing-opentelemetry |
lib.rs | axum-tracing-opentelemetry |
version | 0.23.0 |
source | src |
created_at | 2022-06-11 17:58:40.820733 |
updated_at | 2024-11-05 11:21:52.21065 |
description | Middlewares and tools to integrate axum + tracing + opentelemetry |
homepage | https://github.com/davidB/tracing-opentelemetry-instrumentation-sdk/tree/main/axum-tracing-opentelemetry |
repository | https://github.com/davidB/tracing-opentelemetry-instrumentation-sdk |
max_upload_size | |
id | 604165 |
size | 20,395 |
Middlewares to integrate axum + 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 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();
}
For more info about how to initialize, you can look at crate init-tracing-opentelemetry
or tracing-opentelemetry
.