From baea19aab21966b5afd704e31431ed8e98e1d06f Mon Sep 17 00:00:00 2001 From: Yoann Moinet Date: Wed, 13 Sep 2023 17:12:29 +0200 Subject: [PATCH] Correctly use Map primitive --- src/hooks/datadog/metrics/common.ts | 39 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/hooks/datadog/metrics/common.ts b/src/hooks/datadog/metrics/common.ts index 12f7fc1c..b0d33116 100644 --- a/src/hooks/datadog/metrics/common.ts +++ b/src/hooks/datadog/metrics/common.ts @@ -92,7 +92,7 @@ export const getPlugins = (plugins: TimingsMap): Metric[] => { metrics.push({ metric: 'plugins.count', type: 'count', - value: Object.keys(plugins).length, + value: plugins.size, tags: [], }); @@ -149,27 +149,26 @@ export const getLoaders = (loaders: TimingsMap): Metric[] => { metrics.push({ metric: 'loaders.count', type: 'count', - value: Object.keys(loaders).length, + value: loaders.size, tags: [], }); - metrics.push( - ...flattened( - Object.values(loaders).map((loader) => [ - { - metric: 'loaders.duration', - type: 'duration', - value: loader.duration, - tags: [`loaderName:${loader.name}`], - }, - { - metric: 'loaders.increment', - type: 'count', - value: loader.increment, - tags: [`loaderName:${loader.name}`], - }, - ]) - ) - ); + for (const loader of loaders.values()) { + metrics.push( + { + metric: 'loaders.duration', + type: 'duration', + value: loader.duration, + tags: [`loaderName:${loader.name}`], + }, + { + metric: 'loaders.increment', + type: 'count', + value: loader.increment, + tags: [`loaderName:${loader.name}`], + } + ); + } + return metrics; };