Middlewares and tools to integrate axum + tracing + opentelemetry.
For examples, you can look at:
```rust //... use axumtracingopentelemetry::opentelemetrytracinglayer;
fn inittracing() { use axumtracingopentelemetry::{ makeresource, otlp, //stdio, };
let otel_rsrc = make_resource(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
let otel_tracer = otlp::init_tracer(otel_rsrc, otlp::identity).expect("setup of Tracer");
// let otel_tracer =
// stdio::init_tracer(otel_rsrc, stdio::identity, stdio::WriteNoWhere::default())
// .expect("setup of Tracer");
let otel_layer = tracing_opentelemetry::layer().with_tracer(otel_tracer);
let subscriber = tracing_subscriber::registry()
//...
.with(otel_layer);
tracing::subscriber::set_global_default(subscriber).unwrap();
}
async fn main() -> Result<(), Box
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 retrieve the current trace_id
(eg to add it into error message (as header or attributes))
rust
let trace_id = axum_tracing_opentelemetry::find_current_trace_id();
json!({ "error" : "xxxxxx", "trace_id": trace_id})
/dev/null
) to allow to have trace_id
and the opentelemetry span & metadata on log and http response (without collector)