1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
910use axum::{extract::Request, middleware::Next, response::Response};
11use mz_ore::instrument;
12use std::time::Instant;
1314#[instrument]
15pub async fn logging_middleware(request: Request, next: Next) -> Response {
16let start: Instant = Instant::now();
17let method: hyper::Method = request.method().clone();
18let uri = request.uri().clone();
1920let response = next.run(request).await;
2122let latency = start.elapsed();
23let status = response.status();
2425tracing::info!(
26 method = %method,
27 uri = %uri,
28 status = %status,
29 latency = ?latency,
30"Request completed"
31);
3233 response
34}