Skip to content

Conversation

@just-boris
Copy link
Member

@just-boris just-boris commented Jun 17, 2025

Issue #, if available:

Description of changes:

Refactor this code

  1. Enforce theme, version, origin on all metrics we send
  2. Remove all unused methods from the public API
  3. Add new public methods, both deduplicated by default
    • sendOpsMetricObject(name, detail) for objects
    • sendOpsMetricValue(name, value) for number values

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link

codecov bot commented Jun 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.34%. Comparing base (e41ff41) to head (d3bfb98).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #136      +/-   ##
==========================================
- Coverage   99.35%   99.34%   -0.02%     
==========================================
  Files          32       32              
  Lines         774      760      -14     
  Branches      206      206              
==========================================
- Hits          769      755      -14     
  Misses          5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines -178 to -186
test('throws an error when detail is too long', () => {
const invalidDetail = 'a'.repeat(4001);
metrics.sendMetric('metricName', 0, invalidDetail);
expect(console.error).toHaveBeenCalledWith(`Detail for metric metricName is too long: ${invalidDetail}`);
jest.mocked(console.error).mockReset();
expect(window.panorama).not.toHaveBeenCalled();
expect(window.AWSC.Clog.log).not.toHaveBeenCalled();
});
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate test. Removed this copy, the other one stays

test('throws an error when detail is too long', () => {
const invalidMetric = {
...metric,
eventDetail: 'a'.repeat(4001),
};
metrics.sendPanoramaMetric(invalidMetric);
expect(console.error).toHaveBeenCalledWith(
`Event detail for metric is too long: ${invalidMetric.eventDetail}`
);
jest.mocked(console.error).mockReset();
});

Comment on lines 278 to 286
checkMetric(`awsui_DummyComponentName_d10`, {
o: 'main',
s: 'DummyComponentName',
t: 'default',
a: 'used',
f: 'react',
v: '1.0',
a: 'used',
s: 'DummyComponentName',
c: { props: {} },
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of keys matters, because there is JSON.stringify down the line and we compare the serialized strings

}

export function jsonStringify(detailObject: any) {
export function buildComponentMetricDetail(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separated component metric details from generic base metric details (such as origin, theme, framework, version

Comment on lines +15 to +17
constructor(packageSource: PackageSettings);
constructor(packageSource: string, packageVersion: string);
constructor(...args: [PackageSettings] | [string, string]) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping dual signature until this one usage is migrated: https://github.com/cloudscape-design/components/blob/3bf581977a630226c8f574d5fa83a8e9c52b2a1c/src/internal/metrics.ts#L7

The rest of the code uses useComponentMetrics hook

Comment on lines -37 to -40
if (!theme) {
// Metrics need to be initialized first (initMetrics)
console.error('Metrics need to be initialized first.');
return;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore, because theme is always provided

@just-boris just-boris marked this pull request as ready for review June 17, 2025 22:36
@just-boris just-boris requested a review from a team as a code owner June 17, 2025 22:36
@just-boris just-boris requested review from avinashbot and removed request for a team June 17, 2025 22:36
@just-boris just-boris requested review from a team and Al-Dani and removed request for a team and avinashbot June 18, 2025 12:54
metrics.sendMetricOnce('my-event', 1);
metrics.sendMetricOnce('My-Event', 2);
metrics.sendOpsMetricValue('my-event', 1);
metrics.sendOpsMetricValue('My-Event', 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's just about casing, the value should be the same, otherwise it collides with the test above

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, fixed

@just-boris just-boris requested a review from Al-Dani June 18, 2025 13:32
@just-boris just-boris enabled auto-merge June 18, 2025 15:16
@just-boris just-boris added this pull request to the merge queue Jun 18, 2025
Merged via the queue into main with commit b420fe8 Jun 18, 2025
36 checks passed
@just-boris just-boris deleted the metrics-refactor branch June 18, 2025 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants