From c5917b328f7c766d695f951cd84a7ce867ef4f7a Mon Sep 17 00:00:00 2001 From: Cooper Willetts Date: Fri, 15 Dec 2023 12:13:13 -0500 Subject: [PATCH] adjusted metric name in network layer --- src/storage/networkLayer.ts | 13 ++++++++++++- src/trackMetric.test.ts | 1 - src/utils/enhancers.test.ts | 7 ------- src/utils/enhancers.ts | 1 - 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/storage/networkLayer.ts b/src/storage/networkLayer.ts index f7d98a3..5f1d09a 100644 --- a/src/storage/networkLayer.ts +++ b/src/storage/networkLayer.ts @@ -13,6 +13,17 @@ export const DEFAULT_NETWORK_LAYER = { sendEvents: NO_OP, }; +function metricNameEnhancer( + metrics: Record[] +): Record[] { + metrics.forEach((metric) => { + if (metric['metricName']) { + metric.metric_name = metric.metricName; + delete metric['metricName']; + } + }); + return metrics; +} /* * Schedule an event @@ -83,7 +94,7 @@ export const sendMetrics = (metrics: Metric[], skipScheduler = false) => { const metricEndpoint = `${apiEndpoint}${metricPath}`; const data = { - metricData: JSON.stringify(metrics), + metricData: JSON.stringify(metricNameEnhancer(metrics)), }; if (skipScheduler) { diff --git a/src/trackMetric.test.ts b/src/trackMetric.test.ts index 59ce114..8bc73fa 100644 --- a/src/trackMetric.test.ts +++ b/src/trackMetric.test.ts @@ -27,7 +27,6 @@ describe('trackMetric', () => { tags: { locale: '', auth: "notLoggedIn", - metric_name: "test", platform: "web", project_name: "testing", type: "count", diff --git a/src/utils/enhancers.test.ts b/src/utils/enhancers.test.ts index be8fec1..68a566b 100644 --- a/src/utils/enhancers.test.ts +++ b/src/utils/enhancers.test.ts @@ -53,7 +53,6 @@ describe('enhance', () => { auth: 'notLoggedIn', platform: 'unknown', project_name: '', - metric_name: 'testMetric', type: 'count', version_name: '', }, @@ -75,7 +74,6 @@ describe('enhance', () => { auth: 'notLoggedIn', platform: 'unknown', project_name: '', - metric_name: 'testMetric', type: 'count', version_name: '', }, @@ -93,7 +91,6 @@ describe('enhance', () => { auth: 'notLoggedIn', platform: 'unknown', project_name: '', - metric_name: 'testMetric', type: 'count', version_name: '', }, @@ -125,7 +122,6 @@ describe('enhance', () => { auth: 'notLoggedIn', platform: 'unknown', project_name: '', - metric_name: 'testMetric', type: 'count', version_name: '', }, @@ -145,7 +141,6 @@ describe('enhance', () => { auth: 'notLoggedIn', platform: 'unknown', project_name: '', - metric_name: 'testMetric', type: 'count', version_name: '', }, @@ -170,7 +165,6 @@ describe('enhance', () => { auth: 'notLoggedIn', platform: 'unknown', project_name: '', - metric_name: 'testMetric', type: 'count', version_name: '', }, @@ -199,7 +193,6 @@ describe('enhance', () => { auth: 'notLoggedIn', platform: 'unknown', project_name: '', - metric_name: 'testMetric', type: 'count', version_name: '', }, diff --git a/src/utils/enhancers.ts b/src/utils/enhancers.ts index 95d8d80..f0433ee 100644 --- a/src/utils/enhancers.ts +++ b/src/utils/enhancers.ts @@ -83,7 +83,6 @@ const tagsEnhancer = (entity: T) => { auth: identity.isAuthed() ? 'loggedIn' : 'notLoggedIn', platform: config.platform, project_name: config.projectName, - metric_name: entity.metricName, type: entity.metricType, ...entity.tags, locale: identity.locale ?? '',