feat: JSON-Logging mit Correlation-ID, Anfrage-Log und Audit (M2.4)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 17:39:03 +01:00
parent 2ec9eccde6
commit 6cb930d0b0
31 changed files with 1050 additions and 67 deletions

View File

@ -9,6 +9,7 @@
//! Anfrage und läuft bis zum Beenden des Gateways. Ressourcenplanung,
//! Verdrängung und Idle-Timeouts fehlen.
mod access;
mod auth;
mod chat;
mod error;
@ -19,10 +20,10 @@ mod state;
use std::sync::Arc;
use axum::Router;
use axum::extract::{DefaultBodyLimit, Request};
use axum::http::{HeaderValue, StatusCode};
use axum::middleware::{self, Next};
use axum::response::{IntoResponse, Response};
use axum::extract::DefaultBodyLimit;
use axum::http::StatusCode;
use axum::middleware;
use axum::response::IntoResponse;
use axum::routing::{get, post};
pub use error::ApiError;
@ -41,7 +42,10 @@ pub fn router(state: Arc<AppState>) -> Router {
.route("/gateway/v1/health", get(health))
.fallback(not_found)
.layer(DefaultBodyLimit::max(MAX_BODY_BYTES))
.layer(middleware::from_fn(request_id))
.layer(middleware::from_fn_with_state(
state.clone(),
access::observe,
))
.with_state(state)
}
@ -57,15 +61,3 @@ async fn not_found() -> ApiError {
"Unbekannte Adresse.",
)
}
/// Hängt jeder Antwort eine `x-request-id` an.
async fn request_id(request: Request, next: Next) -> Response {
let id = nexus_core::random_hex(8)
.map(|h| format!("req_{h}"))
.unwrap_or_else(|_| "req_unbekannt".to_string());
let mut response = next.run(request).await;
if let Ok(value) = HeaderValue::from_str(&id) {
response.headers_mut().insert("x-request-id", value);
}
response
}