From fd20bbc6cbed7158e8756fd850d2750bd99b6647 Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Fri, 29 Sep 2023 09:40:27 +0100 Subject: [PATCH] proxy: log params when no endpoint (#5418) ## Problem Our SNI error dashboard features IP addresses but it's not immediately clear who that is still (#5369) ## Summary of changes Log some startup params with this error --- proxy/src/auth/backend.rs | 13 +++++++++++++ proxy/src/proxy.rs | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/proxy/src/auth/backend.rs b/proxy/src/auth/backend.rs index ff73f2b625..03c9029862 100644 --- a/proxy/src/auth/backend.rs +++ b/proxy/src/auth/backend.rs @@ -160,6 +160,19 @@ impl BackendType<'_, ClientCredentials<'_>> { Test(_) => Some("test".to_owned()), } } + + /// Get username from the credentials. + pub fn get_user(&self) -> &str { + use BackendType::*; + + match self { + Console(_, creds) => creds.user, + Postgres(_, creds) => creds.user, + Link(_) => "link", + Test(_) => "test", + } + } + /// Authenticate the client via the requested backend, possibly using credentials. #[tracing::instrument(fields(allow_cleartext = allow_cleartext), skip_all)] pub async fn authenticate( diff --git a/proxy/src/proxy.rs b/proxy/src/proxy.rs index c8f534b2b7..71e00ed58f 100644 --- a/proxy/src/proxy.rs +++ b/proxy/src/proxy.rs @@ -697,7 +697,14 @@ impl Client<'_, S> { .await { Ok(auth_result) => auth_result, - Err(e) => return stream.throw_error(e).await, + Err(e) => { + let user = creds.get_user(); + let db = params.get("database"); + let app = params.get("application_name"); + let params_span = tracing::info_span!("", ?user, ?db, ?app); + + return stream.throw_error(e).instrument(params_span).await; + } }; let AuthSuccess {