Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core) Attempt to log http response size #854

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/http-middlewares/after/log-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ const prepareRequestLog = (req, resp) => {
req = req || {};
resp = resp || {};

let responseSize = 0;
let responseBody;
if (!req.raw) {
if (typeof resp.content !== 'string') {
responseBody = JSON.stringify(resp.content);
} else {
responseBody = resp.content;
}
responseSize = Buffer.byteLength(responseBody, 'utf8'); // Get size in bytes
} else {
responseBody = '<probably streaming data>';
}
Expand All @@ -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) {
Expand Down
Loading