I'm pretty new to Actix/Rust (coming from Java+SpringBoot).
I am setting up a Rust microservice and need to integrate it into the rest of the tracing ecosystem at my company. We are using ECS format for our logs so that we can easily see all of the logs for a given request by filtering on the traceId
My goal is to include a traceId into a structured log event when something is logged from the log crate (info!()
/ warn!()
/ error!()
). I would like to get this traceId from B3 propagation headers.
For example, I would like for the following code to create 3 log events that all have the traceId.
#[get("/")]
pub async fn hello() -> impl Responder {
info!("1");
info!("2");
info!("3");
HttpResponse::Ok().body("Hello world!")
}
I am using env_logger with a custom pipe to send the logs
env_logger::builder()
.format(ecs_logger::format) // Configure ECS logger
.target(env_logger::Target::Pipe(Box::new(kafka_pipe))) // Write to Kafka
.init();
However, my issue is that I am struggling find a way to get the current traceId/spanId into the log record. In Java, the MDC class is how I would accomplish
// Middleware filter in SpringBoot
MDC.put("traceId", "<my-trace-id>");
I've tried using various crates like tracing/opentelemetry but I am getting a bit overwhelmed by all of the crates and how they interact with each other.