@utk09/ui-observability 0.9.1 → 0.9.3

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 (172) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +75 -64
  3. package/dist/batch-D5qvsMQ_.cjs +2 -0
  4. package/dist/batch-D5qvsMQ_.cjs.map +1 -0
  5. package/dist/{batch-DEK4bv9N.js → batch-DDgxg16_.js} +7 -4
  6. package/dist/batch-DDgxg16_.js.map +1 -0
  7. package/dist/bus/bus.d.ts +0 -4
  8. package/dist/{bus-HVQ8E72V.js → bus-C6RwKzPW.js} +63 -66
  9. package/dist/bus-C6RwKzPW.js.map +1 -0
  10. package/dist/bus-WPVDFw2y.cjs +2 -0
  11. package/dist/bus-WPVDFw2y.cjs.map +1 -0
  12. package/dist/capture/network.d.ts +2 -0
  13. package/dist/capture/storm.d.ts +2 -7
  14. package/dist/capture/types.d.ts +3 -0
  15. package/dist/{console-DssDxq1B.cjs → console-BSusX_M-.cjs} +2 -2
  16. package/dist/{console-DssDxq1B.cjs.map → console-BSusX_M-.cjs.map} +1 -1
  17. package/dist/{console-C9Y639mn.js → console-Dv5GfaNn.js} +3 -3
  18. package/dist/{console-C9Y639mn.js.map → console-Dv5GfaNn.js.map} +1 -1
  19. package/dist/constants-Cb92egPS.cjs +2 -0
  20. package/dist/constants-Cb92egPS.cjs.map +1 -0
  21. package/dist/{constants-N99w84xy.js → constants-DhH6VI5a.js} +39 -12
  22. package/dist/constants-DhH6VI5a.js.map +1 -0
  23. package/dist/constants.d.ts +28 -3
  24. package/dist/core/breadcrumbs.d.ts +1 -3
  25. package/dist/core/context.d.ts +0 -8
  26. package/dist/core/diagnostics.d.ts +1 -3
  27. package/dist/core/meter.d.ts +45 -0
  28. package/dist/core/pipeline.d.ts +5 -12
  29. package/dist/core/record.d.ts +7 -0
  30. package/dist/core/runtime.d.ts +17 -0
  31. package/dist/core/sampling.d.ts +3 -3
  32. package/dist/core/sender.d.ts +2 -0
  33. package/dist/deadline-CUrH0Hd8.cjs +2 -0
  34. package/dist/deadline-CUrH0Hd8.cjs.map +1 -0
  35. package/dist/deadline-DeqXEliN.js +31 -0
  36. package/dist/deadline-DeqXEliN.js.map +1 -0
  37. package/dist/{errors-CQusIGWJ.js → errors-DCZWcHkd.js} +4 -4
  38. package/dist/{errors-CQusIGWJ.js.map → errors-DCZWcHkd.js.map} +1 -1
  39. package/dist/{errors-BTWuVnHZ.cjs → errors-ERu-su8m.cjs} +3 -3
  40. package/dist/{errors-BTWuVnHZ.cjs.map → errors-ERu-su8m.cjs.map} +1 -1
  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-B1GDS1Tb.cjs → identity-C1WLItSl.cjs} +2 -2
  46. package/dist/{identity-B1GDS1Tb.cjs.map → identity-C1WLItSl.cjs.map} +1 -1
  47. package/dist/{identity-D4DPjTM9.js → identity-Di-QXGCC.js} +2 -2
  48. package/dist/{identity-D4DPjTM9.js.map → identity-Di-QXGCC.js.map} +1 -1
  49. package/dist/index.cjs +1 -1
  50. package/dist/index.cjs.map +1 -1
  51. package/dist/index.d.ts +18 -0
  52. package/dist/index.js +522 -369
  53. package/dist/index.js.map +1 -1
  54. package/dist/indexeddb-storage-DX18p39D.cjs +2 -0
  55. package/dist/indexeddb-storage-DX18p39D.cjs.map +1 -0
  56. package/dist/{indexeddb-storage-B8SGUzSV.js → indexeddb-storage-T9YIYVYC.js} +48 -59
  57. package/dist/indexeddb-storage-T9YIYVYC.js.map +1 -0
  58. package/dist/{interactions-CnjfQgw3.js → interactions-BLH_tX87.js} +2 -2
  59. package/dist/{interactions-CnjfQgw3.js.map → interactions-BLH_tX87.js.map} +1 -1
  60. package/dist/{interactions-CcxrVzpg.cjs → interactions-_hfOerfC.cjs} +2 -2
  61. package/dist/{interactions-CcxrVzpg.cjs.map → interactions-_hfOerfC.cjs.map} +1 -1
  62. package/dist/journey-BRUj0hqD.cjs +2 -0
  63. package/dist/journey-BRUj0hqD.cjs.map +1 -0
  64. package/dist/{journey-DjvDzHyp.js → journey-yALMEWF7.js} +39 -38
  65. package/dist/journey-yALMEWF7.js.map +1 -0
  66. package/dist/library-request-BcAxuwsf.cjs +2 -0
  67. package/dist/library-request-BcAxuwsf.cjs.map +1 -0
  68. package/dist/library-request-CQD4HUiP.js +25 -0
  69. package/dist/library-request-CQD4HUiP.js.map +1 -0
  70. package/dist/{long-frames-BGik_Yhy.cjs → long-frames-D4Bm3Zkz.cjs} +2 -2
  71. package/dist/{long-frames-BGik_Yhy.cjs.map → long-frames-D4Bm3Zkz.cjs.map} +1 -1
  72. package/dist/{long-frames-CZk3XOkH.js → long-frames-DD_Um9_4.js} +3 -3
  73. package/dist/{long-frames-CZk3XOkH.js.map → long-frames-DD_Um9_4.js.map} +1 -1
  74. package/dist/models/batch.d.ts +6 -0
  75. package/dist/models/config.d.ts +23 -0
  76. package/dist/models/metric.d.ts +50 -0
  77. package/dist/network--GoE7_Or.js +211 -0
  78. package/dist/network--GoE7_Or.js.map +1 -0
  79. package/dist/network-DcuS2H1P.cjs +2 -0
  80. package/dist/network-DcuS2H1P.cjs.map +1 -0
  81. package/dist/openfin-BwEN0uj4.js +8 -0
  82. package/dist/openfin-BwEN0uj4.js.map +1 -0
  83. package/dist/openfin-DtH2f7zX.cjs +2 -0
  84. package/dist/openfin-DtH2f7zX.cjs.map +1 -0
  85. package/dist/platform-GaM6h7XM.js +52 -0
  86. package/dist/platform-GaM6h7XM.js.map +1 -0
  87. package/dist/platform-kIL5AZB7.cjs +2 -0
  88. package/dist/platform-kIL5AZB7.cjs.map +1 -0
  89. package/dist/{remote-rules-M-XZ1xbe.js → remote-rules-6ePq8CrI.js} +23 -25
  90. package/dist/remote-rules-6ePq8CrI.js.map +1 -0
  91. package/dist/remote-rules-CI3gbRCL.cjs +2 -0
  92. package/dist/remote-rules-CI3gbRCL.cjs.map +1 -0
  93. package/dist/sampling-C-M8p3FK.cjs +2 -0
  94. package/dist/sampling-C-M8p3FK.cjs.map +1 -0
  95. package/dist/sampling-Ud_WiuU9.js +65 -0
  96. package/dist/sampling-Ud_WiuU9.js.map +1 -0
  97. package/dist/{sanitize-DKp5MRsa.cjs → sanitize--_e4oOPX.cjs} +2 -2
  98. package/dist/{sanitize-DKp5MRsa.cjs.map → sanitize--_e4oOPX.cjs.map} +1 -1
  99. package/dist/{sanitize-Dwj9JCkI.js → sanitize-DP0xDPrt.js} +2 -2
  100. package/dist/{sanitize-Dwj9JCkI.js.map → sanitize-DP0xDPrt.js.map} +1 -1
  101. package/dist/sender-BESHz6my.cjs +3 -0
  102. package/dist/sender-BESHz6my.cjs.map +1 -0
  103. package/dist/{sender-BBY0IcUo.js → sender-BUBWLn5i.js} +425 -290
  104. package/dist/sender-BUBWLn5i.js.map +1 -0
  105. package/dist/storage/gap.d.ts +20 -0
  106. package/dist/storage/indexeddb-storage.d.ts +1 -7
  107. package/dist/storage/keys.d.ts +9 -0
  108. package/dist/storage/local-storage.d.ts +0 -6
  109. package/dist/storage/memory-storage.d.ts +1 -1
  110. package/dist/storm-DhHGHhOc.cjs +2 -0
  111. package/dist/storm-DhHGHhOc.cjs.map +1 -0
  112. package/dist/storm-OD5J6Ylm.js +10 -0
  113. package/dist/storm-OD5J6Ylm.js.map +1 -0
  114. package/dist/transport/custom-transport.d.ts +3 -2
  115. package/dist/transport/exit-flush.d.ts +13 -2
  116. package/dist/transport/http-transport.d.ts +6 -4
  117. package/dist/transport/retry-engine.d.ts +3 -1
  118. package/dist/transport/serializers/otlp-metrics.d.ts +3 -0
  119. package/dist/transport/serializers/otlp.d.ts +30 -0
  120. package/dist/transport/serializers/select.d.ts +20 -4
  121. package/dist/transport/status-transport.d.ts +19 -11
  122. package/dist/utils/fixed-window.d.ts +15 -0
  123. package/dist/utils/guards.d.ts +6 -0
  124. package/dist/utils/library-request.d.ts +12 -0
  125. package/dist/utils/openfin.d.ts +48 -0
  126. package/dist/utils/platform.d.ts +5 -0
  127. package/package.json +2 -3
  128. package/dist/batch-DEK4bv9N.js.map +0 -1
  129. package/dist/batch-DEVFs28i.cjs +0 -2
  130. package/dist/batch-DEVFs28i.cjs.map +0 -1
  131. package/dist/bus-DNFvTkif.cjs +0 -2
  132. package/dist/bus-DNFvTkif.cjs.map +0 -1
  133. package/dist/bus-HVQ8E72V.js.map +0 -1
  134. package/dist/constants-N99w84xy.js.map +0 -1
  135. package/dist/constants-X86IDwkC.cjs +0 -2
  136. package/dist/constants-X86IDwkC.cjs.map +0 -1
  137. package/dist/deadline-5_PecIl5.js +0 -26
  138. package/dist/deadline-5_PecIl5.js.map +0 -1
  139. package/dist/deadline-XSnm95pg.cjs +0 -2
  140. package/dist/deadline-XSnm95pg.cjs.map +0 -1
  141. package/dist/indexeddb-storage-B8SGUzSV.js.map +0 -1
  142. package/dist/indexeddb-storage-ukzC82dm.cjs +0 -2
  143. package/dist/indexeddb-storage-ukzC82dm.cjs.map +0 -1
  144. package/dist/journey-DjvDzHyp.js.map +0 -1
  145. package/dist/journey-DxlfdFJV.cjs +0 -2
  146. package/dist/journey-DxlfdFJV.cjs.map +0 -1
  147. package/dist/library-request-BZ1ekVtl.cjs +0 -2
  148. package/dist/library-request-BZ1ekVtl.cjs.map +0 -1
  149. package/dist/library-request-C8kc5YWv.js +0 -14
  150. package/dist/library-request-C8kc5YWv.js.map +0 -1
  151. package/dist/network-51iicpLl.js +0 -174
  152. package/dist/network-51iicpLl.js.map +0 -1
  153. package/dist/network-jBbjyAJP.cjs +0 -2
  154. package/dist/network-jBbjyAJP.cjs.map +0 -1
  155. package/dist/platform-Cjts-8k8.js +0 -48
  156. package/dist/platform-Cjts-8k8.js.map +0 -1
  157. package/dist/platform-DW3GFIUE.cjs +0 -2
  158. package/dist/platform-DW3GFIUE.cjs.map +0 -1
  159. package/dist/remote-rules-ByS34k4e.cjs +0 -2
  160. package/dist/remote-rules-ByS34k4e.cjs.map +0 -1
  161. package/dist/remote-rules-M-XZ1xbe.js.map +0 -1
  162. package/dist/sampling-BN3Oi6SV.js +0 -63
  163. package/dist/sampling-BN3Oi6SV.js.map +0 -1
  164. package/dist/sampling-b2ck5X98.cjs +0 -2
  165. package/dist/sampling-b2ck5X98.cjs.map +0 -1
  166. package/dist/sender-BBY0IcUo.js.map +0 -1
  167. package/dist/sender-BXoAZKum.cjs +0 -3
  168. package/dist/sender-BXoAZKum.cjs.map +0 -1
  169. package/dist/storm-CKuaBp7i.cjs +0 -2
  170. package/dist/storm-CKuaBp7i.cjs.map +0 -1
  171. package/dist/storm-DhtL2eVr.js +0 -10
  172. package/dist/storm-DhtL2eVr.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,39 @@
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.3] - 2026-10-31
6
+
7
+ ### Fixed - v0.9.3
8
+
9
+ - 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.
10
+
11
+ ## [0.9.2] - 2026-10-30
12
+
13
+ ### Added - v0.9.2
14
+
15
+ - `metricsEndpoint` sets an 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`, as before. It needs `serializer: "otlp"`, and `endpoint` or `transport`. Without `endpoint` and `transport`, the library reports `config.invalid`. Network capture does not log a request to it.
16
+ - With `metricsEndpoint`, each endpoint has its own throttle. A `429` from one endpoint does not stop the batches of the other endpoint. In the retry queue, a failed batch holds back only the batches of its own endpoint.
17
+ - `counter(name, { unit? })` gives a counter. `add(value, attrs?)` sums a value of 0 or larger in memory. At each `batching.metricFlushIntervalMs`, the library sends one point for each attribute set.
18
+ - `histogram(name, { unit?, boundaries? })` gives a histogram. `record(value, attrs?)` counts a value in buckets in memory. Each point has `count`, `sum`, `min`, `max` and the bucket counts. The default boundaries are the OpenTelemetry default boundaries.
19
+ - Sampling and `minLevel` do not drop a point. The console does not print it.
20
+ - Each instrument keeps at most 100 attribute sets in each interval. The values of more sets go to one set with `otel.metric.overflow: true`.
21
+ - The library drops a point attribute key that starts with `metric.`. It also drops the keys that it sets on each record, for example `page.url` and `log.type`.
22
+ - The record limits do not cut the metric fields of a point, for example the bucket counts. `redact` cannot change these fields.
23
+ - The points of the open interval go out at `flush()`, at `shutdown()` and before the exit flush.
24
+ - The package exports the types `Counter`, `Histogram`, `HistogramOptions`, `InstrumentOptions` and `MetricAttributes`.
25
+ - With `metricsEndpoint`, a counter point is an OTLP delta sum. A histogram point is an OTLP delta histogram. A `logMetric()` gauge is an OTLP gauge. A `logMetric()` histogram is a histogram with one value. The point attributes are only the attributes of the call. The context attributes stay off the point. The resource of each request still has `session.id`, `tab.id`, `context.id` and the user agent. A histogram point with a negative value has no `sum`.
26
+ - `request.kind` of a custom transport is `"metrics"` for a batch of metric records when `metricsEndpoint` is set. Each other batch has the kind `"logs"`.
27
+ - A `logMetric()` record has the new attribute `metric.attribute_keys`. It names the attributes of the call.
28
+ - `capture.httpMetrics` records the `http.client.request.duration` histogram of each request that `fetch` or `xhr` capture sees. It is on by default. The unit is seconds. The attributes are `http.request.method`, `http.response.status_code`, `server.address` and `error.type`. The path, the query and the port stay out. The boundaries are the ones that the OpenTelemetry semantic conventions advise.
29
+ - The diagnostic code `capture.transport_request`. Network capture reports it one time when it sees a request during a custom transport call. Put the URL of your transport in `capture.ignoreUrls`. Without it, each send records a duration value, and that value causes the next send.
30
+ - A child frame on an origin in `bus.trustedOrigins` is also trusted for metric points. Its points bypass the sampling and the limit of 100 attribute sets of the parent.
31
+
32
+ ### Changed - v0.9.2
33
+
34
+ - `flush()` and the exit flush send the metric records and the other records in separate batches. A batch never holds both kinds.
35
+ - The keepalive fetches of one exit flush share one budget of 60,000 bytes. A batch that does not fit goes to the emergency queue.
36
+ - With `capture.fetch` or `capture.xhr` on, each interval now gives one histogram point for each method, status and server. Without `metricsEndpoint`, these points are metric log records on `endpoint`. Set `capture.httpMetrics: false` to turn them off.
37
+
5
38
  ## [0.9.1] - 2026-10-29
6
39
 
7
40
  ### Added - v0.9.1
package/README.md CHANGED
@@ -159,11 +159,13 @@ 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
163
  - Without `transportOnExit`, the last batch goes to the emergency queue when the page closes. The next page load sends it.
163
164
  - With `storage: "none"`, the next page load cannot keep that batch. Set `transportOnExit`, or the library loses the last batch.
164
165
  - The library ignores a `retryAfterMs` or a `maxBytes` that is not a finite number. It uses 0 for a negative value.
165
166
  - After the delivery stack loads, you cannot add or remove `transport`. You can replace it with another function.
166
167
  - Network capture skips a request that your transport starts before its first `await`. Put your telemetry URL in `capture.ignoreUrls` too. A request after an `await` is outside that scope.
168
+ - Without that URL in `capture.ignoreUrls`, each send records a value of the `http.client.request.duration` histogram. That value causes the next send, and the sends do not stop. Network capture reports `capture.transport_request` one time when it sees a request during a transport call.
167
169
 
168
170
  ### Testing
169
171
 
@@ -241,23 +243,27 @@ X-UiObs-Sampling: {"v":1,"ttlMs":600000,"defaultRate":0.1,"rates":{"blotter.grid
241
243
 
242
244
  ### Logging Methods
243
245
 
244
- | Function | Description |
245
- | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
246
- | `getLogger(namespace, options?)` | Returns the cached logger for a namespace. With `options`, it returns a new logger that is not cached. |
247
- | `trace(msg, payload?)` | Logs a TRACE record. |
248
- | `debug(msg, payload?)` | Logs a DEBUG record. |
249
- | `info(msg, payload?)` | Logs an INFO record. |
250
- | `warn(msg, payload?)` | Logs a WARN record. |
251
- | `error(msg, err?, payload?)` | Logs an ERROR record with the error and the breadcrumb trail. |
252
- | `fatal(msg, err?, payload?)` | Logs a FATAL record with the error and the breadcrumb trail. |
253
- | `logAction(name, payload?)` | Logs one user action. |
254
- | `logEvent(name, payload?)` | Logs one domain or lifecycle event. |
255
- | `logMetric(name, value, unit?, type?, attrs?)` | Logs a measurement (`gauge`, `counter`, `histogram`). |
256
- | `timeSync(label, fn, attrs?)` | Times a function and emits a duration histogram with `status` `SUCCESS` or `FAILURE`. |
257
- | `timeAsync(label, fn, attrs?)` | Times a promise and emits a duration histogram with `status` `SUCCESS` or `FAILURE`. |
246
+ | Function | Description |
247
+ | ---------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
248
+ | `getLogger(namespace, options?)` | Returns the cached logger for a namespace. With `options`, it returns a new logger that is not cached. |
249
+ | `trace(msg, payload?)` | Logs a TRACE record. |
250
+ | `debug(msg, payload?)` | Logs a DEBUG record. |
251
+ | `info(msg, payload?)` | Logs an INFO record. |
252
+ | `warn(msg, payload?)` | Logs a WARN record. |
253
+ | `error(msg, err?, payload?)` | Logs an ERROR record with the error and the breadcrumb trail. |
254
+ | `fatal(msg, err?, payload?)` | Logs a FATAL record with the error and the breadcrumb trail. |
255
+ | `logAction(name, payload?)` | Logs one user action. |
256
+ | `logEvent(name, payload?)` | Logs one domain or lifecycle event. |
257
+ | `logMetric(name, value, unit?, type?, attrs?)` | Logs a measurement (`gauge`, `counter`, `histogram`). |
258
+ | `counter(name, { unit? })` | Gives a counter. `add(value, attrs?)` sums a value of 0 or larger in memory. The library sends one point for each attribute set at each interval. |
259
+ | `histogram(name, { unit?, boundaries? })` | Gives a histogram. `record(value, attrs?)` counts a value in buckets in memory. The library sends one point for each attribute set at each interval. |
260
+ | `timeSync(label, fn, attrs?)` | Times a function and emits a duration histogram with `status` `SUCCESS` or `FAILURE`. |
261
+ | `timeAsync(label, fn, attrs?)` | Times a promise and emits a duration histogram with `status` `SUCCESS` or `FAILURE`. |
258
262
 
259
263
  The level methods give records with `log.type: "log"`. Records of the library itself have `log.type: "system"`. `logMetric` drops a value that is not finite and counts `record.dropped_malformed`.
260
264
 
265
+ `counter` and `histogram` sum their values for `batching.metricFlushIntervalMs`. Then they send one point for each attribute set. 1000 calls of `add(1)` give one point with the value 1000. Sampling and `minLevel` do not drop a point. The console does not print it. Each instrument keeps at most 100 attribute sets in each interval. The values of more sets go to one set with `otel.metric.overflow: true`. Attribute values must be strings, finite numbers or booleans. The library drops an attribute key that starts with `metric.`. It also drops the keys that it sets on each record, for example `page.url` and `log.type`. The record limits do not cut the metric fields of a point, for example the bucket counts. `redact` cannot change them. Do not use a user id or a URL as an attribute. Each value makes a new series in the backend. The default histogram boundaries are `[0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000]`. The points of the open interval go out at `flush()`, at `shutdown()` and before the exit flush. A frame that forwards its records sends its points at the interval, at `flush()` and at `shutdown()` only.
266
+
261
267
  ### Context & Correlation
262
268
 
263
269
  | Function | Description |
@@ -288,54 +294,55 @@ The level methods give records with `log.type: "log"`. Records of the library it
288
294
 
289
295
  No key is required. Set `endpoint` to send records. A value of the wrong type or outside its range reports `config.invalid`. The value in force stays. Level names can have any case. You cannot change `batching` and `retention` after the delivery stack loads. You cannot change `limits` and `journey.maxAgeMs` after the first `configure()`.
290
296
 
291
- | Key | Default | Description |
292
- | -------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
293
- | `endpoint` | `""` | HTTP endpoint that receives the batches. `null` selects console-only mode. `""` reports `config.invalid`. |
294
- | `serviceName` | `""` | `service.name` on every record. |
295
- | `serviceVersion` | `""` | `service.version` on every record. |
296
- | `environment` | `""` | `deployment.environment` on every record. |
297
- | `enabled` | `true` | Set `false` to stop all logging. Every log call then does nothing. |
298
- | `minLevel` | `"INFO"` | Lowest level that the library sends (`TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`). It does not drop actions and metrics. |
299
- | `compression` | `"gzip"` | `gzip` or `none`. The library compresses a payload above 1 KB only. |
300
- | `serializer` | `"otlp"` | `otlp`, `ecs`, or a custom `LogSerializer`. |
301
- | `credentials` | `"omit"` | Fetch credentials mode. Set `"include"` for cookie auth. |
302
- | `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. |
303
- | `storage` | `"auto"` | Store for undelivered batches: `auto`, `indexeddb`, `localstorage`, `memory` or `none`. Fixed at startup. |
304
- | `identity` | `"storage"` | Store for session, tab and journey ids. `memory` writes no key. Fixed at startup. |
305
- | `sampling.defaultRate` | `1` | Keep rate for a namespace with no rule. |
306
- | `sampling.rates` | `{}` | Keep rate per namespace. The longest matching prefix wins. |
307
- | `sampling.alwaysSampleTypes` | `["action"]` | Record types that ignore the rate. |
308
- | `sampling.remote` | `false` | Reads sampling rules from the `X-UiObs-Sampling` header of each accepted batch (see Remote Sampling). |
309
- | `sampling.remoteMaxRate` | `1` | Highest rate that a remote rule can set. It applies to the remote `defaultRate` and to each remote namespace rate. |
310
- | `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. |
311
- | `bus.trustedOrigins` | `[]` | Origins of other documents that this document trusts. A parent accepts records from a child frame on these origins. A cross-origin child frame forwards its records only to a parent on these origins. The library keeps the origin of each URL. For a sandboxed frame, set `bus.mode: "sender"` in the frame. |
312
- | `bus.openFinRole` | `"auto"` | `auto`, `provider` or `client`. |
313
- | `journey.scope` | `"auto"` | Which contexts adopt a journey. `context`: each context keeps its own. `tab`: a frame or a worker adopts the journey of its owner. `origin`: each context of the origin, also in other tabs. `auto` is `origin` in OpenFin and `tab` in a browser. |
314
- | `journey.maxAgeMs` | `1800000` | Maximum open time of a journey, in milliseconds. Then the library ends it. The range is 60000 to 86400000. |
315
- | `batching.logFlushIntervalMs` | `2000` | Maximum wait of a partial log batch, in milliseconds. The range is 100 to 60000. |
316
- | `batching.logBatchSize` | `100` | Maximum records in one log batch. The range is 1 to 1000. |
317
- | `batching.metricFlushIntervalMs` | `10000` | Maximum wait of a partial metric batch, in milliseconds. The range is 100 to 60000. |
318
- | `batching.metricBatchSize` | `500` | Maximum records in one metric batch. The range is 1 to 1000. |
319
- | `retention.mode` | `"limited"` | `limited` or `until-delivered`. With `until-delivered`, a stored batch has no age limit and no attempt limit. `retention.maxBatches` still applies. A permanent error still drops the batch. A batch that always gets a temporary error stays first. The batches behind it wait. |
320
- | `retention.maxBatches` | `500` | Maximum stored batches. A new batch evicts the oldest batch without an action first. The range is 1 to 5000. |
321
- | `retention.maxAgeMs` | `86400000` | Maximum age of a stored batch, in milliseconds. The range is 60000 to 604800000. |
322
- | `retention.maxAttempts` | `5` | Maximum send attempts of a stored batch. The range is 1 to 20. |
323
- | `limits.maxBodyChars` | `4096` | Maximum body length, in characters. The range is 256 to 65536. |
324
- | `limits.maxAttributeChars` | `8192` | Maximum length of a string attribute, in characters. The range is 256 to 65536. |
325
- | `limits.maxAttributeCount` | `128` | Maximum keys in one object. The range is 1 to 1024. |
326
- | `limits.maxStackChars` | `8192` | Maximum length of an error stack, in characters. The range is 256 to 65536. |
327
- | `limits.maxDepth` | `6` | Maximum depth of a nested value. The range is 1 to 16. |
328
- | `limits.maxArrayLength` | `100` | Maximum items in one array, set or map. The range is 1 to 10000. |
329
- | `limits.maxNodes` | `10000` | Maximum values in one sanitize pass. The range is 100 to 100000. |
330
- | `limits.maxRecordBytes` | `32768` | Maximum attribute bytes of one record. Above it, the library drops the caller attributes. The range is 1024 to 60000. |
331
- | `capture` | See below | Auto-capture settings. |
332
- | `console` | `false` | Prints records to devtools. `true` prints from `DEBUG` up. A level name prints from that level up. An object sets `level` and `styles` (see Console Output). It does not depend on `minLevel`. |
333
- | `transport(request)` | `undefined` | Sends batches through a channel of your app in place of HTTP (see Custom Transport). |
334
- | `transportOnExit(request)` | `undefined` | Sends the last batch while the page closes. It must return a boolean and must not wait. |
335
- | `otelLoader()` | `undefined` | Loads `@opentelemetry/api`. Without it, OTel is off. |
336
- | `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`. |
337
- | `onDiagnostic(event)` | `undefined` | Receives the faults of the library itself. |
338
- | `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. |
297
+ | Key | Default | Description |
298
+ | -------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
299
+ | `endpoint` | `""` | HTTP endpoint that receives the batches. `null` selects console-only mode. `""` reports `config.invalid`. |
300
+ | `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`. |
301
+ | `serviceName` | `""` | `service.name` on every record. |
302
+ | `serviceVersion` | `""` | `service.version` on every record. |
303
+ | `environment` | `""` | `deployment.environment` on every record. |
304
+ | `enabled` | `true` | Set `false` to stop all logging. Every log call then does nothing. |
305
+ | `minLevel` | `"INFO"` | Lowest level that the library sends (`TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`). It does not drop actions and metrics. |
306
+ | `compression` | `"gzip"` | `gzip` or `none`. The library compresses a payload above 1 KB only. |
307
+ | `serializer` | `"otlp"` | `otlp`, `ecs`, or a custom `LogSerializer`. |
308
+ | `credentials` | `"omit"` | Fetch credentials mode. Set `"include"` for cookie auth. |
309
+ | `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
+ | `storage` | `"auto"` | Store for undelivered batches: `auto`, `indexeddb`, `localstorage`, `memory` or `none`. Fixed at startup. |
311
+ | `identity` | `"storage"` | Store for session, tab and journey ids. `memory` writes no key. Fixed at startup. |
312
+ | `sampling.defaultRate` | `1` | Keep rate for a namespace with no rule. |
313
+ | `sampling.rates` | `{}` | Keep rate per namespace. The longest matching prefix wins. |
314
+ | `sampling.alwaysSampleTypes` | `["action"]` | Record types that ignore the rate. |
315
+ | `sampling.remote` | `false` | Reads sampling rules from the `X-UiObs-Sampling` header of each accepted batch (see Remote Sampling). |
316
+ | `sampling.remoteMaxRate` | `1` | Highest rate that a remote rule can set. It applies to the remote `defaultRate` and to each remote namespace rate. |
317
+ | `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. |
318
+ | `bus.trustedOrigins` | `[]` | Origins of other documents that this document trusts. A parent accepts records from a child frame on these origins. A cross-origin child frame forwards its records only to a parent on these origins. The library keeps the origin of each URL. For a sandboxed frame, set `bus.mode: "sender"` in the frame. A trusted origin is also trusted for metric points. Its points bypass the sampling and the limit of 100 attribute sets of this document. |
319
+ | `bus.openFinRole` | `"auto"` | `auto`, `provider` or `client`. |
320
+ | `journey.scope` | `"auto"` | Which contexts adopt a journey. `context`: each context keeps its own. `tab`: a frame or a worker adopts the journey of its owner. `origin`: each context of the origin, also in other tabs. `auto` is `origin` in OpenFin and `tab` in a browser. |
321
+ | `journey.maxAgeMs` | `1800000` | Maximum open time of a journey, in milliseconds. Then the library ends it. The range is 60000 to 86400000. |
322
+ | `batching.logFlushIntervalMs` | `2000` | Maximum wait of a partial log batch, in milliseconds. The range is 100 to 60000. |
323
+ | `batching.logBatchSize` | `100` | Maximum records in one log batch. The range is 1 to 1000. |
324
+ | `batching.metricFlushIntervalMs` | `10000` | Maximum wait of a partial metric batch, in milliseconds. The range is 100 to 60000. |
325
+ | `batching.metricBatchSize` | `500` | Maximum records in one metric batch. The range is 1 to 1000. |
326
+ | `retention.mode` | `"limited"` | `limited` or `until-delivered`. With `until-delivered`, a stored batch has no age limit and no attempt limit. `retention.maxBatches` still applies. A permanent error still drops the batch. A batch that always gets a temporary error stays first. The batches of the same endpoint behind it wait. |
327
+ | `retention.maxBatches` | `500` | Maximum stored batches. A new batch evicts the oldest batch without an action first. The range is 1 to 5000. |
328
+ | `retention.maxAgeMs` | `86400000` | Maximum age of a stored batch, in milliseconds. The range is 60000 to 604800000. |
329
+ | `retention.maxAttempts` | `5` | Maximum send attempts of a stored batch. The range is 1 to 20. |
330
+ | `limits.maxBodyChars` | `4096` | Maximum body length, in characters. The range is 256 to 65536. |
331
+ | `limits.maxAttributeChars` | `8192` | Maximum length of a string attribute, in characters. The range is 256 to 65536. |
332
+ | `limits.maxAttributeCount` | `128` | Maximum keys in one object. The range is 1 to 1024. |
333
+ | `limits.maxStackChars` | `8192` | Maximum length of an error stack, in characters. The range is 256 to 65536. |
334
+ | `limits.maxDepth` | `6` | Maximum depth of a nested value. The range is 1 to 16. |
335
+ | `limits.maxArrayLength` | `100` | Maximum items in one array, set or map. The range is 1 to 10000. |
336
+ | `limits.maxNodes` | `10000` | Maximum values in one sanitize pass. The range is 100 to 100000. |
337
+ | `limits.maxRecordBytes` | `32768` | Maximum attribute bytes of one record. Above it, the library drops the caller attributes. The range is 1024 to 60000. |
338
+ | `capture` | See below | Auto-capture settings. |
339
+ | `console` | `false` | Prints records to devtools. `true` prints from `DEBUG` up. A level name prints from that level up. An object sets `level` and `styles` (see Console Output). It does not depend on `minLevel`. |
340
+ | `transport(request)` | `undefined` | Sends batches through a channel of your app in place of HTTP (see Custom Transport). |
341
+ | `transportOnExit(request)` | `undefined` | Sends the last batch while the page closes. It must return a boolean and must not wait. |
342
+ | `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`. |
344
+ | `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. |
339
346
 
340
347
  ### Auto-Capture Options
341
348
 
@@ -346,6 +353,8 @@ capture: {
346
353
  resourceErrors: false, // <img>, <script>, <link> load failures
347
354
  fetch: false, // window.fetch duration and status codes
348
355
  xhr: false, // XMLHttpRequest duration and status codes
356
+ httpMetrics: true, // http.client.request.duration histogram of fetch and xhr requests, in seconds.
357
+ // Attributes: http.request.method, http.response.status_code, server.address, error.type
349
358
  interactions: false, // Element click breadcrumbs
350
359
  navigation: false, // Single-page navigation URL changes
351
360
  webVitals: false, // Core Web Vitals (LCP, CLS, INP, FCP, TTFB)
@@ -435,7 +444,8 @@ The ingest server must meet these requirements:
435
444
  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.
436
445
  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.
437
446
  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`.
438
- 6. **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`.
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`.
448
+ 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`.
439
449
 
440
450
  ---
441
451
 
@@ -448,7 +458,8 @@ npm run verify # Format check, version sync, typecheck, lint, build and tests
448
458
  ```
449
459
 
450
460
  - Vanilla playground: `http://localhost:5173/playground/vanilla/index.html`
451
- - Mock ingest server: `http://localhost:8787`
461
+ - Mock ingest server: `http://localhost:8787`. It accepts `/v1/logs` and `/v1/metrics`. It prints one line for each record and for each metric point.
462
+ - The React example sends its counter, histogram and HTTP duration points to `/v1/metrics`.
452
463
 
453
464
  ### Example Applications
454
465
 
@@ -0,0 +1,2 @@
1
+ const e=require("./constants-Cb92egPS.cjs"),t=require("./identity-C1WLItSl.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.mt}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-D5qvsMQ_.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch-D5qvsMQ_.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, pt as t } from "./constants-N99w84xy.js";
2
- import { i as n } from "./identity-D4DPjTM9.js";
1
+ import { d as e, mt as t } from "./constants-DhH6VI5a.js";
2
+ import { i as n } from "./identity-Di-QXGCC.js";
3
3
  //#region src/models/batch.ts
4
4
  function r(e) {
5
5
  if (typeof e != "object" || !e) return !1;
@@ -25,7 +25,10 @@ function a(e, t) {
25
25
  function o(n) {
26
26
  return a(n, e) === t;
27
27
  }
28
+ function s(e) {
29
+ return e.reduce((e, t) => e + t.records.length, 0);
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-DEK4bv9N.js.map
34
+ //# sourceMappingURL=batch-DDgxg16_.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch-DDgxg16_.js","names":["ATTR_LOG_TYPE","LOG_TYPE_ACTION","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,GAAQf,CAAa,MAAMC;AAChD;AAOA,SAAgBkB,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.