@utk09/ui-observability 0.9.2 → 0.9.4

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 (191) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +108 -33
  3. package/dist/batch-C4oF6XZT.cjs +2 -0
  4. package/dist/batch-C4oF6XZT.cjs.map +1 -0
  5. package/dist/{batch-4xKzzSCj.js → batch-D-4xl7op.js} +8 -5
  6. package/dist/batch-D-4xl7op.js.map +1 -0
  7. package/dist/bus/bus.d.ts +0 -4
  8. package/dist/{bus-DrixwdiX.js → bus-Cyvq-Ngx.js} +59 -62
  9. package/dist/bus-Cyvq-Ngx.js.map +1 -0
  10. package/dist/bus-rOhVuRee.cjs +2 -0
  11. package/dist/bus-rOhVuRee.cjs.map +1 -0
  12. package/dist/capture/network.d.ts +1 -0
  13. package/dist/capture/storm.d.ts +2 -7
  14. package/dist/capture/types.d.ts +3 -0
  15. package/dist/capture/web-socket.d.ts +40 -0
  16. package/dist/{console-B3vGRW5p.js → console-BT7mcgU6.js} +3 -3
  17. package/dist/{console-B3vGRW5p.js.map → console-BT7mcgU6.js.map} +1 -1
  18. package/dist/{console-ChfuJlf9.cjs → console-Boqa7new.cjs} +2 -2
  19. package/dist/{console-ChfuJlf9.cjs.map → console-Boqa7new.cjs.map} +1 -1
  20. package/dist/constants-BgRS6MB0.cjs +2 -0
  21. package/dist/constants-BgRS6MB0.cjs.map +1 -0
  22. package/dist/constants-L_d5YvvQ.js +160 -0
  23. package/dist/constants-L_d5YvvQ.js.map +1 -0
  24. package/dist/constants.d.ts +36 -5
  25. package/dist/core/breadcrumbs.d.ts +4 -4
  26. package/dist/core/context.d.ts +0 -8
  27. package/dist/core/diagnostics.d.ts +1 -3
  28. package/dist/core/journey.d.ts +7 -0
  29. package/dist/core/meter.d.ts +19 -1
  30. package/dist/core/pipeline.d.ts +12 -4
  31. package/dist/core/record.d.ts +40 -8
  32. package/dist/core/remote-sampling.d.ts +7 -3
  33. package/dist/core/runtime.d.ts +62 -3
  34. package/dist/core/sampling.d.ts +33 -4
  35. package/dist/core/sender.d.ts +8 -0
  36. package/dist/core/spans.d.ts +34 -0
  37. package/dist/{errors-BGs5NOrw.js → errors-BDI96zKc.js} +6 -6
  38. package/dist/errors-BDI96zKc.js.map +1 -0
  39. package/dist/errors-_xEsCVXn.cjs +3 -0
  40. package/dist/errors-_xEsCVXn.cjs.map +1 -0
  41. package/dist/fixed-window-BR0bu32Y.cjs +2 -0
  42. package/dist/fixed-window-BR0bu32Y.cjs.map +1 -0
  43. package/dist/fixed-window-Re7jIRJH.js +9 -0
  44. package/dist/fixed-window-Re7jIRJH.js.map +1 -0
  45. package/dist/identity-Bwku7zzN.cjs +2 -0
  46. package/dist/identity-Bwku7zzN.cjs.map +1 -0
  47. package/dist/{identity-rpEyjvVg.js → identity-Dtv917nz.js} +33 -23
  48. package/dist/identity-Dtv917nz.js.map +1 -0
  49. package/dist/index.cjs +1 -1
  50. package/dist/index.cjs.map +1 -1
  51. package/dist/index.d.ts +23 -1
  52. package/dist/index.js +804 -537
  53. package/dist/index.js.map +1 -1
  54. package/dist/indexeddb-storage-Cvavrf-y.cjs +2 -0
  55. package/dist/indexeddb-storage-Cvavrf-y.cjs.map +1 -0
  56. package/dist/{indexeddb-storage-Q9fDYlyn.js → indexeddb-storage-HgkQUTyS.js} +57 -68
  57. package/dist/indexeddb-storage-HgkQUTyS.js.map +1 -0
  58. package/dist/{interactions-BAGRmtrv.cjs → interactions-Bhe1ft8P.cjs} +2 -2
  59. package/dist/interactions-Bhe1ft8P.cjs.map +1 -0
  60. package/dist/{interactions-B8zjCjga.js → interactions-Ck01cEij.js} +3 -3
  61. package/dist/interactions-Ck01cEij.js.map +1 -0
  62. package/dist/journey-Co9OlzrW.cjs +2 -0
  63. package/dist/journey-Co9OlzrW.cjs.map +1 -0
  64. package/dist/{journey-_dQQ1eMP.js → journey-DRK0A8u_.js} +37 -33
  65. package/dist/journey-DRK0A8u_.js.map +1 -0
  66. package/dist/{library-request-DX6ev9oG.js → library-request-ChCar5F8.js} +3 -3
  67. package/dist/{library-request-DX6ev9oG.js.map → library-request-ChCar5F8.js.map} +1 -1
  68. package/dist/{library-request-BIG3Xpx3.cjs → library-request-gMFOCNcn.cjs} +2 -2
  69. package/dist/{library-request-BIG3Xpx3.cjs.map → library-request-gMFOCNcn.cjs.map} +1 -1
  70. package/dist/log-record-cwFiLyPY.js +17 -0
  71. package/dist/log-record-cwFiLyPY.js.map +1 -0
  72. package/dist/log-record-jX9eWUP8.cjs +2 -0
  73. package/dist/log-record-jX9eWUP8.cjs.map +1 -0
  74. package/dist/{long-frames-Cq2LgNnp.cjs → long-frames-Bky6nZDF.cjs} +2 -2
  75. package/dist/long-frames-Bky6nZDF.cjs.map +1 -0
  76. package/dist/{long-frames-B0tKuChx.js → long-frames-DDumopji.js} +4 -4
  77. package/dist/long-frames-DDumopji.js.map +1 -0
  78. package/dist/models/batch.d.ts +6 -0
  79. package/dist/models/config.d.ts +56 -5
  80. package/dist/models/log-record.d.ts +1 -1
  81. package/dist/models/plugin.d.ts +47 -0
  82. package/dist/models/stats.d.ts +11 -0
  83. package/dist/{network-CMnEvGJB.js → network-BsBZ6_-Q.js} +43 -29
  84. package/dist/network-BsBZ6_-Q.js.map +1 -0
  85. package/dist/network-_4csBGBM.cjs +2 -0
  86. package/dist/network-_4csBGBM.cjs.map +1 -0
  87. package/dist/openfin-BwEN0uj4.js +8 -0
  88. package/dist/openfin-BwEN0uj4.js.map +1 -0
  89. package/dist/openfin-DtH2f7zX.cjs +2 -0
  90. package/dist/openfin-DtH2f7zX.cjs.map +1 -0
  91. package/dist/platform-4yYjMD-B.js +57 -0
  92. package/dist/platform-4yYjMD-B.js.map +1 -0
  93. package/dist/platform-o7r1ocOu.cjs +2 -0
  94. package/dist/platform-o7r1ocOu.cjs.map +1 -0
  95. package/dist/remote-rules-1KqfVBIu.js +91 -0
  96. package/dist/remote-rules-1KqfVBIu.js.map +1 -0
  97. package/dist/remote-rules-BHgEGlYi.cjs +2 -0
  98. package/dist/remote-rules-BHgEGlYi.cjs.map +1 -0
  99. package/dist/sampling-C4my-ma0.cjs +2 -0
  100. package/dist/sampling-C4my-ma0.cjs.map +1 -0
  101. package/dist/sampling-nYIWP_vP.js +86 -0
  102. package/dist/sampling-nYIWP_vP.js.map +1 -0
  103. package/dist/{sanitize-BNwgPj_B.js → sanitize-BiUKCUG6.js} +2 -2
  104. package/dist/{sanitize-BNwgPj_B.js.map → sanitize-BiUKCUG6.js.map} +1 -1
  105. package/dist/{sanitize-BqzPc4Jg.cjs → sanitize-BxuPSXOk.cjs} +2 -2
  106. package/dist/{sanitize-BqzPc4Jg.cjs.map → sanitize-BxuPSXOk.cjs.map} +1 -1
  107. package/dist/sender-6vrT9fFL.cjs +3 -0
  108. package/dist/sender-6vrT9fFL.cjs.map +1 -0
  109. package/dist/{sender--0_VzPbN.js → sender-DFQMF39P.js} +380 -278
  110. package/dist/sender-DFQMF39P.js.map +1 -0
  111. package/dist/storage/gap.d.ts +20 -0
  112. package/dist/storage/indexeddb-storage.d.ts +1 -7
  113. package/dist/storage/keys.d.ts +9 -0
  114. package/dist/storage/local-storage.d.ts +0 -6
  115. package/dist/storage/memory-storage.d.ts +1 -1
  116. package/dist/storm-6YYbXzT_.cjs +2 -0
  117. package/dist/storm-6YYbXzT_.cjs.map +1 -0
  118. package/dist/storm-CfO0Sam2.js +10 -0
  119. package/dist/storm-CfO0Sam2.js.map +1 -0
  120. package/dist/transport/exit-flush.d.ts +6 -0
  121. package/dist/transport/http-transport.d.ts +2 -1
  122. package/dist/transport/serializers/otlp-traces.d.ts +3 -0
  123. package/dist/transport/serializers/select.d.ts +8 -5
  124. package/dist/transport/status-transport.d.ts +7 -0
  125. package/dist/types-BR9t_w28.js +8 -0
  126. package/dist/types-BR9t_w28.js.map +1 -0
  127. package/dist/types-C7WNpnG1.cjs +2 -0
  128. package/dist/types-C7WNpnG1.cjs.map +1 -0
  129. package/dist/utils/fixed-window.d.ts +15 -0
  130. package/dist/utils/guards.d.ts +6 -0
  131. package/dist/utils/identity.d.ts +11 -0
  132. package/dist/utils/openfin.d.ts +48 -0
  133. package/dist/utils/platform.d.ts +13 -0
  134. package/dist/utils/tracing.d.ts +82 -4
  135. package/dist/web-socket-Ar4cZxmd.js +102 -0
  136. package/dist/web-socket-Ar4cZxmd.js.map +1 -0
  137. package/dist/web-socket-BwJdwSHl.cjs +2 -0
  138. package/dist/web-socket-BwJdwSHl.cjs.map +1 -0
  139. package/package.json +2 -3
  140. package/dist/batch-4xKzzSCj.js.map +0 -1
  141. package/dist/batch-cys7e53Q.cjs +0 -2
  142. package/dist/batch-cys7e53Q.cjs.map +0 -1
  143. package/dist/bus-B6vzPmQM.cjs +0 -2
  144. package/dist/bus-B6vzPmQM.cjs.map +0 -1
  145. package/dist/bus-DrixwdiX.js.map +0 -1
  146. package/dist/constants-Be83LICb.cjs +0 -2
  147. package/dist/constants-Be83LICb.cjs.map +0 -1
  148. package/dist/constants-CQ_D7jIW.js +0 -144
  149. package/dist/constants-CQ_D7jIW.js.map +0 -1
  150. package/dist/deadline-5_PecIl5.js +0 -26
  151. package/dist/deadline-5_PecIl5.js.map +0 -1
  152. package/dist/deadline-XSnm95pg.cjs +0 -2
  153. package/dist/deadline-XSnm95pg.cjs.map +0 -1
  154. package/dist/errors-BGs5NOrw.js.map +0 -1
  155. package/dist/errors-BMJm7KZZ.cjs +0 -3
  156. package/dist/errors-BMJm7KZZ.cjs.map +0 -1
  157. package/dist/identity-DXyV86o-.cjs +0 -2
  158. package/dist/identity-DXyV86o-.cjs.map +0 -1
  159. package/dist/identity-rpEyjvVg.js.map +0 -1
  160. package/dist/indexeddb-storage-BXaPVPyG.cjs +0 -2
  161. package/dist/indexeddb-storage-BXaPVPyG.cjs.map +0 -1
  162. package/dist/indexeddb-storage-Q9fDYlyn.js.map +0 -1
  163. package/dist/interactions-B8zjCjga.js.map +0 -1
  164. package/dist/interactions-BAGRmtrv.cjs.map +0 -1
  165. package/dist/journey-BGSyy8Es.cjs +0 -2
  166. package/dist/journey-BGSyy8Es.cjs.map +0 -1
  167. package/dist/journey-_dQQ1eMP.js.map +0 -1
  168. package/dist/long-frames-B0tKuChx.js.map +0 -1
  169. package/dist/long-frames-Cq2LgNnp.cjs.map +0 -1
  170. package/dist/network-C6kJbW6K.cjs +0 -2
  171. package/dist/network-C6kJbW6K.cjs.map +0 -1
  172. package/dist/network-CMnEvGJB.js.map +0 -1
  173. package/dist/platform-DNOJjpOm.cjs +0 -2
  174. package/dist/platform-DNOJjpOm.cjs.map +0 -1
  175. package/dist/platform-j0uMPwHi.js +0 -48
  176. package/dist/platform-j0uMPwHi.js.map +0 -1
  177. package/dist/remote-rules-DgoBJxZL.cjs +0 -2
  178. package/dist/remote-rules-DgoBJxZL.cjs.map +0 -1
  179. package/dist/remote-rules-UggoZqfP.js +0 -86
  180. package/dist/remote-rules-UggoZqfP.js.map +0 -1
  181. package/dist/sampling-BLMD8EGM.js +0 -64
  182. package/dist/sampling-BLMD8EGM.js.map +0 -1
  183. package/dist/sampling-MthcVXXU.cjs +0 -2
  184. package/dist/sampling-MthcVXXU.cjs.map +0 -1
  185. package/dist/sender--0_VzPbN.js.map +0 -1
  186. package/dist/sender-SPGMqZjD.cjs +0 -3
  187. package/dist/sender-SPGMqZjD.cjs.map +0 -1
  188. package/dist/storm-CTy1dfvs.cjs +0 -2
  189. package/dist/storm-CTy1dfvs.cjs.map +0 -1
  190. package/dist/storm-knaj4GUH.js +0 -10
  191. package/dist/storm-knaj4GUH.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,57 @@
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.9.4] - 2026-10-31
6
+
7
+ ### Added - v0.9.4
8
+
9
+ - `startJourney(name, { id })` sets the journey id. An id of 1 to 64 letters, digits, `_`, `.`, `:` or `-` stays. Another value gives a new id and a `config.invalid` report.
10
+ - `addBreadcrumb(message, data?)` adds a breadcrumb with the category `custom`. The library copies `data` at the call.
11
+ - `minLevels` sets a minimum level for each namespace prefix, for example `{ "trading.ticks": "DEBUG" }`. The longest prefix that matches at a dot wins. A namespace with no match uses `minLevel`. A new map replaces the map in force.
12
+ - Remote sampling rules can have `minLevels`, with at most 100 prefixes. A remote prefix wins over the remote `minLevel`. A remote level only lowers the level of a namespace.
13
+ - `contextProvider()` gives attributes for each record that sampling keeps. Its values override `setContext()` values. The logger scope and the call payload override its values. A provider that throws reports `handler.threw`. A value that is not an object reports `config.invalid`. The record is still built.
14
+ - `getStats()` gives `{ pending, inFlight, stored, lastSendAt }`. `pending` counts the records in the buffers. `inFlight` counts the records in requests. `stored` counts the batches in storage. `lastSendAt` is the time of the last batch that the server accepted. A forwarder reports only its own buffers. The package exports the type `DeliveryStats`.
15
+ - `newSession()` starts a new session in this tab, for example after a logout. It sends the open metric points, ends the active trace and journey, clears the breadcrumbs and writes the new id to `localStorage`. Other tabs read the new id at their next startup. A tab does not write its old id over the new id.
16
+ - `processors` is a list of functions that change or drop a record. They run in list order, before `redact`. A processor has the contract of `redact`. A processor that throws or returns a value that is not a record drops the record. The diagnostic code `record.dropped_by_processor` counts the drops.
17
+ - `capture.plugins` adds capture modules of the app. A plugin has `name`, `install(ctx)` and `uninstall()`. `ctx` gives `logger`, `counter()`, `histogram()`, `addBreadcrumb()` and `ownRequest(fn)`. The logger namespace is `uiobs.capture.<name>`. A plugin that throws in `install()` or `uninstall()` reports `capture.install_failed`. The package exports the types `CapturePlugin` and `PluginContext`.
18
+ - `capture.webSocket` records `websocket.open`, `websocket.close` and `websocket.error` for each WebSocket, with `url.full` and `server.address`. The URL has no user info, no query and no fragment. The counter `ui.websocket.messages` counts the messages by `network.io.direction` and `server.address`. The library never reads the content of a message. It records at most 20 lifecycle records in each 10-second window. It skips a socket in `capture.ignoreUrls`, and does not count a send of the library. `instanceof WebSocket` stays true for a socket that the app opened before the capture loaded. The capture loads as a separate chunk.
19
+ - `tracesEndpoint` sets an OTLP traces endpoint, for example `https://ingest.example/v1/traces`. With it, the library sends spans as an OTLP `ExportTraceServiceRequest`. Without it, the library sends no span. It needs `serializer: "otlp"`, and `endpoint` or `transport`. A batch of spans without `tracesEndpoint` counts `record.dropped_no_destination`.
20
+ - Each trace of the library has one root span. It ends when the trace rotates, at the exit flush, at `shutdown()` and, in a frame or a view that forwards its records, on `pagehide`. Its name is `ui.start`, `ui.interaction`, `ui.navigation` or `ui.trace`.
21
+ - Each `fetch` or XHR request that gets `traceparent` has one CLIENT span. The `traceparent` names the client span. The root span is its parent.
22
+ - `sampling.defaultRate` samples each trace by its trace id. The whole trace stays or goes. For a trace that sampling drops, `traceparent` has the sampled flag off. `minLevel` does not apply to a span. The library sends no span for a trace from the OpenTelemetry API.
23
+ - Spans go through `processors` and `redact`. The console does not print them. At exit, the logs get the beacon budget before the spans.
24
+ - `request.kind` of a custom transport is `"traces"` for a batch of span records.
25
+ - The ECS serializer writes `ecs.version` (`8.10.0`), `log.logger`, `event.kind` and `error.type`, `error.message` and `error.stack_trace`.
26
+ - On Node, the library runs console-only. It installs no capture, keeps the ids in memory, uses no storage and has no exit flush. If you set `endpoint`, `metricsEndpoint`, `tracesEndpoint` or `transport`, it reports `config.invalid` one time.
27
+ - `tools/reference-collector.mjs` is a reference ingest server with no dependencies. It implements each rule of the ingest contract, deduplicates for 24 hours and can forward to an OTLP collector. It listens on `127.0.0.1` by default, limits the rate of each client address and limits the body size after gzip decoding. It is not part of the package.
28
+ - The mock ingest server accepts `/v1/traces` and prints each span.
29
+ - The documents `docs/attributes.md`, `docs/browser-support.md` and `docs/threat-model.md`.
30
+ - The README tells that each top-level tab sends its own records.
31
+
32
+ ### Changed - v0.9.4
33
+
34
+ - The type `LogType` has the new value `"span"`. The type `BatchKind` has the new value `"traces"`.
35
+ - The sender runs its `redact` on each record from a frame or a worker. A context that never calls `configure()` then cannot send a raw record. Write `redact` so that a second run gives the same result.
36
+ - A `redact` hook that changes a record in place now gets the sanitizer and the size limit. Before, only a new record from the hook got them.
37
+ - With `processors` or `redact`, a record from before startup no longer gets `journey.id` and `journey.name` after the hooks ran.
38
+ - The library removes the user info, for example `user:pass@`, from each URL that it records, also with `capture.fullUrls`. `error.source` follows `capture.fullUrls`.
39
+ - With `storage: "memory"` or `"none"`, the exit flush does not use the emergency queue in `localStorage`. A batch that it cannot send is lost, and `onDrop` reports `not_stored`.
40
+ - `adoptJourney()` refuses a token without a start time, or with a start time more than 5 minutes ahead.
41
+ - A tab no longer writes its session id over a newer session id of another tab that has not expired.
42
+ - The ECS serializer moves `app.namespace` and the string `error.type`, `error.message` and `error.stack_trace` attributes out of `labels`. The other attributes stay in `labels`.
43
+ - A console-only runtime next to another version of the library also ignores `metricsEndpoint` and `tracesEndpoint`.
44
+ - The size budget of the main graph is 32,200 B.
45
+
46
+ ### Fixed - v0.9.4
47
+
48
+ - A reused XHR sent a second record for its earlier request at each later send.
49
+
50
+ ## [0.9.3] - 2026-10-31
51
+
52
+ ### Fixed - v0.9.3
53
+
54
+ - The limit on ERROR and FATAL records starts a new window when the clock moves back. Before, the library dropped each ERROR and FATAL record above the limit until the clock passed the old window start.
55
+
5
56
  ## [0.9.2] - 2026-10-30
6
57
 
7
58
  ### Added - v0.9.2
package/README.md CHANGED
@@ -89,7 +89,7 @@ configure({
89
89
  - `identity: "memory"` writes no key to `localStorage` or `sessionStorage`.
90
90
  - `console` and `minLevel` are independent. `console` sets what the library prints. `minLevel` sets what the library sends.
91
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 that `redact` drops prints no line. A record below `minLevel` shows its message and error only, because the library does not build it.
92
+ - With a `redact` hook, the console shows only what `redact` returns. A record that a processor or `redact` drops prints no line. A record below `minLevel`, or a record that sampling drops, shows its message and error only, because the library does not build it.
93
93
 
94
94
  ### Console Output
95
95
 
@@ -159,7 +159,8 @@ configure({
159
159
  - A rejected promise counts as a network error. The library sends the batch again later. A call that does not settle in 15 seconds counts as a timeout.
160
160
  - The library does not compress `request.body`. Compress it in your transport if necessary.
161
161
  - `request.records` holds the built records after `redact`. Do not change them, because the retry engine can send them again.
162
- - `request.kind` is `"metrics"` for a batch of metric records when `metricsEndpoint` is set. `request.body` is then an OTLP `ExportMetricsServiceRequest`. Send it to your metrics endpoint. Each other batch has the kind `"logs"`.
162
+ - `request.kind` is `"metrics"` for a batch of metric records when `metricsEndpoint` is set. `request.body` is then an OTLP `ExportMetricsServiceRequest`. Send it to your metrics endpoint.
163
+ - `request.kind` is `"traces"` for a batch of span records. `request.body` is then an OTLP `ExportTraceServiceRequest`. Send it to your traces endpoint. Each other batch has the kind `"logs"`.
163
164
  - Without `transportOnExit`, the last batch goes to the emergency queue when the page closes. The next page load sends it.
164
165
  - With `storage: "none"`, the next page load cannot keep that batch. Set `transportOnExit`, or the library loses the last batch.
165
166
  - The library ignores a `retryAfterMs` or a `maxBytes` that is not a finite number. It uses 0 for a negative value.
@@ -225,6 +226,7 @@ X-UiObs-Sampling: {"v":1,"ttlMs":600000,"defaultRate":0.1,"rates":{"blotter.grid
225
226
  - `v` must be `1`. `ttlMs` is mandatory, from more than 0 to 3,600,000 (1 hour). After the TTL, the rules from `configure()` apply again.
226
227
  - `rates` apply over the `configure()` rates. The other `configure()` rates stay. `defaultRate` applies only if the header has it.
227
228
  - `minLevel` can only lower the level that the library sends. It does not change the console level.
229
+ - `minLevels` sets a level for each namespace prefix, for example `{"trading.ticks":"DEBUG"}`. A remote prefix wins over the remote `minLevel`. A remote level applies only when it is lower than the `configure()` level of the namespace. At most 100 prefixes.
228
230
  - `sampling.remoteMaxRate` caps each remote rate. It also caps the records that a remote `minLevel` adds. Set it below 1 to limit the traffic that a compromised server can cause.
229
231
  - The library rejects all the rules if one field is not valid, for example a rate outside 0 to 1, more than 100 `rates` or a header longer than 4096 characters. It reports `config.invalid`.
230
232
  - The library keeps the rules in memory only. A reload uses the `configure()` rules until the next accepted batch.
@@ -266,27 +268,30 @@ The level methods give records with `log.type: "log"`. Records of the library it
266
268
 
267
269
  ### Context & Correlation
268
270
 
269
- | Function | Description |
270
- | ------------------------------ | ------------------------------------------------------------- |
271
- | `setContext(key, value)` | Sets one ambient attribute on every later record. |
272
- | `setContextMap(values)` | Merges an attribute map into the ambient context. |
273
- | `removeContext(key)` | Removes one attribute from the ambient context. |
274
- | `startJourney(name, options?)` | Starts a journey across windows. |
275
- | `endJourney()` | Ends the active journey. |
276
- | `currentJourney()` | Returns the active `Journey`, or null. |
277
- | `getJourneyToken()` | Serializes the active journey into a URL token. |
278
- | `adoptJourney(token)` | Adopts a journey token into this context. |
279
- | `startTrace()` | Rotates the ambient trace context. |
280
- | `getTraceHeaders()` | Returns the W3C `traceparent` header for an outgoing request. |
281
- | `registerWorker(worker)` | Attaches a Web Worker or MessagePort to the bus. |
271
+ | Function | Description |
272
+ | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
273
+ | `setContext(key, value)` | Sets one ambient attribute on every later record. |
274
+ | `setContextMap(values)` | Merges an attribute map into the ambient context. |
275
+ | `removeContext(key)` | Removes one attribute from the ambient context. |
276
+ | `addBreadcrumb(message, data?)` | Adds a breadcrumb with the category `custom`. The next error record carries the trail. The library copies `data` at the call. |
277
+ | `startJourney(name, options?)` | Starts a journey across windows. `options.parent: true` links the active journey as the parent. `options.id` sets the id, 1 to 64 letters, digits, `_`, `.`, `:` or `-`. Another value gives a new id and a `config.invalid` report. |
278
+ | `endJourney()` | Ends the active journey. |
279
+ | `currentJourney()` | Returns the active `Journey`, or null. |
280
+ | `getJourneyToken()` | Serializes the active journey into a URL token. |
281
+ | `adoptJourney(token)` | Adopts a journey token into this context. |
282
+ | `startTrace()` | Rotates the ambient trace context. |
283
+ | `getTraceHeaders()` | Returns the W3C `traceparent` header for an outgoing request. |
284
+ | `registerWorker(worker)` | Attaches a Web Worker or MessagePort to the bus. |
285
+ | `newSession()` | Starts a new session in this tab, for example after a logout. It sends the open metric points, ends the active trace and journey, and clears the breadcrumbs. Other tabs read the new id at their next startup. |
282
286
 
283
287
  ### Delivery & Diagnostics
284
288
 
285
- | Function | Description |
286
- | ------------------------- | -------------------------------------------------------------------------------------------------- |
287
- | `flush()` | Sends the records held in the pipeline or the forward buffer, and waits for the batches in flight. |
288
- | `getQueueDepth()` | Returns the number of batches in storage. |
289
- | `getDiagnosticCounters()` | Returns the count of each diagnostic code. |
289
+ | Function | Description |
290
+ | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
291
+ | `flush()` | Sends the records held in the pipeline or the forward buffer, and waits for the batches in flight. |
292
+ | `getQueueDepth()` | Returns the number of batches in storage. |
293
+ | `getStats()` | Returns `{ pending, inFlight, stored, lastSendAt }`. `pending` counts the records in the buffers. `inFlight` counts the records in requests. `stored` counts the batches in storage. `lastSendAt` is the epoch time in ms of the last batch that the server accepted, or null. A forwarder reports only its own buffers. |
294
+ | `getDiagnosticCounters()` | Returns the count of each diagnostic code. |
290
295
 
291
296
  ---
292
297
 
@@ -298,13 +303,15 @@ No key is required. Set `endpoint` to send records. A value of the wrong type or
298
303
  | -------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
299
304
  | `endpoint` | `""` | HTTP endpoint that receives the batches. `null` selects console-only mode. `""` reports `config.invalid`. |
300
305
  | `metricsEndpoint` | `""` | OTLP metrics endpoint, for example `https://ingest.example/v1/metrics`. With it, each batch of metric records goes there as an OTLP `ExportMetricsServiceRequest`. Without it, metric records are log records on `endpoint`. It needs `serializer: "otlp"`, and `endpoint` or `transport`. |
306
+ | `tracesEndpoint` | `""` | OTLP traces endpoint, for example `https://ingest.example/v1/traces`. With it, the library records spans and sends them there as an OTLP `ExportTraceServiceRequest`. Without it, the library sends no span. It needs `serializer: "otlp"`, and `endpoint` or `transport`. See [Spans](#spans). |
301
307
  | `serviceName` | `""` | `service.name` on every record. |
302
308
  | `serviceVersion` | `""` | `service.version` on every record. |
303
309
  | `environment` | `""` | `deployment.environment` on every record. |
304
310
  | `enabled` | `true` | Set `false` to stop all logging. Every log call then does nothing. |
305
311
  | `minLevel` | `"INFO"` | Lowest level that the library sends (`TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`). It does not drop actions and metrics. |
312
+ | `minLevels` | `{}` | Lowest level for each namespace prefix, for example `{ "trading.ticks": "DEBUG" }`. The longest matching prefix wins. A prefix matches its own namespace and the namespaces below it after a dot. A namespace with no match uses `minLevel`. A new map replaces the map in force. |
306
313
  | `compression` | `"gzip"` | `gzip` or `none`. The library compresses a payload above 1 KB only. |
307
- | `serializer` | `"otlp"` | `otlp`, `ecs`, or a custom `LogSerializer`. |
314
+ | `serializer` | `"otlp"` | `otlp`, `ecs`, or a custom `LogSerializer`. `ecs` writes ECS 8.10 NDJSON. It maps `app.namespace` to `log.logger`, `error.type`, `error.message` and `error.stack_trace` to `error.*`, and `log.type` to `event.kind`. The other attributes go to `labels`. |
308
315
  | `credentials` | `"omit"` | Fetch credentials mode. Set `"include"` for cookie auth. |
309
316
  | `headers` | `{}` | Static headers, or a function that returns them. After a 401 or 403, a function gets one more call and the batch one more send. The exit flush sends the last headers. Before a function gives its first result, the exit flush puts the batch in the emergency queue. `headers: undefined` removes the headers. |
310
317
  | `storage` | `"auto"` | Store for undelivered batches: `auto`, `indexeddb`, `localstorage`, `memory` or `none`. Fixed at startup. |
@@ -340,9 +347,11 @@ No key is required. Set `endpoint` to send records. A value of the wrong type or
340
347
  | `transport(request)` | `undefined` | Sends batches through a channel of your app in place of HTTP (see Custom Transport). |
341
348
  | `transportOnExit(request)` | `undefined` | Sends the last batch while the page closes. It must return a boolean and must not wait. |
342
349
  | `otelLoader()` | `undefined` | Loads `@opentelemetry/api`. Without it, OTel is off. |
343
- | `redact(record)` | `undefined` | Changes a record before the library sends or prints it. Return `null` to drop the record. If the hook throws or returns a value that is not a record, the library drops the record. It counts `record.dropped_by_redact`. |
350
+ | `contextProvider()` | `undefined` | Returns attributes for each record that sampling keeps, for example the current route. Its values override `setContext()` values. The logger scope and the call payload override its values. Keep it fast and synchronous. A provider that throws reports `handler.threw`. A value that is not an object reports `config.invalid`. The record is still built. |
351
+ | `processors` | `[]` | Functions that change or drop a record. They run in list order, before `redact`. A processor has the contract of `redact`. Return the record or a new record to keep it, or `null` to drop it. If a processor throws or returns a value that is not a record, the library drops the record. It counts `record.dropped_by_processor`. A new list replaces the list in force. |
352
+ | `redact(record)` | `undefined` | Changes a record before the library sends or prints it. Return `null` to drop the record. If the hook throws or returns a value that is not a record, the library drops the record. It counts `record.dropped_by_redact`. The sender also runs its `redact` on each record from a frame or a worker. A record that the child already redacted then runs through `redact` again. Write `redact` so that a second run gives the same result. |
344
353
  | `onDiagnostic(event)` | `undefined` | Receives the faults of the library itself. |
345
- | `onDrop(summary)` | `undefined` | Receives a summary when the library loses records that it built. The summary has `reason`, `records`, `batchIds`, `journeyIds` and `actions`. Sampling, `minLevel` and `redact` do not cause a loss. Do not log through the library in the hook. A record from the hook can evict a stored batch. A batch that storage evicts during its send can still reach the server. |
354
+ | `onDrop(summary)` | `undefined` | Receives a summary when the library loses records that it built. The summary has `reason`, `records`, `batchIds`, `journeyIds` and `actions`. Sampling, `minLevel`, `processors` and `redact` do not cause a loss. Do not log through the library in the hook. A record from the hook can evict a stored batch. A batch that storage evicts during its send can still reach the server. |
346
355
 
347
356
  ### Auto-Capture Options
348
357
 
@@ -364,6 +373,8 @@ capture: {
364
373
  fullUrls: false, // Keep query strings and fragments on recorded URLs
365
374
  ignoreUrls: [], // URL patterns excluded from network capture
366
375
  propagateTraceHeaderTo: [], // Origins, or RegExp patterns, that receive traceparent
376
+ webSocket: false, // WebSocket open, close and error, and ui.websocket.messages
377
+ plugins: [], // Capture plugins of your app
367
378
  }
368
379
  ```
369
380
 
@@ -386,34 +397,96 @@ capture: {
386
397
  - To record an argument, the library reads each property, also a getter. A getter with a side effect then runs during the console call.
387
398
  - On `shutdown()`, the library restores each method. If another script wrapped the method later, the library leaves it and reports `capture.install_failed`.
388
399
 
400
+ `webSocket` records the lifecycle of each WebSocket that the app opens after the capture loads.
401
+
402
+ - `websocket.open` and `websocket.close` are events. `websocket.error` is a WARN record. Each has `url.full` and `server.address`.
403
+ - `websocket.close` adds `websocket.close.code` and `websocket.close.clean`.
404
+ - `url.full` has no user info, no query and no fragment, also with `fullUrls`. A socket URL often holds a token.
405
+ - The counter `ui.websocket.messages` counts the messages, with `network.io.direction` (`transmit` or `receive`) and `server.address`.
406
+ - The library never reads the content of a message.
407
+ - The library records at most 20 lifecycle records in each 10-second window. The counter counts each message.
408
+
409
+ `plugins` adds your own capture modules. A plugin is an object with `name`, `install(ctx)` and `uninstall()`.
410
+
411
+ - `ctx` gives `logger`, `counter()`, `histogram()`, `addBreadcrumb()` and `ownRequest(fn)`. The logger namespace is `uiobs.capture.<name>`.
412
+ - `ownRequest(fn)` runs `fn`. The network capture does not record a request that `fn` starts before its first `await`, and does not add `traceparent` to it.
413
+ - A `configure()` that changes the capture section calls `uninstall()`, then `install(ctx)` again. `shutdown()` calls `uninstall()`.
414
+ - If `install()` or `uninstall()` throws, the library reports `capture.install_failed`. The other capture modules keep working.
415
+ - The console-only runtime next to another version of the library installs no plugin.
416
+
417
+ ```ts
418
+ import { type CapturePlugin, configure } from "@utk09/ui-observability";
419
+
420
+ let onChange: (() => void) | undefined;
421
+
422
+ const visibility: CapturePlugin = {
423
+ name: "visibility",
424
+ install(ctx) {
425
+ onChange = () => {
426
+ ctx.logger.logEvent("page.visibility", { state: document.visibilityState });
427
+ };
428
+ document.addEventListener("visibilitychange", onChange);
429
+ },
430
+ uninstall() {
431
+ if (onChange) {
432
+ document.removeEventListener("visibilitychange", onChange);
433
+ }
434
+ },
435
+ };
436
+
437
+ configure({ endpoint: "https://ingest.example/v1/logs", capture: { plugins: [visibility] } });
438
+ ```
439
+
389
440
  `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 a RegExp in `propagateTraceHeaderTo` match the full URL.
390
441
 
391
442
  A string in `propagateTraceHeaderTo` is an origin, for example `"https://api.example"`. It matches a request to that origin only. A URL with a path gives its origin. A relative request URL resolves against the page. To match a path, use a RegExp. A RegExp tests the request URL in the form that the caller gives. Start each RegExp with `^`. Without it, `/\/api\//` also matches `https://vendor.example/api/`. For example, `/^https:\/\/api\.example\/v2\//` matches one path on one origin. `/^\/api\//` matches a relative request URL only.
392
443
 
444
+ ### Spans
445
+
446
+ With `tracesEndpoint`, the library sends spans. The backend then has a root span for each trace of the library.
447
+
448
+ - **Root span:** Each ambient trace has one root span of kind INTERNAL. It starts with the trace and ends when the trace rotates. Its name tells why the trace started: `ui.start`, `ui.interaction`, `ui.navigation` or `ui.trace`.
449
+ - **Client span:** Each `fetch` or XHR request that gets `traceparent` from `capture.propagateTraceHeaderTo` has one span of kind CLIENT. The `traceparent` names the client span, and the root span is its parent. Its name is the HTTP method. Its attributes are `http.request.method`, `url.full`, `server.address`, `http.response.status_code` and `error.type`. A status of 0 or 400 and more sets the status ERROR.
450
+ - **Sampling:** `sampling.defaultRate` samples each trace by its trace id. The whole trace stays or goes. `minLevel` does not apply to a span. For a trace that sampling drops, the `traceparent` has the sampled flag off. A downstream service then drops its spans too.
451
+ - **Exit:** The exit flush and `shutdown()` end the root span of the active trace. The root span of a trace ends one time. A tab that becomes hidden ends it too, because a mobile OS can stop a hidden page.
452
+ - **OpenTelemetry:** With `otelLoader`, a trace from the OpenTelemetry API keeps its own spans. The library sends no span for it.
453
+ - `getTraceHeaders()` names the root span. Your server span is then a child of the root span.
454
+ - Span records go through `processors` and `redact`. They also carry the context attributes of a record, for example `page.url` and `journey.id`.
455
+
393
456
  ### Browser Storage Keys
394
457
 
395
- | Key | Store | Written when | Option that stops it |
396
- | ------------------------------ | ---------------- | ---------------------------------------------------------------- | --------------------------------------------- |
397
- | `ui-observability.session` | `localStorage` | At startup, then at most one time each minute while logging | `identity: "memory"` |
398
- | `ui-observability.tab` | `sessionStorage` | At startup, and when the bus finds a duplicated tab | `identity: "memory"` |
399
- | `ui-observability.journey` | `sessionStorage` | When a journey starts or ends | `identity: "memory"` |
400
- | `ui-observability.batch.*` | `localStorage` | When a send fails and the `localstorage` adapter holds the batch | `storage` other than `auto` or `localstorage` |
401
- | `ui-observability.emergency.*` | `localStorage` | When the exit flush cannot send a batch | `endpoint: null` |
402
- | `ui-observability.probe` | `localStorage` | One write and one remove, when the library tests `localStorage` | `storage` other than `auto` or `localstorage` |
458
+ | Key | Store | Written when | Option that stops it |
459
+ | ------------------------------ | ---------------- | ---------------------------------------------------------------- | ------------------------------------------------- |
460
+ | `ui-observability.session` | `localStorage` | At startup, then at most one time each minute while logging | `identity: "memory"` |
461
+ | `ui-observability.tab` | `sessionStorage` | At startup, and when the bus finds a duplicated tab | `identity: "memory"` |
462
+ | `ui-observability.journey` | `sessionStorage` | When a journey starts or ends | `identity: "memory"` |
463
+ | `ui-observability.batch.*` | `localStorage` | When a send fails and the `localstorage` adapter holds the batch | `storage` other than `auto` or `localstorage` |
464
+ | `ui-observability.emergency.*` | `localStorage` | When the exit flush cannot send a batch | `endpoint: null`, `storage: "memory"` or `"none"` |
465
+ | `ui-observability.probe` | `localStorage` | One write and one remove, when the library tests `localStorage` | `storage` other than `auto` or `localstorage` |
403
466
 
404
467
  IndexedDB holds undelivered batches with `storage: "auto"` or `"indexeddb"`.
405
468
 
406
469
  ---
407
470
 
471
+ ## Reference Documents
472
+
473
+ - [Attribute reference](docs/attributes.md): each attribute that the library writes, and its type.
474
+ - [Browser support](docs/browser-support.md): the browser APIs that the library uses, and the fallback for each.
475
+ - [Threat model](docs/threat-model.md): the trust boundaries, the threats and the controls.
476
+
477
+ ---
478
+
408
479
  ## Core Architecture
409
480
 
410
481
  - **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.
411
482
  - **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.
412
483
  - **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.
484
+ - **One sender for each tab:** Each top-level tab or window has its own sender. Two tabs of one origin send their records separately. They have the same `session.id` and a different `tab.id`. A retry of stored batches runs in one tab at a time, under a Web Lock.
413
485
  - **Five correlation ids:** Each record carries `session.id`, `tab.id`, `context.id`, `journey.id` and `trace_id`.
414
486
  - **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. When the document becomes hidden, the library runs a normal flush with the headers, gzip and retry. While the document is hidden, a send of 60 KB or less uses `keepalive`. A mobile OS can stop a hidden page with no `pagehide`. On `pagehide`, `freeze` or OpenFin close, it sends pending records with `navigator.sendBeacon` if they are below 60 KB. With `headers`, it uses a keepalive fetch with the last headers, because a beacon cannot set a header. A larger payload goes to the emergency queue. `shutdown()` runs a normal flush before the exit flush. An action is an audit fact. When storage is over `retention.maxBatches` or over the quota of the browser, it removes the batches without an action first. Before startup, the hold buffers keep up to 2000 actions. The 500-record limit applies only to other records. `onDrop` tells the app about each loss.
487
+ - **Server (Node):** On Node, for example during server-side rendering, the library runs console-only. It installs no capture, keeps the ids in memory, uses no storage and has no exit flush. If you set `endpoint`, `metricsEndpoint`, `tracesEndpoint` or `transport`, it reports `config.invalid` one time.
415
488
  - **One library version on a page:** If a copy of another version owns the page runtime, this copy runs console-only. It installs no capture and reports `runtime.version_mismatch`. Load one version of the library on the page.
416
- - **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.
489
+ - **Emergency queue:** The emergency queue is best effort. With `storage: "memory"` or `"none"`, the exit flush does not use it. A batch that it cannot send is then lost, and `onDrop` reports `not_stored`. 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.
417
490
  - **Configuration after startup:** A second `configure()` call merges the new options into the live runtime. The runtime refuses 5 changes and reports `config.invalid` for each:
418
491
  - A change to `storage`. The stored batches stay in the adapter that the runtime built at startup.
419
492
  - A change to `identity`. The ids exist from startup.
@@ -444,9 +517,11 @@ The ingest server must meet these requirements:
444
517
  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.
445
518
  4. **Throttling:** Return `429` or `503` with `Retry-After`. Expose the header with `Access-Control-Expose-Headers: retry-after`. The library waits 60 s at most.
446
519
  5. **Status codes:** `200`, `202` and `204` accept the batch. `413` makes the library split the batch. With a `headers` function, a `401` or `403` gets one more send with new headers. The library drops a batch that gets any other `4xx`.
447
- 6. **Metrics endpoint (optional):** With `metricsEndpoint`, the library sends each batch of metric records there as an OTLP/JSON `ExportMetricsServiceRequest`. The rules 1 to 5 also apply to that endpoint. A throttle or a failed batch of one endpoint does not hold back the batches of the other endpoint. `headers` applies to both endpoints. Each point is a delta from the previous point of its attribute set. A histogram point with a negative value has no `sum`.
520
+ 6. **Metrics and traces endpoints (optional):** With `metricsEndpoint`, the library sends each batch of metric records there as an OTLP/JSON `ExportMetricsServiceRequest`. With `tracesEndpoint`, it sends each batch of span records there as an OTLP/JSON `ExportTraceServiceRequest`. The rules 1 to 5 also apply to these endpoints. A throttle or a failed batch of one endpoint does not hold back the batches of another endpoint. `headers` applies to each endpoint. Each point is a delta from the previous point of its attribute set. A histogram point with a negative value has no `sum`.
448
521
  7. **Remote sampling (optional):** To send sampling rules, add `X-UiObs-Sampling` to a `2xx` answer. Expose the header with `Access-Control-Expose-Headers: x-uiobs-sampling`.
449
522
 
523
+ `tools/reference-collector.mjs` implements each rule with no dependencies. It is not part of the package. Run `node tools/reference-collector.mjs`. Set `ALLOWED_ORIGINS` to the origins of your app. Set `UPSTREAM_URL` to an OTLP/HTTP collector, for example `http://localhost:4318`, to forward each OTLP batch there. The file lists the other settings: `PORT`, `AUTH_TOKEN`, `SAMPLING_RULES`, `MAX_BODY_BYTES` and `MAX_REQUESTS_PER_SECOND`.
524
+
450
525
  ---
451
526
 
452
527
  ## Development
@@ -0,0 +1,2 @@
1
+ const e=require("./constants-BgRS6MB0.cjs"),t=require("./identity-Bwku7zzN.cjs");function n(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`id`),n=Reflect.get(e,`createdAt`),r=Reflect.get(e,`attempts`),i=Reflect.get(e,`records`);return typeof t==`string`&&typeof n==`number`&&typeof r==`number`&&Array.isArray(i)}function r(e,n){if(e.records.length<2)return null;let r=Math.floor(e.records.length/2),i=r=>({id:t.i(n),records:r,createdAt:e.createdAt,attempts:e.attempts});return[i(e.records.slice(0,r)),i(e.records.slice(r))]}function i(e,t){let n=e;if(typeof n!=`object`||!n)return;let r=Reflect.get(n,`attributes`);if(typeof r==`object`&&r)return Reflect.get(r,t)}function a(t){return i(t,e.d)===e._t}function o(e){return e.reduce((e,t)=>e+t.records.length,0)}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return i}});
2
+ //# sourceMappingURL=batch-C4oF6XZT.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch-C4oF6XZT.cjs","names":["newId","ATTR_LOG_TYPE","LOG_TYPE_ACTION","require_constants","require_identity","isLogBatch","value","id","createdAt","attempts","records","splitBatch","batch","middle","halve","diagnostics","attributeOf","record","attributes","key","isActionRecord","countRecords","batches","total"],"sources":["../src/models/batch.ts"],"sourcesContent":["// src/models/batch.ts\n//\n// A batch of log records for delivery to the ingest endpoint.\n\nimport { ATTR_LOG_TYPE, LOG_TYPE_ACTION } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { newId } from \"../utils/identity\";\nimport type { LogRecord } from \"./log-record\";\n\n/**\n * A batch of records with a stable id used for server-side deduplication across retries.\n * @see {@link splitBatch}\n */\nexport interface LogBatch {\n /** Deduplication key. It stays the same across retries and reloads. */\n id: string;\n /** Records to deliver, in log order. */\n records: LogRecord[];\n /** Batch creation time, in epoch milliseconds. */\n createdAt: number;\n /** Delivery attempts so far. */\n attempts: number;\n}\n\n/**\n * Tells if a value from storage has all fields of a batch. `keyOf` cannot match\n * an entry without `id` after delivery. The library then retries that entry with no\n * end, and the entry blocks each batch behind it. An entry without `attempts` counts\n * as NaN. That count never reaches `maxAttempts`. Thus the library never drops the\n * entry as a dead letter.\n * @param value Parsed storage entry.\n * @returns True when each required field is present and has the correct type.\n */\nexport function isLogBatch(value: unknown): value is LogBatch {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const id: unknown = Reflect.get(value, \"id\");\n const createdAt: unknown = Reflect.get(value, \"createdAt\");\n const attempts: unknown = Reflect.get(value, \"attempts\");\n const records: unknown = Reflect.get(value, \"records\");\n\n return (\n typeof id === \"string\" &&\n typeof createdAt === \"number\" &&\n typeof attempts === \"number\" &&\n Array.isArray(records)\n );\n}\n\n/**\n * Splits a batch that the server rejected as too large into two halves.\n * Each half gets a new id. Each half keeps the age and attempts of the original batch.\n * @param batch The rejected batch.\n * @param diagnostics Diagnostics reporter for the new batch ids.\n * @returns Two batches, or `null` if a single record is already over the limit.\n */\nexport function splitBatch(batch: LogBatch, diagnostics: Diagnostics): [LogBatch, LogBatch] | null {\n if (batch.records.length < 2) {\n return null;\n }\n\n const middle = Math.floor(batch.records.length / 2);\n const halve = (records: LogRecord[]): LogBatch => ({\n id: newId(diagnostics),\n records,\n createdAt: batch.createdAt,\n attempts: batch.attempts,\n });\n\n return [halve(batch.records.slice(0, middle)), halve(batch.records.slice(middle))];\n}\n\n/**\n * Reads one attribute of a record. A record from storage can be corrupt. It can be null or have\n * no attributes.\n * @param record Record to read.\n * @param key Attribute key.\n * @returns The attribute value, or undefined for a corrupt record.\n */\nexport function attributeOf(record: LogRecord, key: string): unknown {\n const value: unknown = record;\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n const attributes: unknown = Reflect.get(value, \"attributes\");\n if (typeof attributes !== \"object\" || attributes === null) {\n return undefined;\n }\n\n return Reflect.get(attributes, key);\n}\n\n/**\n * Tests if a record is an action. A corrupt record from storage is not an action.\n * @param record Record to test.\n * @returns True for an action record.\n */\nexport function isActionRecord(record: LogRecord): boolean {\n return attributeOf(record, ATTR_LOG_TYPE) === LOG_TYPE_ACTION;\n}\n\n/**\n * Returns the total record count of the batches.\n * @param batches Batches to measure.\n * @returns Total record count.\n */\nexport function countRecords(batches: readonly LogBatch[]): number {\n return batches.reduce((total, batch) => total + batch.records.length, 0);\n}\n"],"mappings":"iFAiCA,SAAgBK,EAAW,EAAmC,CAC5D,GAAI,OAAOC,GAAU,WAAYA,EAC/B,MAAO,GAGT,IAAMC,EAAc,QAAQ,IAAID,EAAO,IAAI,EACrCE,EAAqB,QAAQ,IAAIF,EAAO,WAAW,EACnDG,EAAoB,QAAQ,IAAIH,EAAO,UAAU,EACjDI,EAAmB,QAAQ,IAAIJ,EAAO,SAAS,EAErD,OACE,OAAOC,GAAO,UACd,OAAOC,GAAc,UACrB,OAAOC,GAAa,UACpB,MAAM,QAAQC,CAAO,CAEzB,CASA,SAAgBC,EAAW,EAAiB,EAAuD,CACjG,GAAIC,EAAM,QAAQ,OAAS,EACzB,OAAO,KAGT,IAAMC,EAAS,KAAK,MAAMD,EAAM,QAAQ,OAAS,CAAC,EAC5CE,EAAS,IAAoC,CACjD,GAAId,EAAAA,EAAMe,CAAW,EACrB,UACA,UAAWH,EAAM,UACjB,SAAUA,EAAM,QAClB,GAEA,MAAO,CAACE,EAAMF,EAAM,QAAQ,MAAM,EAAGC,CAAM,CAAC,EAAGC,EAAMF,EAAM,QAAQ,MAAMC,CAAM,CAAC,CAAC,CACnF,CASA,SAAgBG,EAAY,EAAmB,EAAsB,CACnE,IAAMV,EAAiBW,EACvB,GAAI,OAAOX,GAAU,WAAYA,EAC/B,OAGF,IAAMY,EAAsB,QAAQ,IAAIZ,EAAO,YAAY,EAC3D,GAAI,OAAOY,GAAe,UAAYA,EAItC,OAAO,QAAQ,IAAIA,EAAYC,CAAG,CACpC,CAOA,SAAgBC,EAAe,EAA4B,CACzD,OAAOJ,EAAYC,EAAQhB,EAAAA,CAAa,IAAMC,EAAAA,EAChD,CAOA,SAAgBmB,EAAa,EAAsC,CACjE,OAAOC,EAAQ,QAAQ,EAAO,IAAUC,EAAQX,EAAM,QAAQ,OAAQ,CAAC,CACzE"}
@@ -1,5 +1,5 @@
1
- import { d as e, mt as t } from "./constants-CQ_D7jIW.js";
2
- import { i as n } from "./identity-rpEyjvVg.js";
1
+ import { _t as e, d as t } from "./constants-L_d5YvvQ.js";
2
+ import { i as n } from "./identity-Dtv917nz.js";
3
3
  //#region src/models/batch.ts
4
4
  function r(e) {
5
5
  if (typeof e != "object" || !e) return !1;
@@ -23,9 +23,12 @@ function a(e, t) {
23
23
  if (typeof r == "object" && r) return Reflect.get(r, t);
24
24
  }
25
25
  function o(n) {
26
- return a(n, e) === t;
26
+ return a(n, t) === e;
27
+ }
28
+ function s(e) {
29
+ return e.reduce((e, t) => e + t.records.length, 0);
27
30
  }
28
31
  //#endregion
29
- export { i, o as n, r, a as t };
32
+ export { i as a, r as i, s as n, o as r, a as t };
30
33
 
31
- //# sourceMappingURL=batch-4xKzzSCj.js.map
34
+ //# sourceMappingURL=batch-D-4xl7op.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch-D-4xl7op.js","names":["LOG_TYPE_ACTION","ATTR_LOG_TYPE","newId","isLogBatch","value","id","createdAt","attempts","records","splitBatch","batch","middle","halve","diagnostics","attributeOf","record","attributes","key","isActionRecord","countRecords","batches","total"],"sources":["../src/models/batch.ts"],"sourcesContent":["// src/models/batch.ts\n//\n// A batch of log records for delivery to the ingest endpoint.\n\nimport { ATTR_LOG_TYPE, LOG_TYPE_ACTION } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { newId } from \"../utils/identity\";\nimport type { LogRecord } from \"./log-record\";\n\n/**\n * A batch of records with a stable id used for server-side deduplication across retries.\n * @see {@link splitBatch}\n */\nexport interface LogBatch {\n /** Deduplication key. It stays the same across retries and reloads. */\n id: string;\n /** Records to deliver, in log order. */\n records: LogRecord[];\n /** Batch creation time, in epoch milliseconds. */\n createdAt: number;\n /** Delivery attempts so far. */\n attempts: number;\n}\n\n/**\n * Tells if a value from storage has all fields of a batch. `keyOf` cannot match\n * an entry without `id` after delivery. The library then retries that entry with no\n * end, and the entry blocks each batch behind it. An entry without `attempts` counts\n * as NaN. That count never reaches `maxAttempts`. Thus the library never drops the\n * entry as a dead letter.\n * @param value Parsed storage entry.\n * @returns True when each required field is present and has the correct type.\n */\nexport function isLogBatch(value: unknown): value is LogBatch {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const id: unknown = Reflect.get(value, \"id\");\n const createdAt: unknown = Reflect.get(value, \"createdAt\");\n const attempts: unknown = Reflect.get(value, \"attempts\");\n const records: unknown = Reflect.get(value, \"records\");\n\n return (\n typeof id === \"string\" &&\n typeof createdAt === \"number\" &&\n typeof attempts === \"number\" &&\n Array.isArray(records)\n );\n}\n\n/**\n * Splits a batch that the server rejected as too large into two halves.\n * Each half gets a new id. Each half keeps the age and attempts of the original batch.\n * @param batch The rejected batch.\n * @param diagnostics Diagnostics reporter for the new batch ids.\n * @returns Two batches, or `null` if a single record is already over the limit.\n */\nexport function splitBatch(batch: LogBatch, diagnostics: Diagnostics): [LogBatch, LogBatch] | null {\n if (batch.records.length < 2) {\n return null;\n }\n\n const middle = Math.floor(batch.records.length / 2);\n const halve = (records: LogRecord[]): LogBatch => ({\n id: newId(diagnostics),\n records,\n createdAt: batch.createdAt,\n attempts: batch.attempts,\n });\n\n return [halve(batch.records.slice(0, middle)), halve(batch.records.slice(middle))];\n}\n\n/**\n * Reads one attribute of a record. A record from storage can be corrupt. It can be null or have\n * no attributes.\n * @param record Record to read.\n * @param key Attribute key.\n * @returns The attribute value, or undefined for a corrupt record.\n */\nexport function attributeOf(record: LogRecord, key: string): unknown {\n const value: unknown = record;\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n const attributes: unknown = Reflect.get(value, \"attributes\");\n if (typeof attributes !== \"object\" || attributes === null) {\n return undefined;\n }\n\n return Reflect.get(attributes, key);\n}\n\n/**\n * Tests if a record is an action. A corrupt record from storage is not an action.\n * @param record Record to test.\n * @returns True for an action record.\n */\nexport function isActionRecord(record: LogRecord): boolean {\n return attributeOf(record, ATTR_LOG_TYPE) === LOG_TYPE_ACTION;\n}\n\n/**\n * Returns the total record count of the batches.\n * @param batches Batches to measure.\n * @returns Total record count.\n */\nexport function countRecords(batches: readonly LogBatch[]): number {\n return batches.reduce((total, batch) => total + batch.records.length, 0);\n}\n"],"mappings":";;;AAiCA,SAAgBG,EAAW,GAAmC;CAC5D,IAAI,OAAOC,KAAU,aAAYA,GAC/B,OAAO;CAGT,IAAMC,IAAc,QAAQ,IAAID,GAAO,IAAI,GACrCE,IAAqB,QAAQ,IAAIF,GAAO,WAAW,GACnDG,IAAoB,QAAQ,IAAIH,GAAO,UAAU,GACjDI,IAAmB,QAAQ,IAAIJ,GAAO,SAAS;CAErD,OACE,OAAOC,KAAO,YACd,OAAOC,KAAc,YACrB,OAAOC,KAAa,YACpB,MAAM,QAAQC,CAAO;AAEzB;AASA,SAAgBC,EAAW,GAAiB,GAAuD;CACjG,IAAIC,EAAM,QAAQ,SAAS,GACzB,OAAO;CAGT,IAAMC,IAAS,KAAK,MAAMD,EAAM,QAAQ,SAAS,CAAC,GAC5CE,KAAS,OAAoC;EACjD,IAAIV,EAAMW,CAAW;EACrB;EACA,WAAWH,EAAM;EACjB,UAAUA,EAAM;CAClB;CAEA,OAAO,CAACE,EAAMF,EAAM,QAAQ,MAAM,GAAGC,CAAM,CAAC,GAAGC,EAAMF,EAAM,QAAQ,MAAMC,CAAM,CAAC,CAAC;AACnF;AASA,SAAgBG,EAAY,GAAmB,GAAsB;CACnE,IAAMV,IAAiBW;CACvB,IAAI,OAAOX,KAAU,aAAYA,GAC/B;CAGF,IAAMY,IAAsB,QAAQ,IAAIZ,GAAO,YAAY;CAC3D,IAAI,OAAOY,KAAe,YAAYA,GAItC,OAAO,QAAQ,IAAIA,GAAYC,CAAG;AACpC;AAOA,SAAgBC,EAAe,GAA4B;CACzD,OAAOJ,EAAYC,GAAQd,CAAa,MAAMD;AAChD;AAOA,SAAgBmB,EAAa,GAAsC;CACjE,OAAOC,EAAQ,QAAQ,GAAO,MAAUC,IAAQX,EAAM,QAAQ,QAAQ,CAAC;AACzE"}
package/dist/bus/bus.d.ts CHANGED
@@ -47,8 +47,6 @@ export declare class Bus {
47
47
  private openFinLink;
48
48
  /** True if this context is the OpenFin platform provider. */
49
49
  private isOpenFinProvider;
50
- /** True if role resolution is complete. */
51
- private resolved;
52
50
  /** Timer that asks the upstream owner for the remote sampling rules. */
53
51
  private rulesPoll;
54
52
  /** True after destroy(). A handshake that ends later must not start a timer. */
@@ -68,8 +66,6 @@ export declare class Bus {
68
66
  constructor(config: ResolvedConfig, diagnostics: Diagnostics, platform: PlatformMetadata, contextId: string, tabId: string, handlers: BusHandlers, handshakeOptions?: HandshakeOptions);
69
67
  /** Returns the resolved bus role. */
70
68
  getRole(): BusRole;
71
- /** Returns true if role resolution is complete. */
72
- isResolved(): boolean;
73
69
  /**
74
70
  * Resolves bus role and establishes control links.
75
71
  * @returns Resolved role.