Repository navigation
Conversation
Coverage report
Test suite run success763 tests passing in 24 suites. Report generated by 🧪jest coverage report action from 48f09e2 |
There was a problem hiding this comment.
🟡 Changes recommended
Documentation contains a broken startup-method reference and an outdated claim that load() is called only once.
1 open issue
What changed in this PR
This pull request improves AWS RUM startup resilience and Angular integration by retrying failed credential requests, running initialization outside Angular’s zone, and preserving sign-out intent until startup completes.
Changes:
- Adds bounded startup retries with event buffering and failure handling.
- Runs RUM initialization and related timers outside Angular’s zone.
- Applies pending sign-outs when the client starts.
- Updates tests and documentation for retry, session, cookie, and provider behavior.
| File | Description |
|---|---|
projects/ngx-ui-watchtower/rum/src/lib/uwt-rum-telemetry.sink/uwt-rum-telemetry.sink.ts |
Adds startup retries, zone-neutral initialization, and deferred sign-out handling. |
projects/ngx-ui-watchtower/rum/src/lib/uwt-rum-telemetry.sink/uwt-rum-telemetry.sink.spec.ts |
Tests retry behavior, retry limits, destruction, zone execution, and deferred sign-out. |
projects/ngx-ui-watchtower/rum/src/lib/uwt-rum-credentials/uwt-rum-credentials.ts |
Updates session, cookie, and credential-provider contract documentation. |
projects/ngx-ui-watchtower/README.md |
Updates the credentials-provider example to throw on failed requests. |
projects/ngx-ui-watchtower/DESIGN.md |
Documents retry, session, cookie, sign-out, and zone behavior. |
Review effort: Lite
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…rt-up-turns-rum-off-for-the-whole-page
| left collecting with stale credentials. | ||
|
|
||
| Throwing means the request failed, not that telemetry is unwanted. The sink | ||
| tries again every 30 seconds — at startup, keeping events buffered meanwhile, |
There was a problem hiding this comment.
Wouldn’t exponential backoff with jitter be better than a constant 30 s retry interval? The SDK only starts capturing errors and failed HTTP calls once the client exists, so a one-second broker blip currently costs at least 30 secs of that data. Jitter would also keep tabs from retrying in lockstep after a mass reload during an outage.
There was a problem hiding this comment.
Great suggestion. Now we retry with exponential backoff from 1 to 60 seconds, and give up after 5 minutes.
| if (this.awsRum) { | ||
| this.awsRum.startSession({ userId: uwtUuid() }); | ||
| } else { | ||
| this.signOutPending = true; |
There was a problem hiding this comment.
This also fires on the initial undefined most auth streams emit (user$.pipe(map(u => u?.id))), so every page load ends in startSession(). That means an extra session_start, re-rolled sampling and no session continuity.
Could we only start a new session on a real signed-in → signed-out transition (no-op if there was no previous userId)? Plus a test: setUserId(undefined) before init, then init() → startSession not called.
There was a problem hiding this comment.
Good catch. setUserId(undefined) / '' now starts a new session only on a real signed-in → signed-out transition; with no previous userId it's a no-op, so an auth stream's initial undefined (and any repeat) leaves the session alone. A real sign-out made before init is still applied once the client starts.
Also added two related updates:
- The SDK reads the user id when it sends a batch, not when it records, so on a user change the sink first sends what's waiting under the old id (skipped when the client already has the new id, e.g. after a reload).
- Every event now carries
signedInproperty in its metadata (absent until the app's firstsetUserId), since anonymous ids and MSAL ids are both UUIDs and can't otherwise be distinguished.
…rt-up-turns-rum-off-for-the-whole-page
…rt-up-turns-rum-off-for-the-whole-page
…d-broker-request-at-start-up-turns-rum-off-for-the-whole-page
There was a problem hiding this comment.
🟡 Changes recommended
Critical attribution bugs remain: buffered events can inherit later authentication state, and a restored SDK user ID may survive initial sign-out, misattributing telemetry across sessions.
2 open issues
1 resolved since last review
Review effort: Lite
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because constructor-time SDK events can bypass the metadata hook, creating a potential conflict with the documented guarantee for early signed-in state propagation.
No open issues 🎉
2 resolved since last review
Review effort: Lite


Overview
A failed broker request at start-up no longer switches RUM off for the page. The sink retries with backoff and jitter, keeping events buffered. The RUM client and the sink's timers now run outside Angular's zone. User attribution is fixed: signing out while nobody is signed in no longer starts a new session, events no longer go out under the wrong user around a sign-in or sign-out, and every event says whether a user is signed in.
Key Changes
UwtRumTelemetrySink):load()throws, the sink waits a random time up to a limit that starts at 1 s and doubles after each failure, up to 60 s, keeping events buffered (at most 100);init()runs insideNgZone.runOutsideAngular, so the SDK's dispatch interval and the sink's retry and refresh timers no longer keep a zone-based app from becoming stable. This fixes an older bug.setUserId(undefined)orsetUserId('')starts a new session only when a user was signed in. Repeating it, or an auth stream's initialundefined, does nothing. A real sign-out made before the client starts is applied once it does; a sign-in in the meantime cancels it.signedInon every event: event metadata carriessignedIn: true | false, so a real user id can be told from an anonymous one; both are UUIDs. It is absent until the app's firstsetUserIdcall.signedIn, the UUID requirement for user ids, cookies and theload()contract.Impact on consumers
setUserId(undefined)at startup or on every auth emission no longer get a new session and a new anonymous user id each time.signedIn. CallsetUserIdearly, e.g. right after MSAL initializes, so no event goes out without it.localAccountId, nothomeAccountId. This was always the case; it's now documented.nullon a failed request behave as before: RUM off for the page. Switch them to throwing to get the retry.Closes #17