collab logging (#9420)

- **Log errors inside the connection span**
- **Tidy up collab logging**


Release Notes:

- N/A
This commit is contained in:
Conrad Irwin 2024-03-15 16:02:37 -06:00 committed by GitHub
parent 0329b4a5cb
commit ca6e588085
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 101 additions and 63 deletions

View file

@ -1,5 +1,10 @@
use anyhow::anyhow;
use axum::{extract::MatchedPath, http::Request, routing::get, Extension, Router};
use axum::{
extract::MatchedPath,
http::{Request, Response},
routing::get,
Extension, Router,
};
use collab::{
api::fetch_extensions_from_blob_store_periodically, db, env, executor::Executor, AppState,
Config, MigrateConfig, Result,
@ -10,11 +15,11 @@ use std::{
net::{SocketAddr, TcpListener},
path::Path,
sync::Arc,
time::Duration,
};
#[cfg(unix)]
use tokio::signal::unix::SignalKind;
use tower_http::trace::{self, TraceLayer};
use tracing::Level;
use tower_http::trace::TraceLayer;
use tracing_subscriber::{
filter::EnvFilter, fmt::format::JsonFields, util::SubscriberInitExt, Layer,
};
@ -107,7 +112,16 @@ async fn main() -> Result<()> {
matched_path,
)
})
.on_response(trace::DefaultOnResponse::new().level(Level::INFO)),
.on_response(
|response: &Response<_>, latency: Duration, _: &tracing::Span| {
let duration_ms = latency.as_micros() as f64 / 1000.;
tracing::info!(
duration_ms,
status = response.status().as_u16(),
"finished processing request"
);
},
),
);
#[cfg(unix)]
@ -192,7 +206,7 @@ pub fn init_tracing(config: &Config) -> Option<()> {
tracing_subscriber::fmt::format()
.json()
.flatten_event(true)
.with_span_list(true),
.with_span_list(false),
)
.with_filter(filter),
) as Box<dyn Layer<_> + Send + Sync>