Skip to content

Commit 87fe9cb

Browse files
committed
log timing info
1 parent 64c4d22 commit 87fe9cb

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

libsql-server/src/connection/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use tonic::metadata::BinaryMetadataValue;
1010

1111
use crate::auth::Authenticated;
1212
use crate::error::Error;
13+
use crate::http::user::timing::sample_time;
1314
use crate::metrics::{
1415
CONCURRENT_CONNECTIONS_COUNT, CONNECTION_ALIVE_DURATION, CONNECTION_CREATE_TIME,
1516
};
@@ -398,6 +399,7 @@ pub struct TrackedConnection<DB> {
398399

399400
impl<T> Drop for TrackedConnection<T> {
400401
fn drop(&mut self) {
402+
sample_time("connection-duration", self.created_at.elapsed());
401403
CONCURRENT_CONNECTIONS_COUNT.decrement(1.0);
402404
CONNECTION_ALIVE_DURATION.record(self.created_at.elapsed());
403405
}

libsql-server/src/http/user/timing.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use axum::middleware::Next;
77
use axum::response::Response;
88
use hashbrown::HashMap;
99
use parking_lot::Mutex;
10+
use tracing::{Instrument, Span};
1011

1112
#[derive(Default, Clone, Debug)]
1213
pub struct Timings {
@@ -40,13 +41,22 @@ macro_rules! record_time {
4041
let __ret__ = {
4142
$($rest)*
4243
};
43-
let _ = $crate::http::user::timing::TIMINGS.try_with(|t| t.record($k, __before__.elapsed()));
44+
let __elapsed__ = __before__.elapsed();
45+
tracing::debug!(target: "timings", name = $k, elapsed = tracing::field::debug(__elapsed__));
46+
let _ = $crate::http::user::timing::TIMINGS.try_with(|t| t.record($k, __elapsed__));
4447
__ret__
4548
}
4649
};
4750
}
4851

52+
pub fn sample_time(name: &'static str, duration: Duration) {
53+
tracing::debug!(target: "timings", name = name, elapsed = tracing::field::debug(duration));
54+
let _ = TIMINGS.try_with(|t| t.record(name, duration));
55+
}
56+
57+
#[tracing::instrument(skip_all, fields(req_id = tracing::field::debug(uuid::Uuid::new_v4())))]
4958
pub(crate) async fn timings_middleware<B>(request: Request<B>, next: Next<B>) -> Response {
59+
// tracing::error!("hello");
5060
TIMINGS
5161
.scope(Default::default(), async move {
5262
let mut response = record_time! {

0 commit comments

Comments
 (0)