Skip to content

Commit

Permalink
[Infra] Use callback for logger.trace calls (elastic#199805)
Browse files Browse the repository at this point in the history
Use a callback for logger.trace() so big objects only get stringified
when trace logging is enabled.

---------

Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
(cherry picked from commit b8e6bbd)
  • Loading branch information
dgieselaar committed Nov 19, 2024
1 parent f3f9ac9 commit cf8f08a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ export const getData = async (
customMetric,
fieldsExisted
);
logger.trace(`Request: ${JSON.stringify(request)}`);
logger.trace(() => `Request: ${JSON.stringify(request)}`);
const body = await esClient.search<undefined, ResponseAggregations>(request);
logger.trace(`Response: ${JSON.stringify(body)}`);
logger.trace(() => `Response: ${JSON.stringify(body)}`);
if (body.aggregations) {
return handleResponse(body.aggregations, previousNodes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export const checkMissingGroups = async (
];
});

logger.trace(`Request: ${JSON.stringify({ searches })}`);
logger.trace(() => `Request: ${JSON.stringify({ searches })}`);
const response = await esClient.msearch({ searches });
logger.trace(`Response: ${JSON.stringify(response)}`);
logger.trace(() => `Response: ${JSON.stringify(response)}`);

const verifiedMissingGroups = response.responses
.map((resp, index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ export const getData = async (
fieldsExisted
),
};
logger.trace(`Request: ${JSON.stringify(request)}`);
logger.trace(() => `Request: ${JSON.stringify(request)}`);
const body = await esClient.search<undefined, ResponseAggregations>(request);
const { aggregations, _shards } = body;
logger.trace(`Response: ${JSON.stringify(body)}`);
logger.trace(() => `Response: ${JSON.stringify(body)}`);
if (aggregations) {
return handleResponse(aggregations, previousResults, _shards.successful);
} else if (_shards.successful) {
Expand Down

0 comments on commit cf8f08a

Please sign in to comment.