Skip to content

Commit e3571df

Browse files
authored
refactor: move the AWS RUM sink into the core's rum entry point (#50)
1 parent 9a55281 commit e3571df

31 files changed

Lines changed: 2559 additions & 1480 deletions

‎.eslintrc.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,31 @@ module.exports = {
6868
]
6969
}
7070
},
71+
{
72+
// The core's AWS RUM entry point: aws-rum-web, and still no framework.
73+
files: ['projects/ui-watchtower/rum/**/*.ts'],
74+
rules: {
75+
'no-restricted-imports': [
76+
'error',
77+
{
78+
patterns: [
79+
{
80+
group: [
81+
'@angular/*',
82+
'zone.js',
83+
'@absaoss-cps/ngx-ui-watchtower',
84+
'@absaoss-cps/ngx-ui-watchtower/*',
85+
'rxjs',
86+
'rxjs/*'
87+
],
88+
message:
89+
'The core is framework-independent, and this entry point loads no other optional peer.'
90+
}
91+
]
92+
}
93+
]
94+
}
95+
},
7196
{
7297
// The core's RxJS entry point: RxJS, and still no framework.
7398
files: ['projects/ui-watchtower/rxjs/**/*.ts'],

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ How it is designed: [projects/ngx-ui-watchtower/DESIGN.md](projects/ngx-ui-watch
2424
projects/ui-watchtower/
2525
src/ @absaoss-cps/ui-watchtower — the framework-independent engine
2626
rxjs/ secondary entry point — @absaoss-cps/ui-watchtower/rxjs
27+
rum/ secondary entry point — @absaoss-cps/ui-watchtower/rum
2728
type-tests/ consumer type tests, without a framework
2829
README.md usage guide, published to npm
2930
package.json the published package's manifest

‎jest.config.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module.exports = {
77
'<rootDir>/projects/ui-watchtower/src/public-api.ts',
88
'^@absaoss-cps/ui-watchtower/rxjs$':
99
'<rootDir>/projects/ui-watchtower/rxjs/src/public-api.ts',
10+
'^@absaoss-cps/ui-watchtower/rum$':
11+
'<rootDir>/projects/ui-watchtower/rum/src/public-api.ts',
1012
'^@absaoss-cps/ngx-ui-watchtower$':
1113
'<rootDir>/projects/ngx-ui-watchtower/src/public-api.ts',
1214
'^@absaoss-cps/ngx-ui-watchtower/rum$':
@@ -34,5 +36,8 @@ module.exports = {
3436
'!projects/**/public-api.ts',
3537
// Compiled by the typecheck, never run.
3638
'!projects/**/type-tests/**'
37-
]
39+
],
40+
coverageThreshold: {
41+
global: { statements: 90, branches: 90, functions: 90, lines: 90 }
42+
}
3843
};

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint": "eslint \"**/*.ts\" --max-warnings=0",
1212
"format": "prettier --write \"**/*.{ts,mjs,html}\"",
1313
"format:check": "prettier --check \"**/*.{ts,mjs,html}\"",
14-
"typecheck": "tsc -p projects/ui-watchtower/tsconfig.lib.json --noEmit && tsc -p projects/ui-watchtower/rxjs/tsconfig.lib.json --noEmit && tsc -p projects/ui-watchtower/tsconfig.spec.json --noEmit && tsc -p projects/ui-watchtower/type-tests/tsconfig.json && tsc -p projects/ui-watchtower/type-tests/tsconfig.augmented.json && ng build --configuration=production --project=ui-watchtower && tsc -p projects/ngx-ui-watchtower/tsconfig.lib.json --noEmit && tsc -p projects/ngx-ui-watchtower/tsconfig.spec.json --noEmit && tsc -p projects/ngx-ui-watchtower/rum/tsconfig.lib.json --noEmit && tsc -p projects/ngx-ui-watchtower/rum/tsconfig.spec.json --noEmit && ngc -p projects/ngx-ui-watchtower/type-tests/tsconfig.json && ngc -p projects/ngx-ui-watchtower/type-tests/tsconfig.augmented.json",
14+
"typecheck": "tsc -p projects/ui-watchtower/tsconfig.lib.json --noEmit && tsc -p projects/ui-watchtower/rxjs/tsconfig.lib.json --noEmit && tsc -p projects/ui-watchtower/rum/tsconfig.lib.json --noEmit && tsc -p projects/ui-watchtower/tsconfig.spec.json --noEmit && tsc -p projects/ui-watchtower/type-tests/tsconfig.json && tsc -p projects/ui-watchtower/type-tests/tsconfig.augmented.json && ng build --configuration=production --project=ui-watchtower && tsc -p projects/ngx-ui-watchtower/tsconfig.lib.json --noEmit && tsc -p projects/ngx-ui-watchtower/tsconfig.spec.json --noEmit && tsc -p projects/ngx-ui-watchtower/rum/tsconfig.lib.json --noEmit && tsc -p projects/ngx-ui-watchtower/rum/tsconfig.spec.json --noEmit && ngc -p projects/ngx-ui-watchtower/type-tests/tsconfig.json && ngc -p projects/ngx-ui-watchtower/type-tests/tsconfig.augmented.json",
1515
"api:check": "npm run build && node scripts/api-snapshot.mjs",
1616
"api:update": "npm run build && node scripts/api-snapshot.mjs --update"
1717
},

‎projects/ngx-ui-watchtower/DESIGN.md‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,16 @@ providers: [
229229
broadcast plumbing stay internal so they can change freely. Redaction is
230230
the exception: a custom sink needs `uwtRedactMetadata`,
231231
`uwtNormalizeError`, `uwtScrubString` and `uwtRedactConfigFor`.
232+
- **The RUM sink is the core's too.** Its logic — the lazy `aws-rum-web`
233+
import, startup retries, credential refresh, the pre-init buffer, the
234+
settings check — lives in `@absaoss-cps/ui-watchtower/rum`. This package's
235+
`/rum` keeps `UWT_RUM_CREDENTIALS_PROVIDER`, `provideUwtTelemetryRumSink()`
236+
and `UwtRumTelemetrySink`, an injectable subclass of the core's.
232237
- **The secondary entry keeps private copies of a few utilities.** ng-packagr
233238
fixes each entry point's `rootDir` to its own `src`, so
234239
`@absaoss-cps/ngx-ui-watchtower/rum` can't import the main entry's
235-
internals by relative path and carries small copies of what it needs.
240+
internals by relative path and carries small copies of what it needs: its
241+
Angular helpers and the reporter.
236242
- **Test doubles live in the specs that use them**, declared inline, never in
237243
a shared file and never exported. The one browser gap needing a stub is
238244
`BroadcastChannel`, which jsdom doesn't implement.
@@ -1608,12 +1614,15 @@ convention, for an application that wants the pre-fallback behavior back.
16081614
## 11. Error handling and performance
16091615

16101616
- **Telemetry never breaks the application.** Every public entry point is
1611-
wrapped and never rethrows. The core prints nothing by itself: it hands a
1612-
suppressed error, or data it had to drop, to the `UwtReporter` it is
1613-
given. This package gives it one that writes to the console, prefixed
1617+
wrapped and never rethrows. The core hands a suppressed error (`'error'`),
1618+
or data it had to drop (`'warn'`), to the `UwtReporter` it is given. This
1619+
package gives it one that writes to the console, prefixed
16141620
`[ngx-ui-watchtower]`, in development mode only, so bugs surface in
1615-
development and production stays silent. Even a broken `console.error`
1616-
cannot turn a suppressed failure into a throw.
1621+
development and production stays silent. What cannot work as configured
1622+
(`'config'`) — a second broadcast host, a host in a forwarding realm, RUM
1623+
settings of the wrong type — is printed in production too, as it always
1624+
was; without a reporter, the core prints it itself. Even a broken
1625+
`console.error` cannot turn a suppressed failure into a throw.
16171626
- **Fail-open.** A broker outage, expired credentials or an SDK throw all
16181627
leave the application behaving exactly as with healthy telemetry. A failed
16191628
broker request at startup is retried with backoff for five minutes. A

‎projects/ngx-ui-watchtower/public-api.snapshot.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@
541541
"UwtRumTelemetrySink": [
542542
"class",
543543
"new (): UwtRumTelemetrySink",
544+
"dispose(): void",
544545
"flush(beacon?: boolean | undefined): void",
545546
"getSessionId(): string | undefined",
546547
"getUserId(): string | undefined",

0 commit comments

Comments
 (0)