feat(cc-ui-logging): add PROPS_UPDATED event logging with propsToWatch filter#656
feat(cc-ui-logging): add PROPS_UPDATED event logging with propsToWatch filter#656bhabalan wants to merge 2 commits intowebex:nextfrom
Conversation
…h filter Adds prop change tracking to the withMetrics HOC. A new optional propsToWatch parameter allows components to specify which props should trigger PROPS_UPDATED metric events, filtering out noisy props like timers. Includes getChangedWatchedProps utility that reports old/new values for changed watched props. CAI-6890
| @@ -1,5 +1,5 @@ | |||
| import store from '@webex/cc-store'; | |||
| import {logMetrics, havePropsChanged, WidgetMetrics} from '../src/metricsLogger'; | |||
| import {logMetrics, havePropsChanged, getChangedWatchedProps, WidgetMetrics} from '../src/metricsLogger'; | |||
There was a problem hiding this comment.
Add more comprehensive tests
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a215fab2ca
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| for (const key of propsToWatch) { | ||
| if (prev[key] !== next[key]) { | ||
| changes[key] = {oldValue: prev[key], newValue: next[key]}; |
There was a problem hiding this comment.
Sanitize watched prop values before logging metrics
getChangedWatchedProps stores raw oldValue/newValue objects, and withMetrics forwards that payload to logMetrics, which serializes with JSON.stringify. If a watched prop contains a circular or otherwise non-serializable value (common for SDK/model objects), JSON.stringify throws inside the effect, causing runtime errors instead of emitting metrics. This new PROPS_UPDATED path should sanitize or safely serialize watched values before calling logMetrics.
Useful? React with 👍 / 👎.
|
This pull request is automatically being deployed by Amplify Hosting (learn more). |
…thMetrics Add edge case tests for havePropsChanged (same reference, null/object transitions, empty objects, function references, undefined values) and getChangedWatchedProps (undefined transitions, boolean/numeric props, partial changes, null inputs). Add withMetrics tests for multiple watched props, cross-render tracking, first-render behavior, and different widget names. CAI-6890
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0a85385984
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| useEffect(() => { | ||
| if (prevPropsRef.current && propsToWatch.length > 0) { | ||
| const changes = getChangedWatchedProps( | ||
| prevPropsRef.current as Record<string, any>, | ||
| props as Record<string, any>, |
There was a problem hiding this comment.
Emit watched object prop changes even when memo skips render
This PROPS_UPDATED logic only runs inside an effect after the wrapped component renders, but withMetrics is still memoized with havePropsChanged, which treats object-to-object prop changes as unchanged. In practice, if a watched prop is an object (for example task or agent) and its reference changes between renders, React.memo can skip the render and this effect never runs, so the new feature silently misses updates for watched object props.
Useful? React with 👍 / 👎.
COMPLETES
https://jira-eng-sjc12.cisco.com/jira/browse/CAI-6890
This pull request addresses
The widgets metrics system records mount and unmount events but does not track prop changes. We need to log a PROPS_UPDATED event when important props change, while filtering out noisy props like timers that would pollute the logs.
by making the following changes
getChangedWatchedProps()utility that compares previous and current props, checking only the specifiedpropsToWatchkeys, and returns a record of changed prop keys with their old/new valueswithMetricsHOC to accept an optionalpropsToWatchparameter. Uses auseRefto track previous props and logsPROPS_UPDATEDevents only when watched props change. Backward compatible — existing usages withoutpropsToWatchare unaffectedgetChangedWatchedPropsand 3 new tests forwithMetricsPROPS_UPDATED behaviorChange Type
The following scenarios were tested
The GAI Coding Policy And Copyright Annotation Best Practices
Checklist before merging
Make sure to have followed the contributing guidelines before submitting.