dont disable on_failure. the log breadcrumbs can be helpful still

This commit is contained in:
Bryan Stitt 2023-07-14 23:04:24 -07:00
parent 140dc04a8b
commit fe672b5189

@ -259,28 +259,25 @@ pub async fn serve(
.layer(Extension(Arc::new(response_cache))) .layer(Extension(Arc::new(response_cache)))
// request id // request id
.layer( .layer(
TraceLayer::new_for_http() TraceLayer::new_for_http().make_span_with(|request: &Request<Body>| {
.make_span_with(|request: &Request<Body>| { // We get the request id from the header
// We get the request id from the header // If no header, a new Ulid is created
// If no header, a new Ulid is created // TODO: move this header name to config
// TODO: move this header name to config let request_id = request
let request_id = request .headers()
.headers() .get("x-amzn-trace-id")
.get("x-amzn-trace-id") .and_then(|x| x.to_str().ok())
.and_then(|x| x.to_str().ok()) .map(ToString::to_string)
.map(ToString::to_string) .unwrap_or_else(|| Ulid::new().to_string());
.unwrap_or_else(|| Ulid::new().to_string());
// And then we put it along with other information into the `request` span // And then we put it along with other information into the `request` span
error_span!( error_span!(
"request", "request",
id = %request_id, id = %request_id,
// method = %request.method(), // method = %request.method(),
// path = %request.uri().path(), // path = %request.uri().path(),
) )
}) }), // .on_failure(|| todo!("on failure that has the request and response body so we can debug more easily")),
// TODO: on failure that has the request and response body so we can debug more easily
.on_failure(()),
) )
// 404 for any unknown routes // 404 for any unknown routes
.fallback(errors::handler_404); .fallback(errors::handler_404);