From 22e9e7e735e0fbbf72d1c6036b76aa5fe09703ac Mon Sep 17 00:00:00 2001 From: Stanley Chin Date: Fri, 30 Aug 2024 14:41:16 -0400 Subject: [PATCH] Attempt to log http response size --- .../src/app-middlewares/after/large-response-cacher.js | 7 +++++++ packages/core/src/http-middlewares/after/log-response.js | 3 +++ 2 files changed, 10 insertions(+) diff --git a/packages/core/src/app-middlewares/after/large-response-cacher.js b/packages/core/src/app-middlewares/after/large-response-cacher.js index d7a97b8aa..db0068378 100644 --- a/packages/core/src/app-middlewares/after/large-response-cacher.js +++ b/packages/core/src/app-middlewares/after/large-response-cacher.js @@ -28,6 +28,13 @@ const largeResponseCachePointer = async (output) => { output.resultsUrl = url; output.results = Array.isArray(output.results) ? [] : {}; } + + if (size > autostashLimit) { + console.log( + `Oh no! Payload is ${size}, which is larger than ${autostashLimit}.` + ); + } + return output; }; diff --git a/packages/core/src/http-middlewares/after/log-response.js b/packages/core/src/http-middlewares/after/log-response.js index a396ba462..e6fd20e54 100644 --- a/packages/core/src/http-middlewares/after/log-response.js +++ b/packages/core/src/http-middlewares/after/log-response.js @@ -8,6 +8,7 @@ const prepareRequestLog = (req, resp) => { req = req || {}; resp = resp || {}; + let responseSize = 0; let responseBody; if (!req.raw) { if (typeof resp.content !== 'string') { @@ -15,6 +16,7 @@ const prepareRequestLog = (req, resp) => { } else { responseBody = resp.content; } + responseSize = Buffer.byteLength(responseBody, 'utf8'); // Get size in bytes } else { responseBody = ''; } @@ -36,6 +38,7 @@ const prepareRequestLog = (req, resp) => { response_status_code: resp.status, response_headers: resp.headers, response_content: responseBody, + response_size: responseSize, }; if (req._requestStart) {