From 99403e481b732cadb561f7978948f0b3f6eb9f61 Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Wed, 22 May 2024 10:08:31 +0200 Subject: [PATCH] feat: add prometheus metrics error logging (#7105) --- src/lib/metrics.ts | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/lib/metrics.ts b/src/lib/metrics.ts index 096f07c4a0..6bfc50368b 100644 --- a/src/lib/metrics.ts +++ b/src/lib/metrics.ts @@ -616,24 +616,29 @@ export default class MetricsMonitor { }); }); + const logger = config.getLogger('metrics.ts'); eventBus.on(CLIENT_METRICS, (m: ValidatedClientMetrics) => { - for (const entry of Object.entries(m.bucket.toggles)) { - featureFlagUsageTotal.increment( - { - toggle: entry[0], - active: 'true', - appName: m.appName, - }, - entry[1].yes, - ); - featureFlagUsageTotal.increment( - { - toggle: entry[0], - active: 'false', - appName: m.appName, - }, - entry[1].no, - ); + try { + for (const entry of Object.entries(m.bucket.toggles)) { + featureFlagUsageTotal.increment( + { + toggle: entry[0], + active: 'true', + appName: m.appName, + }, + entry[1].yes, + ); + featureFlagUsageTotal.increment( + { + toggle: entry[0], + active: 'false', + appName: m.appName, + }, + entry[1].no, + ); + } + } catch (e) { + logger.warn('Metrics registration failed', e); } }); eventStore.on(CLIENT_REGISTER, (m) => {