From 8c546d0fd36d218ea28abae2a10a89fee7e17f26 Mon Sep 17 00:00:00 2001 From: Iain Sproat <68657+iainsproat@users.noreply.github.com> Date: Fri, 16 May 2025 15:28:31 +0100 Subject: [PATCH 1/2] chore(server/logging): do not log Express if logged by Apollo - requests to `/graphql` are logged by Apollo middleware, so no need to also log by Express - Should reduce log volume by around one third --- .../components/express/expressLogging.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/server/observability/components/express/expressLogging.ts b/packages/server/observability/components/express/expressLogging.ts index a376ed0c6..e5f43da8f 100644 --- a/packages/server/observability/components/express/expressLogging.ts +++ b/packages/server/observability/components/express/expressLogging.ts @@ -50,14 +50,23 @@ export const sanitizeQueryParams = ( return query } +const shouldBeLoggedAsDebug = (req: IncomingMessage) => { + const path = getRequestPath(req) + const shouldBeDebug = [ + '/metrics', + '/readiness', + '/liveness', + '/graphql' // graphql endpoint is logged by the graphql middleware + ].includes(path || '') + return shouldBeDebug +} + export const LoggingExpressMiddleware = HttpLogger({ logger, autoLogging: true, genReqId: GenerateRequestId, customLogLevel: (req, res, err) => { - const path = getRequestPath(req) - const shouldBeDebug = ['/metrics', '/readiness', '/liveness'].includes(path || '') - if (shouldBeDebug) return 'debug' + if (shouldBeLoggedAsDebug(req)) return 'debug' if (res.statusCode >= 400 && res.statusCode < 500) { return 'info' From 5148cb915fcf3eea9c71cd7c567d59204f39ea68 Mon Sep 17 00:00:00 2001 From: Iain Sproat <68657+iainsproat@users.noreply.github.com> Date: Fri, 16 May 2025 15:33:52 +0100 Subject: [PATCH 2/2] tidy code --- .../observability/components/express/expressLogging.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/server/observability/components/express/expressLogging.ts b/packages/server/observability/components/express/expressLogging.ts index e5f43da8f..4bae14630 100644 --- a/packages/server/observability/components/express/expressLogging.ts +++ b/packages/server/observability/components/express/expressLogging.ts @@ -52,13 +52,13 @@ export const sanitizeQueryParams = ( const shouldBeLoggedAsDebug = (req: IncomingMessage) => { const path = getRequestPath(req) - const shouldBeDebug = [ + if (!path) return false + return [ '/metrics', '/readiness', '/liveness', '/graphql' // graphql endpoint is logged by the graphql middleware - ].includes(path || '') - return shouldBeDebug + ].includes(path) } export const LoggingExpressMiddleware = HttpLogger({