Skip to content

Commit

Permalink
adjusted metric name in network layer
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperwilletts-cb committed Dec 15, 2023
1 parent 647f259 commit c5917b3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
13 changes: 12 additions & 1 deletion src/storage/networkLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ export const DEFAULT_NETWORK_LAYER = {
sendEvents: NO_OP,
};

function metricNameEnhancer(
metrics: Record<string, unknown>[]
): Record<string, unknown>[] {
metrics.forEach((metric) => {
if (metric['metricName']) {
metric.metric_name = metric.metricName;
delete metric['metricName'];
}
});
return metrics;
}

/*
* Schedule an event
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/trackMetric.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('trackMetric', () => {
tags: {
locale: '',
auth: "notLoggedIn",
metric_name: "test",
platform: "web",
project_name: "testing",
type: "count",
Expand Down
7 changes: 0 additions & 7 deletions src/utils/enhancers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ describe('enhance', () => {
auth: 'notLoggedIn',
platform: 'unknown',
project_name: '',
metric_name: 'testMetric',
type: 'count',
version_name: '',
},
Expand All @@ -75,7 +74,6 @@ describe('enhance', () => {
auth: 'notLoggedIn',
platform: 'unknown',
project_name: '',
metric_name: 'testMetric',
type: 'count',
version_name: '',
},
Expand All @@ -93,7 +91,6 @@ describe('enhance', () => {
auth: 'notLoggedIn',
platform: 'unknown',
project_name: '',
metric_name: 'testMetric',
type: 'count',
version_name: '',
},
Expand Down Expand Up @@ -125,7 +122,6 @@ describe('enhance', () => {
auth: 'notLoggedIn',
platform: 'unknown',
project_name: '',
metric_name: 'testMetric',
type: 'count',
version_name: '',
},
Expand All @@ -145,7 +141,6 @@ describe('enhance', () => {
auth: 'notLoggedIn',
platform: 'unknown',
project_name: '',
metric_name: 'testMetric',
type: 'count',
version_name: '',
},
Expand All @@ -170,7 +165,6 @@ describe('enhance', () => {
auth: 'notLoggedIn',
platform: 'unknown',
project_name: '',
metric_name: 'testMetric',
type: 'count',
version_name: '',
},
Expand Down Expand Up @@ -199,7 +193,6 @@ describe('enhance', () => {
auth: 'notLoggedIn',
platform: 'unknown',
project_name: '',
metric_name: 'testMetric',
type: 'count',
version_name: '',
},
Expand Down
1 change: 0 additions & 1 deletion src/utils/enhancers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ const tagsEnhancer = <T extends Metric>(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 ?? '',
Expand Down

0 comments on commit c5917b3

Please sign in to comment.