Skip to content

Commit

Permalink
Agama server logging (#1143)
Browse files Browse the repository at this point in the history
## Problem

We want to have an insight into incoming requests and corresponding
responses
- https://trello.com/c/erXAzTxp

## Solution

Configured
[TraceLayer](https://docs.rs/tower-http/0.5.2/tower_http/trace/struct.TraceLayer.html)
to write some basic info into journald

## Testing

- *Tested manually*


## Screenshots


![agama-web-server_logs](https://github.com/openSUSE/agama/assets/1579239/f8197e39-df20-4f82-a59e-a7d529f620a9)
  • Loading branch information
mchf authored Apr 15, 2024
2 parents c5e1c5d + 7f9f06c commit 748cfbb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions rust/agama-server/src/web/service.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
use super::http::{login, login_from_query, logout, session};
use super::{auth::TokenClaims, config::ServiceConfig, state::ServiceState, EventsSender};
use axum::{
body::Body,
extract::Request,
middleware,
response::IntoResponse,
response::{IntoResponse, Response},
routing::{get, post},
Router,
};
use std::time::Duration;
use std::{
convert::Infallible,
path::{Path, PathBuf},
};
use tower::Service;
use tower_http::{compression::CompressionLayer, services::ServeDir, trace::TraceLayer};
use tracing::Span;

/// Builder for Agama main service.
///
Expand Down Expand Up @@ -93,7 +96,17 @@ impl MainServiceBuilder {
.route("/login", get(login_from_query))
.route("/po.js", get(super::http::po))
.nest("/api", api_router)
.layer(TraceLayer::new_for_http())
.layer(
TraceLayer::new_for_http()
.on_request(|request: &Request<Body>, _span: &Span| {
tracing::info!("request: {} {}", request.method(), request.uri().path())
})
.on_response(
|response: &Response<Body>, latency: Duration, _span: &Span| {
tracing::info!("response: {} {:?}", response.status(), latency)
},
),
)
.layer(CompressionLayer::new().br(true))
.with_state(state)
}
Expand Down

0 comments on commit 748cfbb

Please sign in to comment.