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 <elasticmachine@users.noreply.github.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent 94aaed3 commit b8e6bbd
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 b8e6bbd

Please sign in to comment.