An Actix-web middleware component which synchronises a correlation ID for cross API request logging
```rust use actixweb::{ client::Client, middleware::Logger, web::{self}, App, Error, HttpResponse, HttpServer, }; use actixwebcorrelationid::{ Correlation, CorrelationId, CorrelationIdPropagate, CorrelationIdVariable, };
async fn index(corr_id: CorrelationId) -> Result
let mut res = client
.get("http://google.com/")
.with_corr_id(corr_id)
.send()
.await?;
let mut client_resp = HttpResponse::build(res.status());
Ok(client_resp.body(res.body().await?))
}
async fn main() -> std::io::Result<()> { envlogger::initfromenv(envlogger::Env::new().defaultfilteror("info"));
HttpServer::new(move || {
App::new()
.wrap(
Logger::new("%{corr-id}xi %a \"%r\" %s %b \"%{Referer}i\" \"%{User-Agent}i\" %T")
.add_corr_id(),
)
.wrap(
Correlation::new()
.header_name("x-correlation-id")
.enforce_header(false)
.resp_header_name(Some("x-correlation-id"))
.include_in_resp(true),
)
.service(web::resource("/simple").route(web::post().to(index)))
})
.bind("127.0.0.1:8080")?
.run()
.await
} ```