@utk09/ui-observability 0.4.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +114 -59
  3. package/dist/bus/bus.d.ts +10 -10
  4. package/dist/bus/links.d.ts +1 -1
  5. package/dist/bus-BTMuVkDk.js +378 -0
  6. package/dist/bus-BTMuVkDk.js.map +1 -0
  7. package/dist/bus-ChIXDAWD.cjs +2 -0
  8. package/dist/bus-ChIXDAWD.cjs.map +1 -0
  9. package/dist/capture/network.d.ts +2 -2
  10. package/dist/capture/types.d.ts +10 -10
  11. package/dist/capture/web-vitals.d.ts +7 -4
  12. package/dist/{constants-DVbpJ1tv.js → constants-0-YchbAL.js} +9 -8
  13. package/dist/constants-0-YchbAL.js.map +1 -0
  14. package/dist/constants-TUFcy95w.cjs +2 -0
  15. package/dist/constants-TUFcy95w.cjs.map +1 -0
  16. package/dist/constants.d.ts +55 -40
  17. package/dist/core/breadcrumbs.d.ts +14 -14
  18. package/dist/core/config.d.ts +5 -4
  19. package/dist/core/context.d.ts +2 -2
  20. package/dist/core/diagnostics.d.ts +10 -9
  21. package/dist/core/journey.d.ts +28 -22
  22. package/dist/core/logger.d.ts +29 -10
  23. package/dist/core/pipeline.d.ts +34 -29
  24. package/dist/core/record.d.ts +6 -6
  25. package/dist/core/runtime.d.ts +119 -35
  26. package/dist/core/sampling.d.ts +15 -16
  27. package/dist/core/sender.d.ts +58 -0
  28. package/dist/errors-DRXBRqvm.cjs +3 -0
  29. package/dist/errors-DRXBRqvm.cjs.map +1 -0
  30. package/dist/errors-Dwm2SzBa.js +76 -0
  31. package/dist/errors-Dwm2SzBa.js.map +1 -0
  32. package/dist/index.cjs +1 -3
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.ts +6 -5
  35. package/dist/index.js +476 -2247
  36. package/dist/index.js.map +1 -1
  37. package/dist/indexeddb-storage-B5dwq4hW.cjs +2 -0
  38. package/dist/indexeddb-storage-B5dwq4hW.cjs.map +1 -0
  39. package/dist/{indexeddb-storage-B6uqejZb.js → indexeddb-storage-DjY4Ml6t.js} +18 -22
  40. package/dist/indexeddb-storage-DjY4Ml6t.js.map +1 -0
  41. package/dist/interactions-DVom6eYn.cjs +2 -0
  42. package/dist/interactions-DVom6eYn.cjs.map +1 -0
  43. package/dist/interactions-DZmLu7l2.js +67 -0
  44. package/dist/interactions-DZmLu7l2.js.map +1 -0
  45. package/dist/models/batch.d.ts +12 -9
  46. package/dist/models/bus.d.ts +12 -13
  47. package/dist/models/config.d.ts +84 -49
  48. package/dist/models/log-record.d.ts +12 -10
  49. package/dist/models/serializer.d.ts +3 -2
  50. package/dist/models/storage.d.ts +2 -2
  51. package/dist/network-C4d2uw2Z.js +111 -0
  52. package/dist/network-C4d2uw2Z.js.map +1 -0
  53. package/dist/network-CuqWadNn.cjs +2 -0
  54. package/dist/network-CuqWadNn.cjs.map +1 -0
  55. package/dist/platform-CXio0W2n.cjs +2 -0
  56. package/dist/platform-CXio0W2n.cjs.map +1 -0
  57. package/dist/platform-CY8S3hUs.js +48 -0
  58. package/dist/platform-CY8S3hUs.js.map +1 -0
  59. package/dist/sampling-CEthcmEX.cjs +2 -0
  60. package/dist/sampling-CEthcmEX.cjs.map +1 -0
  61. package/dist/sampling-CJsI_24L.js +251 -0
  62. package/dist/sampling-CJsI_24L.js.map +1 -0
  63. package/dist/sender-ByFAkXVd.cjs +3 -0
  64. package/dist/sender-ByFAkXVd.cjs.map +1 -0
  65. package/dist/sender-dpvR_bHM.js +907 -0
  66. package/dist/sender-dpvR_bHM.js.map +1 -0
  67. package/dist/storage/emergency-queue.d.ts +2 -2
  68. package/dist/storage/factory.d.ts +2 -1
  69. package/dist/storage/idb-driver.d.ts +19 -19
  70. package/dist/storage/indexeddb-storage.d.ts +18 -17
  71. package/dist/storage/keys.d.ts +1 -1
  72. package/dist/storage/local-storage.d.ts +19 -18
  73. package/dist/storage/memory-storage.d.ts +12 -11
  74. package/dist/transport/compression.d.ts +2 -2
  75. package/dist/transport/errors.d.ts +8 -7
  76. package/dist/transport/exit-flush.d.ts +27 -24
  77. package/dist/transport/http-transport.d.ts +19 -10
  78. package/dist/transport/retry-engine.d.ts +33 -28
  79. package/dist/transport/serializers/ecs.d.ts +1 -1
  80. package/dist/transport/serializers/otlp.d.ts +1 -1
  81. package/dist/transport/serializers/select.d.ts +8 -0
  82. package/dist/unref-16maCyKA.js +8 -0
  83. package/dist/unref-16maCyKA.js.map +1 -0
  84. package/dist/unref-CU9Nyz_9.cjs +2 -0
  85. package/dist/unref-CU9Nyz_9.cjs.map +1 -0
  86. package/dist/utils/console.d.ts +11 -3
  87. package/dist/utils/identity.d.ts +53 -8
  88. package/dist/utils/lock.d.ts +4 -4
  89. package/dist/utils/platform.d.ts +5 -3
  90. package/dist/utils/sanitize.d.ts +5 -2
  91. package/dist/utils/sequence.d.ts +2 -2
  92. package/dist/utils/tracing.d.ts +14 -12
  93. package/dist/web-vitals-B2FYsEAU.cjs +2 -0
  94. package/dist/web-vitals-B2FYsEAU.cjs.map +1 -0
  95. package/dist/web-vitals-DHZ0yA_H.js +51 -0
  96. package/dist/web-vitals-DHZ0yA_H.js.map +1 -0
  97. package/package.json +21 -11
  98. package/dist/constants-DVbpJ1tv.js.map +0 -1
  99. package/dist/constants-tQpoTzkY.cjs +0 -2
  100. package/dist/constants-tQpoTzkY.cjs.map +0 -1
  101. package/dist/indexeddb-storage-B6uqejZb.js.map +0 -1
  102. package/dist/indexeddb-storage-CgT1GLYj.cjs +0 -2
  103. package/dist/indexeddb-storage-CgT1GLYj.cjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,69 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4
4
 
5
+ ## [0.6.0] - 2026-10-11
6
+
7
+ ### Breaking changes - v0.6.0
8
+
9
+ - Each diagnostic message, `TransportError` message and IndexedDB error message is a complete sentence. For example, "server throttled us" is now "The server throttles the requests." Filter on `event.code`, not on `event.message`.
10
+
11
+ ### Added - v0.6.0
12
+
13
+ - The diagnostic code `platform.api_blocked` counts a browser API that a sandbox or a cross-origin boundary blocks. This includes `crypto.randomUUID`, `window.top` and `location.href`.
14
+ - `getDiagnosticCounters()["record.sanitize_failed"]` counts each value that throws during sanitization, for example a hostile getter.
15
+
16
+ ### Changed - v0.6.0
17
+
18
+ - The comments, the JSDoc in the `.d.ts` files and the README follow ASD-STE100.
19
+ - The `BusMode` JSDoc said that `off` "does neither". With `off`, the context delivers its own records.
20
+
21
+ ## [0.5.0] - 2026-10-11
22
+
23
+ ### Breaking changes - v0.5.0
24
+
25
+ - The library does not import `@opentelemetry/api` by itself. Set `otelLoader` to put records on your spans. Without `otelLoader`, OTel is off. The library reports no diagnostic.
26
+ - `capture.webVitals` needs `capture.webVitalsLoader`. Without the loader, the library reports `config.invalid`. Navigation timing continues.
27
+ - `console` does not depend on `minLevel`. `minLevel` limits what the library sends. `console` limits what it prints.
28
+ - A console line starts with the logger namespace, for example `[board.hop] WARN`. It started with `[ui-observability]`.
29
+ - A console line shows the caller's payload. It showed all record attributes.
30
+ - With a `redact` hook, the console shows only what `redact` returns. A record that the library does not build shows its message and error only.
31
+ - After `shutdown()`, every call does nothing until the next `configure()`. A log call after `shutdown()` started a new runtime with default settings.
32
+ - After the delivery stack loads, `configure({ endpoint: null })` and `configure({ endpoint: "" })` report `config.invalid`. The endpoint in force stays.
33
+ - `OneLogger` takes a function that returns the runtime. It took the runtime.
34
+
35
+ ```ts
36
+ // OpenTelemetry, imported by the library before 0.5.0
37
+ configure({ endpoint, otelLoader: () => import("@opentelemetry/api") });
38
+
39
+ // web vitals
40
+ configure({ endpoint, capture: { webVitals: true, webVitalsLoader: () => import("web-vitals") } });
41
+ ```
42
+
43
+ ### Added - v0.5.0
44
+
45
+ - `endpoint: null` selects console-only mode. The library sends nothing. It reports no diagnostic about the endpoint. A missing endpoint or `""` still reports `config.invalid`.
46
+ - `identity: "memory"` keeps session, tab and journey ids in memory. The library writes no key to `localStorage` or `sessionStorage` for them. You cannot change `identity` after startup.
47
+ - `npm run check:peers` fails if a built file imports an optional peer by name.
48
+
49
+ ### Fixed - v0.5.0
50
+
51
+ - The Vite dev server failed when a peer was not installed. `dist/index.js` imported `web-vitals` and `@opentelemetry/api` by name. Peers load only through the loaders.
52
+ - `getLogger()` before `configure()` started a runtime with default settings. That runtime refused a later `configure({ storage })`. A logger finds the runtime on its first write.
53
+ - A logger held across `shutdown()` wrote to the destroyed runtime. After the next `configure()`, it writes to the new runtime.
54
+ - `error(message, err, payload)` printed the error without the payload. The console line shows both.
55
+ - A `shutdown()` during startup still installed the capture modules. Their window listeners stayed until the page closed.
56
+ - `endpoint: undefined` in a later `configure()` removed the live endpoint. The endpoint in force now stays.
57
+ - The runtime dropped a forwarded record that arrived before the pipeline existed. The record now waits for the delivery stack.
58
+ - A `configure()` during startup did not apply to `endpoint` or `capture`. It applies now.
59
+ - A worker registered in a nested frame lost its handshake while the bus started. The runtime now attaches the worker when it constructs the bus.
60
+ - `flush()`, `getQueueDepth()` and `shutdown()` did not wait for a delivery stack that was still loading. They wait now.
61
+ - A `%o` or `%c` in a logger namespace changed the console output. The namespace now prints as text.
62
+ - A failed exit flush install left the retry loop running. The library now stops the retry loop.
63
+
64
+ ### Performance - v0.5.0
65
+
66
+ - The main chunk holds only the logger, the record builder and the console sink. The delivery stack loads only when you set an endpoint. The bus loads only when the context needs it. Each capture module loads only when you enable it. A console-only setup loads half the code of 0.4.1.
67
+
5
68
  ## [0.4.1] - 2026-09-09
6
69
 
7
70
  ### Fixed - v0.4.1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Structured logging and UI observability for browsers, embedded webviews and OpenFin containers. The library imports no framework.
4
4
 
5
- The library batches records and sends them over HTTP as OTLP/JSON. A failed send persists to storage and retries. A closing document flushes what is left. Iframes, workers and OpenFin windows share one sender through the bus. A log call never throws.
5
+ The library batches records and sends them over HTTP as OTLP/JSON. It stores a batch that fails to send, and sends it again later. When the page closes, the library sends the records that are left. Iframes, workers and OpenFin windows share one sender through the bus. A log call never throws.
6
6
 
7
7
  > **Status: early development.** A minor release can change a public API. Pin the exact version.
8
8
 
@@ -18,7 +18,7 @@ npm install @utk09/ui-observability
18
18
 
19
19
  Both peers are optional. The library has no runtime dependency.
20
20
 
21
- Install `web-vitals` (`^4 || ^5 || ^6`) for `capture.webVitals`:
21
+ Install `web-vitals` (`^4 || ^5 || ^6`) for `capture.webVitals`, and set `capture.webVitalsLoader`. Without the loader, the library reports `config.invalid`:
22
22
 
23
23
  ```ts
24
24
  configure({
@@ -30,7 +30,9 @@ configure({
30
30
  });
31
31
  ```
32
32
 
33
- Install `@opentelemetry/api` (`^1`) to put records on the traces your spans carry. Without it, the library mints its own `trace_id` and reports `trace.otel_failed` one time. The library imports the package when it is installed. Set `otelLoader` when your bundler cannot resolve the import:
33
+ Install `@opentelemetry/api` (`^1`) to put records on the traces of your spans. Set `otelLoader` to load it. Without `otelLoader`, OTel is off. The library then makes its own `trace_id`.
34
+
35
+ The library never imports a peer by name. A missing peer cannot break your bundler or your dev server.
34
36
 
35
37
  ```ts
36
38
  configure({
@@ -62,9 +64,32 @@ log.logAction("ORDER_SUBMIT", { orderId: "ORD-1001", qty: 100 });
62
64
  log.error("pricing call failed", caughtError);
63
65
  ```
64
66
 
65
- - `configure()` is idempotent. A later call updates the runtime singleton in place. `storage` is fixed at startup. A later change to it is reported and ignored.
66
- - One context per document calls `configure()`. A second call renames `service.name` on the records of every other context. In a composed page, the shell configures, and each microfrontend takes a namespace.
67
- - A log call before `configure()` goes to an implicit runtime. It does not throw.
67
+ - `configure()` is idempotent. A later call updates the runtime singleton in place. You cannot change `storage` or `identity` after startup. The library reports that change and ignores it.
68
+ - Call `configure()` from one context in each document. A second call changes `service.name` on the records of every other context. In a composed page, the shell calls `configure()`. Each microfrontend uses its own namespace.
69
+ - You can call `getLogger()` at module top level, before `configure()`. The logger finds the runtime on its first write.
70
+ - A write before the first `configure()` starts a runtime with default settings. It does not throw.
71
+ - After `shutdown()`, every call does nothing until the next `configure()`.
72
+
73
+ ### Console Only (No Network)
74
+
75
+ Set `endpoint: null`. The library sends nothing. It prints records to the console only.
76
+
77
+ ```ts
78
+ configure({
79
+ endpoint: null,
80
+ serviceName: "skardela",
81
+ identity: "memory",
82
+ storage: "none",
83
+ bus: { mode: "off" },
84
+ console: import.meta.env.DEV ? "DEBUG" : "WARN",
85
+ });
86
+ ```
87
+
88
+ - `endpoint: null` loads no transport, no storage and no exit flush. It reports no diagnostic.
89
+ - `identity: "memory"` writes no key to `localStorage` or `sessionStorage`.
90
+ - `console` and `minLevel` are independent. `console` sets what the library prints. `minLevel` sets what the library sends.
91
+ - The console output does not depend on the bus or the endpoint.
92
+ - With a `redact` hook, the console shows only what `redact` returns. A record below `minLevel` shows its message and error only, because the library does not build it.
68
93
 
69
94
  ---
70
95
 
@@ -72,26 +97,26 @@ log.error("pricing call failed", caughtError);
72
97
 
73
98
  ### Lifecycle & Setup
74
99
 
75
- | Function | Description |
76
- | ------------------- | -------------------------------------------------- |
77
- | `configure(config)` | Starts the runtime singleton, or updates it. |
78
- | `shutdown()` | Flushes pending records and stops every subsystem. |
100
+ | Function | Description |
101
+ | ------------------- | ----------------------------------------------------------------------------------------------------- |
102
+ | `configure(config)` | Starts the runtime singleton, or updates it. |
103
+ | `shutdown()` | Sends pending records and stops every subsystem. Later calls do nothing until the next `configure()`. |
79
104
 
80
105
  ### Logging Methods
81
106
 
82
- | Function | Description |
83
- | ---------------------------------------------- | --------------------------------------------------------------------------------------- |
84
- | `getLogger(namespace, options?)` | Returns the cached logger for a namespace. With `options`, returns a new one, uncached. |
85
- | `trace(msg, payload?)` | Logs a TRACE record. |
86
- | `debug(msg, payload?)` | Logs a DEBUG record. |
87
- | `info(msg, payload?)` | Logs an INFO record. |
88
- | `warn(msg, payload?)` | Logs a WARN record. |
89
- | `error(msg, err?, payload?)` | Logs an ERROR record with the error and the breadcrumb trail. |
90
- | `logAction(name, payload?)` | Logs one user action. |
91
- | `logEvent(name, payload?)` | Logs one domain or lifecycle event. |
92
- | `logMetric(name, value, unit?, type?, attrs?)` | Logs a measurement (`gauge`, `counter`, `histogram`). |
93
- | `timeSync(label, fn, attrs?)` | Times a function and emits a duration histogram. |
94
- | `timeAsync(label, fn, attrs?)` | Times a promise and emits a duration histogram. |
107
+ | Function | Description |
108
+ | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
109
+ | `getLogger(namespace, options?)` | Returns the cached logger for a namespace. With `options`, it returns a new logger that is not cached. |
110
+ | `trace(msg, payload?)` | Logs a TRACE record. |
111
+ | `debug(msg, payload?)` | Logs a DEBUG record. |
112
+ | `info(msg, payload?)` | Logs an INFO record. |
113
+ | `warn(msg, payload?)` | Logs a WARN record. |
114
+ | `error(msg, err?, payload?)` | Logs an ERROR record with the error and the breadcrumb trail. |
115
+ | `logAction(name, payload?)` | Logs one user action. |
116
+ | `logEvent(name, payload?)` | Logs one domain or lifecycle event. |
117
+ | `logMetric(name, value, unit?, type?, attrs?)` | Logs a measurement (`gauge`, `counter`, `histogram`). |
118
+ | `timeSync(label, fn, attrs?)` | Times a function and emits a duration histogram. |
119
+ | `timeAsync(label, fn, attrs?)` | Times a promise and emits a duration histogram. |
95
120
 
96
121
  ### Context & Correlation
97
122
 
@@ -121,32 +146,33 @@ log.error("pricing call failed", caughtError);
121
146
 
122
147
  ## Configuration Options
123
148
 
124
- `endpoint` is the only required key.
125
-
126
- | Key | Default | Description |
127
- | ---------------------------- | ------------ | --------------------------------------------------------------------------------- |
128
- | `endpoint` | _required_ | HTTP endpoint that receives the batches. |
129
- | `serviceName` | `""` | `service.name` on every record. |
130
- | `serviceVersion` | `""` | `service.version` on every record. |
131
- | `environment` | `""` | `deployment.environment` on every record. |
132
- | `enabled` | `true` | Kill switch. `false` makes every log call a no-op. |
133
- | `minLevel` | `"INFO"` | Lowest level that ships (`TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`). |
134
- | `compression` | `"gzip"` | `gzip` or `none`. It applies above 1 KB. |
135
- | `serializer` | `"otlp"` | `otlp`, `ecs`, or a custom `LogSerializer`. |
136
- | `credentials` | `"omit"` | Fetch credentials mode. Set `"include"` for cookie auth. |
137
- | `headers` | `{}` | Static headers, or a function that returns them. |
138
- | `storage` | `"auto"` | `auto`, `indexeddb`, `localstorage`, `memory` or `none`. Fixed at startup. |
139
- | `sampling.defaultRate` | `1` | Keep rate for a namespace with no rule. |
140
- | `sampling.rates` | `{}` | Keep rate per namespace. The longest matching prefix wins. |
141
- | `sampling.alwaysSampleTypes` | `["action"]` | Record types that ignore the rate. |
142
- | `bus.mode` | `"auto"` | `auto`, `sender`, `forwarder` or `off`. |
143
- | `bus.trustedOrigins` | `[]` | Origins that may post records from a cross-origin frame. |
144
- | `bus.openFinRole` | `"auto"` | `auto`, `provider` or `client`. |
145
- | `capture` | See below | Auto-capture settings. |
146
- | `console` | `false` | Mirrors records to devtools. `true` starts at `DEBUG`. A level name starts there. |
147
- | `otelLoader()` | `undefined` | Supplies `@opentelemetry/api`. Omit it and the library imports the package. |
148
- | `redact(record)` | `undefined` | Mutates a record before it ships. Return `null` to drop it. |
149
- | `onDiagnostic(event)` | `undefined` | Receives this library's own faults. |
149
+ No key is required. Set `endpoint` to send records.
150
+
151
+ | Key | Default | Description |
152
+ | ---------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
153
+ | `endpoint` | `""` | HTTP endpoint that receives the batches. `null` selects console-only mode. `""` reports `config.invalid`. |
154
+ | `serviceName` | `""` | `service.name` on every record. |
155
+ | `serviceVersion` | `""` | `service.version` on every record. |
156
+ | `environment` | `""` | `deployment.environment` on every record. |
157
+ | `enabled` | `true` | Set `false` to stop all logging. Every log call then does nothing. |
158
+ | `minLevel` | `"INFO"` | Lowest level that the library sends (`TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`). |
159
+ | `compression` | `"gzip"` | `gzip` or `none`. The library compresses a payload above 1 KB only. |
160
+ | `serializer` | `"otlp"` | `otlp`, `ecs`, or a custom `LogSerializer`. |
161
+ | `credentials` | `"omit"` | Fetch credentials mode. Set `"include"` for cookie auth. |
162
+ | `headers` | `{}` | Static headers, or a function that returns them. |
163
+ | `storage` | `"auto"` | Store for undelivered batches: `auto`, `indexeddb`, `localstorage`, `memory` or `none`. Fixed at startup. |
164
+ | `identity` | `"storage"` | Store for session, tab and journey ids. `memory` writes no key. Fixed at startup. |
165
+ | `sampling.defaultRate` | `1` | Keep rate for a namespace with no rule. |
166
+ | `sampling.rates` | `{}` | Keep rate per namespace. The longest matching prefix wins. |
167
+ | `sampling.alwaysSampleTypes` | `["action"]` | Record types that ignore the rate. |
168
+ | `bus.mode` | `"auto"` | `auto`, `sender`, `forwarder` or `off`. With `off`, this context sends its own records and opens no link. A same-origin child frame can still forward to it. |
169
+ | `bus.trustedOrigins` | `[]` | Origins that may post records from a cross-origin frame. |
170
+ | `bus.openFinRole` | `"auto"` | `auto`, `provider` or `client`. |
171
+ | `capture` | See below | Auto-capture settings. |
172
+ | `console` | `false` | Prints records to devtools. `true` prints from `DEBUG` up. A level name prints from that level up. It does not depend on `minLevel`. |
173
+ | `otelLoader()` | `undefined` | Loads `@opentelemetry/api`. Without it, OTel is off. |
174
+ | `redact(record)` | `undefined` | Changes a record before the library sends or prints it. Return `null` to drop the record. |
175
+ | `onDiagnostic(event)` | `undefined` | Receives the faults of the library itself. |
150
176
 
151
177
  ### Auto-Capture Options
152
178
 
@@ -166,31 +192,59 @@ capture: {
166
192
  }
167
193
  ```
168
194
 
169
- `fullUrls` is off. The library cuts a page URL, a request target and a failed resource URL at the first `?` or `#`. `ignoreUrls` and `propagateTraceHeaderTo` match the whole URL.
195
+ `fullUrls` is off by default. The library then cuts each recorded URL at the first `?` or `#`. This applies to the page URL, the request target and the URL of a failed resource. `ignoreUrls` and `propagateTraceHeaderTo` match the full URL.
196
+
197
+ ### Browser Storage Keys
198
+
199
+ | Key | Store | Written when | Option that stops it |
200
+ | ------------------------------ | ---------------- | ---------------------------------------------------------------- | --------------------------------------------- |
201
+ | `ui-observability.session` | `localStorage` | At startup, then at most one time each minute while logging | `identity: "memory"` |
202
+ | `ui-observability.tab` | `sessionStorage` | At startup, and when the bus finds a duplicated tab | `identity: "memory"` |
203
+ | `ui-observability.journey` | `sessionStorage` | When a journey starts or ends | `identity: "memory"` |
204
+ | `ui-observability.batch.*` | `localStorage` | When a send fails and the `localstorage` adapter holds the batch | `storage` other than `auto` or `localstorage` |
205
+ | `ui-observability.emergency.*` | `localStorage` | When the exit flush cannot send a batch | `endpoint: null` |
206
+ | `ui-observability.probe` | `localStorage` | One write and one remove, when the library tests `localStorage` | `storage` other than `auto` or `localstorage` |
207
+
208
+ IndexedDB holds undelivered batches with `storage: "auto"` or `"indexeddb"`.
170
209
 
171
210
  ---
172
211
 
173
212
  ## Core Architecture
174
213
 
175
- - **Document singleton:** The runtime pins to `globalThis[Symbol.for("ui-observability.runtime")]`. Federated microfrontends and separate bundles share one buffer, one sequence and one transport.
214
+ - **Code splitting:** The main chunk holds the logger, the record builder and the console sink. The delivery stack loads only when you set an endpoint. The bus loads only when the context needs it. Each capture module loads only when you enable it.
215
+ - **Document singleton:** The library keeps the runtime at `globalThis[Symbol.for("ui-observability.runtime")]`. Federated microfrontends and separate bundles share one buffer, one sequence and one transport.
176
216
  - **One sender:** Iframes, workers and OpenFin views find the nearest long-lived context. They forward their records to it over the bus. That context batches, stores and sends for all of them.
177
217
  - **Five correlation ids:** Each record carries `session.id`, `tab.id`, `context.id`, `journey.id` and `trace_id`.
178
- - **Durability and exit flush:** A failed send persists to IndexedDB or localStorage, then retries with exponential jittered backoff. On `pagehide` or `freeze`, pending records go out with `navigator.sendBeacon` below 60 KB. A larger payload goes to the emergency queue.
179
- - **Emergency queue:** The emergency queue is best effort. It writes to `localStorage` synchronously. No other storage works while the document unloads. A refused write reports `storage.quota_exceeded`. The library then loses the batch.
180
- - **Configuration after startup:** A second `configure()` call merges the new options into the live runtime. The `storage` option is the exception. The runtime builds the storage adapter one time. A change leaves the stored batches in the old adapter. The runtime refuses the change. It reports `config.invalid`.
181
- - **Deterministic sampling:** FNV-1a hashing applies one keep rate to a whole journey. An error and an explicit action bypass sampling.
218
+ - **Durability and exit flush:** The library stores a batch that fails to send, in IndexedDB or localStorage. It sends the batch again with exponential backoff and jitter. On `pagehide` or `freeze`, it sends pending records with `navigator.sendBeacon` if they are below 60 KB. A larger payload goes to the emergency queue.
219
+ - **Emergency queue:** The emergency queue is best effort. It writes to `localStorage` synchronously, because no other storage works while the page unloads. If the browser refuses the write, the library reports `storage.quota_exceeded`. The library then loses the batch.
220
+ - **Configuration after startup:** A second `configure()` call merges the new options into the live runtime. The runtime refuses 3 changes and reports `config.invalid` for each:
221
+ - A change to `storage`. The stored batches stay in the adapter that the runtime built at startup.
222
+ - A change to `identity`. The ids exist from startup.
223
+ - An `endpoint` change to `null` or `""` after the delivery stack loads. Without an endpoint, the stored batches would be lost. A change to another endpoint URL is accepted.
224
+ - **Deterministic sampling:** FNV-1a hashing applies one keep rate to a whole journey. An error and an explicit action are always kept.
182
225
 
183
226
  ---
184
227
 
185
228
  ## Ingest Server Requirements
186
229
 
187
- The server must obey this contract:
230
+ The ingest server must meet these requirements:
188
231
 
189
232
  1. **Protocol:** Accept `POST` with `Content-Type: application/json` or `text/plain;charset=UTF-8`. `sendBeacon` sends the second one to avoid a CORS preflight.
190
- 2. **Preflight:** Answer `OPTIONS` on the ingest path. The transport sends two headers with each batch: `X-UiObs-Batch-Id` and `X-UiObs-Attempt`. For a payload of more than 1 KiB, the transport also sends `Content-Encoding: gzip`. Each of these headers causes a CORS preflight. Allow the three headers with `Access-Control-Allow-Headers: content-type, content-encoding, x-uiobs-batch-id, x-uiobs-attempt`. If the server does not allow them, each preflight fails. The transport then gets a `TypeError`. The retry engine sends the batch five more times, then drops the batch. The exit flush sends no headers, so the exit flush continues to work. The server thus receives only the records from the exit flush.
191
- 3. **Deduplication:** Deduplicate on the `X-UiObs-Batch-Id` header and the `uiobs_batch_id` query parameter. Hold the ids for 24 hours minimum.
233
+ 2. **Preflight:** Answer `OPTIONS` on the ingest path, and allow the request headers:
234
+
235
+ ```http
236
+ Access-Control-Allow-Headers: content-type, content-encoding, x-uiobs-batch-id, x-uiobs-attempt
237
+ ```
238
+
239
+ - The transport sends `X-UiObs-Batch-Id` and `X-UiObs-Attempt` with each batch.
240
+ - Above 1 KiB, it also sends `Content-Encoding: gzip`.
241
+ - Each of these headers causes a CORS preflight. If the server does not allow them, each preflight fails.
242
+ - After a failed preflight, the library tries the batch 5 more times. It then drops the batch.
243
+ - Only the exit flush records arrive, because the exit flush sends no custom header.
244
+
245
+ 3. **Deduplication:** Deduplicate on the `X-UiObs-Batch-Id` header and the `uiobs_batch_id` query parameter. Keep the ids for at least 24 hours.
192
246
  4. **Throttling:** Return `429` or `503` with `Retry-After`. Expose the header with `Access-Control-Expose-Headers: retry-after`.
193
- 5. **Status codes:** `200`, `202` and `204` accept the batch. `413` makes the client split the batch. Another `4xx` drops the batch.
247
+ 5. **Status codes:** `200`, `202` and `204` accept the batch. `413` makes the library split the batch. The library drops a batch that gets any other `4xx`.
194
248
 
195
249
  ---
196
250
 
@@ -214,6 +268,7 @@ npm run build
214
268
  npm run example:react # http://localhost:5180
215
269
  npm run example:angular # http://localhost:4200
216
270
  npm run example:microfrontend # Shell on http://localhost:5191, remotes on 5192 and 5193
271
+ npm run example:console-only # http://localhost:5195
217
272
  ```
218
273
 
219
274
  ---
package/dist/bus/bus.d.ts CHANGED
@@ -7,12 +7,12 @@ import type { PlatformMetadata } from "../utils/platform";
7
7
  import { type Receive, type WorkerLike } from "./links";
8
8
  /** Handshake timing for a forwarder waiting on an owner. */
9
9
  export interface HandshakeOptions {
10
- /** Max time to wait for an owner to answer, in milliseconds. */
10
+ /** Maximum time that a forwarder waits for an owner to answer, in milliseconds. */
11
11
  timeoutMs: number;
12
12
  /** Attempts allowed before a cross-origin forwarder promotes itself to sender. */
13
13
  maxAttempts: number;
14
14
  }
15
- /** Handshake timing in force. Tests build a bus with shorter values. */
15
+ /** Default handshake timing. Tests build a bus with shorter values. */
16
16
  export declare const HANDSHAKE_OPTIONS: HandshakeOptions;
17
17
  /** Callbacks for handling records and journey events from connected realms. */
18
18
  export interface BusHandlers {
@@ -20,9 +20,9 @@ export interface BusHandlers {
20
20
  onRecords: (records: LogRecord[]) => void;
21
21
  /** Applies journey updates received from the control bus. */
22
22
  onJourney: (journey: Journey | null) => void;
23
- /** Returns the active journey for inquiring child contexts. */
23
+ /** Returns the active journey to a child context that requests it. */
24
24
  onJourneyRequest: () => Journey | null;
25
- /** Invoked when a tab identifier collision is detected across windows. */
25
+ /** Runs when two windows use the same tab identifier. */
26
26
  onTabConflict: () => void;
27
27
  }
28
28
  /** Coordinates cross-realm communication, role resolution, and message dispatch. */
@@ -34,7 +34,7 @@ export declare class Bus {
34
34
  private readonly tabId;
35
35
  private readonly handlers;
36
36
  private readonly handshakeOptions;
37
- /** Current bus role. Defaults to "sender". */
37
+ /** Current bus role. The default is "sender". */
38
38
  private role;
39
39
  /** Upstream forwarding link, or null when acting as sender. */
40
40
  private upstream;
@@ -93,15 +93,15 @@ export declare class Bus {
93
93
  private allLinks;
94
94
  /** Broadcasts a message across all open links. */
95
95
  private post;
96
- /** Sends a message exclusively over links matching the specified kind. */
96
+ /** Sends a message only over links of the given kind. */
97
97
  private postOver;
98
98
  /** Routes incoming messages to registered handlers or upstream targets. */
99
99
  private readonly receive;
100
100
  /**
101
- * Tells whether records from a link can go upstream. Posted back on the link
102
- * they arrived on, the records echo to their sender. A direct link is an
103
- * exception: it is one call into one parent, so two direct links in a chain are
104
- * different links.
101
+ * Tells whether records from a link can go upstream. Records that go back on
102
+ * their arrival link return to their sender. A direct link is an exception.
103
+ * Each direct link is one call into one parent. Thus two direct links in a
104
+ * chain are different links.
105
105
  * @param link Kind of the link the records arrived on.
106
106
  * @returns True if the relay is safe.
107
107
  */
@@ -18,7 +18,7 @@ export interface Link {
18
18
  * @param source Origin and link metadata.
19
19
  */
20
20
  export type Receive = (message: BusMessage, source: MessageSource) => void;
21
- /** Interface exposed on global symbol by same-origin parent runtimes. */
21
+ /** Interface that a same-origin parent runtime exposes on a global symbol. */
22
22
  export interface DirectHost {
23
23
  /**
24
24
  * Accepts a message directly from a child frame and replies synchronously.