Skip to content

Commit 86f1d80

Browse files
authored
feat: Pass package source name in component usage metric (#160)
1 parent e539ae0 commit 86f1d80

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

src/internal/base-component/__tests__/metrics.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ describe('Client Metrics support', () => {
276276
v: testCase[1][1],
277277
a: 'used',
278278
s: 'DummyComponentName',
279+
p: 'pkg',
279280
c: { props: {} },
280281
});
281282
});
@@ -293,6 +294,7 @@ describe('Client Metrics support', () => {
293294
v: '1.0',
294295
a: 'used',
295296
s: 'DummyComponentName',
297+
p: 'dummy-package',
296298
c: { props: {} },
297299
});
298300
});
@@ -306,6 +308,7 @@ describe('Client Metrics support', () => {
306308
v: '1.0',
307309
a: 'used',
308310
s: 'DummyComponentName',
311+
p: 'dummy-package',
309312
c: { props: { variant: 'primary' }, metadata: { isMobile: true } },
310313
});
311314
});
@@ -322,6 +325,7 @@ describe('Client Metrics support', () => {
322325
v: '1.0',
323326
a: 'used',
324327
s: 'DummyComponentName',
328+
p: 'dummy-package',
325329
c: { props: {}, metadata: { nullValue: null } },
326330
});
327331
});
@@ -337,6 +341,7 @@ describe('Client Metrics support', () => {
337341
v: '1.0',
338342
a: 'used',
339343
s: 'DummyComponentName',
344+
p: 'dummy-package',
340345
c: { props: { count: 123, notANumber: 'NaN', maxSize: 'Infinity' } },
341346
});
342347
});

src/internal/base-component/__tests__/use-component-metrics.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ describe('useComponentMetrics', () => {
8787
v: '3.0.0',
8888
a: 'used',
8989
s: 'test-component-1',
90+
p: 'toolkit',
9091
c: { props: {} },
9192
})
9293
);
@@ -113,6 +114,7 @@ describe('useComponentMetrics', () => {
113114
v: '3.0.0',
114115
a: 'used',
115116
s: 'test-component-2',
117+
p: 'toolkit',
116118
c: { props: {} },
117119
})
118120
);
@@ -133,6 +135,7 @@ describe('useComponentMetrics', () => {
133135
v: '3.0.0',
134136
a: 'used',
135137
s: 'test-component-with-props',
138+
p: 'toolkit',
136139
};
137140
expect(window.AWSC.Clog.log).toHaveBeenCalledTimes(1);
138141
expect(window.AWSC.Clog.log).toHaveBeenCalledWith(
@@ -165,6 +168,7 @@ describe('useComponentMetrics', () => {
165168
v: '3.0.0',
166169
a: 'used',
167170
s: 'test-component-1',
171+
p: 'toolkit',
168172
c: { props: {} },
169173
})
170174
);

src/internal/base-component/metrics/formatters.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ export function buildMetricDetail(detail: JSONObject, context: PackageSettings):
2020
}
2121

2222
export function buildComponentMetricDetail(
23-
{ componentName, action, configuration }: ComponentMetricDetail,
23+
{ componentName, action, configuration, packageSource }: ComponentMetricDetail,
2424
context: PackageSettings
2525
): string {
2626
return buildMetricDetail(
2727
{
2828
a: action,
2929
s: componentName,
30+
p: packageSource,
3031
c: configuration as JSONObject | undefined,
3132
},
3233
context

src/internal/base-component/metrics/interfaces.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface ComponentMetricDetail {
2727
// "used" – individual component used
2828
action: 'loaded' | 'used';
2929
configuration?: ComponentConfiguration;
30+
packageSource?: string;
3031
}
3132

3233
export interface ComponentMetricMinified {
@@ -44,4 +45,6 @@ export interface ComponentMetricMinified {
4445
v: string;
4546
// component configuration
4647
c?: JSONObject;
48+
// package name
49+
p?: string;
4750
}

src/internal/base-component/metrics/metrics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export class Metrics {
7878
action: 'used',
7979
componentName,
8080
configuration,
81+
packageSource: this.context.packageSource,
8182
});
8283
}
8384
}

0 commit comments

Comments
 (0)