From cf8f08ab11566fe085d113a30fc20b9a6c869cc1 Mon Sep 17 00:00:00 2001 From: Dario Gieselaar Date: Tue, 19 Nov 2024 09:51:55 +0100 Subject: [PATCH] [Infra] Use callback for logger.trace calls (#199805) Use a callback for logger.trace() so big objects only get stringified when trace logging is enabled. --------- Co-authored-by: Elastic Machine Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit b8e6bbd4610b50169f1d19a0929d0db68aa82ad7) --- .../lib/alerting/inventory_metric_threshold/lib/get_data.ts | 4 ++-- .../lib/alerting/metric_threshold/lib/check_missing_group.ts | 4 ++-- .../server/lib/alerting/metric_threshold/lib/get_data.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/observability_solution/infra/server/lib/alerting/inventory_metric_threshold/lib/get_data.ts b/x-pack/plugins/observability_solution/infra/server/lib/alerting/inventory_metric_threshold/lib/get_data.ts index 207f2fcb7cb27..e911440ce5aa2 100644 --- a/x-pack/plugins/observability_solution/infra/server/lib/alerting/inventory_metric_threshold/lib/get_data.ts +++ b/x-pack/plugins/observability_solution/infra/server/lib/alerting/inventory_metric_threshold/lib/get_data.ts @@ -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(request); - logger.trace(`Response: ${JSON.stringify(body)}`); + logger.trace(() => `Response: ${JSON.stringify(body)}`); if (body.aggregations) { return handleResponse(body.aggregations, previousNodes); } diff --git a/x-pack/plugins/observability_solution/infra/server/lib/alerting/metric_threshold/lib/check_missing_group.ts b/x-pack/plugins/observability_solution/infra/server/lib/alerting/metric_threshold/lib/check_missing_group.ts index f5e2a19cb70e9..d50c11710db76 100644 --- a/x-pack/plugins/observability_solution/infra/server/lib/alerting/metric_threshold/lib/check_missing_group.ts +++ b/x-pack/plugins/observability_solution/infra/server/lib/alerting/metric_threshold/lib/check_missing_group.ts @@ -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) => { diff --git a/x-pack/plugins/observability_solution/infra/server/lib/alerting/metric_threshold/lib/get_data.ts b/x-pack/plugins/observability_solution/infra/server/lib/alerting/metric_threshold/lib/get_data.ts index d2afb40cecf50..e30edbeac9360 100644 --- a/x-pack/plugins/observability_solution/infra/server/lib/alerting/metric_threshold/lib/get_data.ts +++ b/x-pack/plugins/observability_solution/infra/server/lib/alerting/metric_threshold/lib/get_data.ts @@ -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(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) {