Skip to content

fix: drop RUM config values that would make aws-rum-web throw - #23

Open
fateeand wants to merge 11 commits into
mainfrom
fix-drop-rum-config-vals
Open

fateeand wants to merge 11 commits into
mainfrom
fix-drop-rum-config-vals

Conversation

@fateeand

@fateeand fateeand commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

A string where aws-rum-web expects a RegExp or a function (typically from a broker's JSON) no longer breaks the host app. The RUM sink checks those settings before loading the SDK and fails closed: if one has the wrong type, RUM doesn't start for the page, and a console warning names the setting and the type it expects.

Key Changes

  • Config check (UwtRumTelemetrySink.performInit):
    • checks pagesToInclude/pagesToExclude (array of RegExp) and, inside telemetries, urlsToInclude/urlsToExclude (array of RegExp), addXRayTraceIdHeader (boolean or array of RegExp), and ignore/interactionId (function);
    • fails closed: any wrong type means RUM stays off for the page, as with a broker returning null. Dropping just the bad value would fail open: the filters and ignore decide what is not recorded, so RUM would record pages and URLs the app meant to keep out;
    • warns in every environment, not just dev mode, naming each setting and its expected type, never the value;
    • treats an explicit undefined as unset, and strips undefined telemetry options before they reach the SDK, whose Object.assign merge would otherwise replace a default with undefined and throw.
  • Tests (uwt-rum-telemetry.sink.spec.ts):
    • wrong-typed telemetry options and page filters stop RUM, with the exact warning;
    • valid RegExps, functions and booleans are passed through, with no warning;
    • undefined options are treated as unset (strict equality).
  • API docs: UwtRumAppMonitorConfig.telemetries, pagesToInclude and pagesToExclude describe the check.
  • README and DESIGN: the credentials and advanced-config examples say that settings needing a RegExp or a function belong in code. DESIGN explains why the sink fails closed.

Impact on consumers

  • No API change. Valid configuration behaves exactly as before.
  • Apps sending one of these settings with the wrong type used to break: requests or navigation threw. Now RUM stays off for that page, and the console says which setting to fix and what type it needs. Set it in code.

Closes #22

@fateeand fateeand linked an issue Oct 26, 2026 that may be closed by this pull request
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

St.❔
Category Percentage Covered / Total
🟢 Statements
97.06% (-0.05% 🔻)
1322/1362
🟢 Branches
95.23% (-0.04% 🔻)
738/775
🟢 Functions
97.03% (+0.08% 🔼)
327/337
🟢 Lines
97.41% (-0.07% 🔻)
1279/1313
Show files with reduced coverage 🔻
St.❔
File Statements Branches Functions Lines
🟢
... / uwt-rum-telemetry.sink.ts
95.76% (-0.07% 🔻)
92.52% (+0.55% 🔼)
94.83% (+0.95% 🔼)
96.96% (-0.36% 🔻)

Test suite run success

747 tests passing in 24 suites.

Report generated by 🧪jest coverage report action from 23860a1

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

An explicit undefined option is wrongly reported as dropped, and the fail-open handling of exclusion filters needs a decision before merge.

4 open issues
What changed in this PR

This PR stops a common configuration failure in the RUM (real user monitoring) sink. Broker JSON cannot carry RegExp or function values, and a string in their place made the AWS RUM SDK throw on requests or navigation. The sink now drops such values before the SDK sees them, so the SDK's default applies, and it logs a dev-mode warning naming what was dropped. The PR also corrects several README and DESIGN examples.

Changes:

  • The sink checks telemetries options, pagesToInclude and pagesToExclude before passing them on, and drops values of the wrong type.
  • Tests cover dropped string options, kept valid values, and a dropped string page filter.
  • API docs, the README, and DESIGN.md explain what is dropped, and update the logging, batching, and fragment-channel examples.
File Description
projects/​ngx-ui-watchtower/​rum/​src/​lib/​uwt-rum-telemetry.sink/​uwt-rum-telemetry.sink.ts Adds the option checks and drops wrong-typed values with a single dev-mode warning.
projects/​ngx-ui-watchtower/​rum/​src/​lib/​uwt-rum-telemetry.sink/​uwt-rum-telemetry.sink.spec.ts Adds tests for dropped strings, kept valid values, and dropped string page filters.
projects/​ngx-ui-watchtower/​rum/​src/​lib/​uwt-rum-credentials/​uwt-rum-credentials.ts Documents which telemetry and page-filter options are dropped and why.
projects/​ngx-ui-watchtower/​README.md Says settings needing a RegExp or function belong in code, and limits keepalive to the hidden page.
projects/​ngx-ui-watchtower/​DESIGN.md Updates the credentials, logging, batching, and fragment-channel examples to match the new behavior.

Review effort: Lite

Comment thread projects/ngx-ui-watchtower/DESIGN.md Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The PR description and linked issue still describe the old drop-and-warn behavior, and the warning text and docs need fixes before merge.

2 open issues
1 previously missed issue

In code that hasn't changed since last review

Low severity Document fail-closed behavior for invalid configuration

projects/​ngx-ui-watchtower/​rum/​src/​lib/​uwt-rum-telemetry.sink/​uwt-rum-telemetry.sink.ts:251

The PR description and issue #22 describe dropping the invalid value so the SDK default applies, with a dev-mode-only warning. The code instead keeps RUM off for the page and warns in every environment. The README, DESIGN.md, the API docs and the review-thread replies all match the code, so update the PR description's Key Changes, Tests and Impact on consumers sections, and the issue's expected behavior, to describe this fail-closed behavior.

4 resolved since last review

Review effort: Lite

Comment thread projects/ngx-ui-watchtower/DESIGN.md Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The handling of JSON null changes whether RUM starts on production pages, and a maintainer still needs to decide it.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Clarify null handling for optional configuration fields

projects/​ngx-ui-watchtower/​rum/​src/​lib/​uwt-rum-telemetry.sink/​uwt-rum-telemetry.sink.ts:141

null is treated as invalid here and at line 155, but the rest of this sink treats null as unset (config.endpoint ??, config.telemetries ??, config.allowCookies ?? true). A broker that sends unset optional fields as JSON null will turn RUM off for every page, and omitUndefined keeps null rather than dropping it. This needs a maintainer decision. If null means unset, skip it in this check and drop it in omitUndefined and withoutUndefinedOptions. If null is invalid, state in the API docs and DESIGN.md that brokers must omit the key.

Low severity Correct keepalive comment for hidden background tabs

projects/​ngx-ui-watchtower/​DESIGN.md:1709

The comment says keepalive is used "only while the page is going away", but the condition document.visibilityState === 'hidden' also matches a backgrounded tab that is not unloading. Reword the comment to say keepalive applies only while the page is hidden. Same issue in README.md:113-115.

2 resolved since last review

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The change alters production RUM startup and privacy-related page filtering, and the unchecked telemetries shape still needs a fix.

2 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Validate telemetries shape before iterating

projects/​ngx-ui-watchtower/​rum/​src/​lib/​uwt-rum-telemetry.sink/​uwt-rum-telemetry.sink.ts:146

telemetries is never checked for its shape. A non-iterable value (a number, true, or a JSON object) makes this for...of throw, and performInit()'s catch only reports through reportFailure, which returns early outside dev mode, so production stays silently off. A string such as "errors" iterates character by character without being flagged, and buildRumConfig() then passes it to the SDK unchanged. Check the shape up front and report it like the other settings.

Review effort: Lite

Comment thread projects/ngx-ui-watchtower/DESIGN.md Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

It changes whether production RUM starts and which pages it records, and the tests and type check could not be run in this review.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Low severity Check current window before traversing parent windows

projects/​ngx-ui-watchtower/​DESIGN.md:2362

The new shellChannelName() never checks the fragment's own window. The loop starts at window but moves to w.parent before reading, so when the fragment runs in the shell's own window, the loop never runs and the shell's channel is never read. The previous window.top lookup did find it. Check the current window first, then climb through parent until it stops changing. This is a docs-only bug; the library code is unaffected.

Low severity Correct setting problem output documentation and parameter name

projects/​ngx-ui-watchtower/​rum/​src/​lib/​uwt-rum-telemetry.sink/​uwt-rum-telemetry.sink.ts:672

The JSDoc says only setting names are printed, but each entry also includes its expected type, for example pagesToExclude (expected an array of RegExp). The parameter names has the same mismatch. Say that each setting's name and expected type are printed, never its value, and rename the parameter to problems.

2 resolved since last review

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

It changes RUM startup gating and privacy-sensitive filter behavior, so a person should confirm the behavior change for apps with misconfigured settings.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Low severity Correct invalid page filter wording to session scope

projects/​ngx-ui-watchtower/​rum/​src/​lib/​uwt-rum-credentials/​uwt-rum-credentials.ts:237

Invalid pagesToInclude or pagesToExclude values keep RUM from starting "for the page", but the sink disables RUM for the rest of the session, as it does for a null from the provider. The same wrong wording appears in uwt-rum-credentials.ts:109, uwt-rum-telemetry.sink.ts:268-271, and the README and DESIGN additions. Change all of them to "for the session".

Low severity Clarify buildRumConfig documentation covers only checked settings

projects/​ngx-ui-watchtower/​rum/​src/​lib/​uwt-rum-telemetry.sink/​uwt-rum-telemetry.sink.ts:481

The buildRumConfig doc says "Values the SDK can't use never get here", but performInit() only checks the page filters, the telemetries shape, and the telemetry options in TELEMETRY_OPTION_CHECKS. Other settings, such as sessionSampleRate, pass through unchecked. Name the checked settings in the doc so it doesn't promise more than the check does.

Review effort: Lite

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Docs changes (keepalive/sendBeacon, window.top to ancestor-walk change) seem to be unrelated to the PR's scope, they deserve their own PR.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done: #33

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.

RUM config from a broker's JSON can make every app request throw

3 participants