@utk09/ui-observability 0.9.0 → 0.9.2
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.
- package/CHANGELOG.md +63 -0
- package/README.md +83 -52
- package/dist/batch-4xKzzSCj.js +31 -0
- package/dist/batch-4xKzzSCj.js.map +1 -0
- package/dist/batch-cys7e53Q.cjs +2 -0
- package/dist/batch-cys7e53Q.cjs.map +1 -0
- package/dist/{bus-CtJWf9QN.cjs → bus-B6vzPmQM.cjs} +2 -2
- package/dist/{bus-CtJWf9QN.cjs.map → bus-B6vzPmQM.cjs.map} +1 -1
- package/dist/{bus-D8kH58tb.js → bus-DrixwdiX.js} +10 -10
- package/dist/{bus-D8kH58tb.js.map → bus-DrixwdiX.js.map} +1 -1
- package/dist/capture/network.d.ts +2 -0
- package/dist/capture/types.d.ts +3 -0
- package/dist/{console-DjLbryED.js → console-B3vGRW5p.js} +3 -3
- package/dist/{console-DjLbryED.js.map → console-B3vGRW5p.js.map} +1 -1
- package/dist/{console-BpHfWstv.cjs → console-ChfuJlf9.cjs} +2 -2
- package/dist/{console-BpHfWstv.cjs.map → console-ChfuJlf9.cjs.map} +1 -1
- package/dist/constants-Be83LICb.cjs +2 -0
- package/dist/constants-Be83LICb.cjs.map +1 -0
- package/dist/constants-CQ_D7jIW.js +144 -0
- package/dist/constants-CQ_D7jIW.js.map +1 -0
- package/dist/constants.d.ts +44 -11
- package/dist/core/diagnostics.d.ts +1 -1
- package/dist/core/drops.d.ts +29 -0
- package/dist/core/hold-buffer.d.ts +27 -0
- package/dist/core/meter.d.ts +45 -0
- package/dist/core/pipeline.d.ts +7 -19
- package/dist/core/record.d.ts +7 -0
- package/dist/core/runtime.d.ts +61 -8
- package/dist/core/sampling.d.ts +2 -0
- package/dist/core/sender.d.ts +6 -1
- package/dist/deadline-5_PecIl5.js +26 -0
- package/dist/deadline-5_PecIl5.js.map +1 -0
- package/dist/deadline-XSnm95pg.cjs +2 -0
- package/dist/deadline-XSnm95pg.cjs.map +1 -0
- package/dist/{errors-DH4QJS0u.js → errors-BGs5NOrw.js} +4 -4
- package/dist/{errors-DH4QJS0u.js.map → errors-BGs5NOrw.js.map} +1 -1
- package/dist/{errors-CpGRhhIf.cjs → errors-BMJm7KZZ.cjs} +2 -2
- package/dist/{errors-CpGRhhIf.cjs.map → errors-BMJm7KZZ.cjs.map} +1 -1
- package/dist/identity-DXyV86o-.cjs +2 -0
- package/dist/identity-DXyV86o-.cjs.map +1 -0
- package/dist/{deadline-B5DINjD5.js → identity-rpEyjvVg.js} +3 -26
- package/dist/identity-rpEyjvVg.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +19 -0
- package/dist/index.js +683 -369
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-storage-BXaPVPyG.cjs +2 -0
- package/dist/indexeddb-storage-BXaPVPyG.cjs.map +1 -0
- package/dist/{indexeddb-storage-n1qkFBGA.js → indexeddb-storage-Q9fDYlyn.js} +76 -47
- package/dist/indexeddb-storage-Q9fDYlyn.js.map +1 -0
- package/dist/{interactions-OU94MPXs.js → interactions-B8zjCjga.js} +2 -2
- package/dist/{interactions-OU94MPXs.js.map → interactions-B8zjCjga.js.map} +1 -1
- package/dist/{interactions-31eHGwEQ.cjs → interactions-BAGRmtrv.cjs} +2 -2
- package/dist/{interactions-31eHGwEQ.cjs.map → interactions-BAGRmtrv.cjs.map} +1 -1
- package/dist/journey-BGSyy8Es.cjs +2 -0
- package/dist/journey-BGSyy8Es.cjs.map +1 -0
- package/dist/{journey-CeJ1QoT2.js → journey-_dQQ1eMP.js} +27 -26
- package/dist/{journey-CeJ1QoT2.js.map → journey-_dQQ1eMP.js.map} +1 -1
- package/dist/library-request-BIG3Xpx3.cjs +2 -0
- package/dist/library-request-BIG3Xpx3.cjs.map +1 -0
- package/dist/library-request-DX6ev9oG.js +25 -0
- package/dist/library-request-DX6ev9oG.js.map +1 -0
- package/dist/{long-frames-C_7OutLs.js → long-frames-B0tKuChx.js} +3 -3
- package/dist/{long-frames-C_7OutLs.js.map → long-frames-B0tKuChx.js.map} +1 -1
- package/dist/{long-frames-B8VdA_ny.cjs → long-frames-Cq2LgNnp.cjs} +2 -2
- package/dist/{long-frames-B8VdA_ny.cjs.map → long-frames-Cq2LgNnp.cjs.map} +1 -1
- package/dist/models/batch.d.ts +14 -0
- package/dist/models/config.d.ts +169 -0
- package/dist/models/drop.d.ts +39 -0
- package/dist/models/metric.d.ts +50 -0
- package/dist/models/storage.d.ts +15 -3
- package/dist/network-C6kJbW6K.cjs +2 -0
- package/dist/network-C6kJbW6K.cjs.map +1 -0
- package/dist/network-CMnEvGJB.js +211 -0
- package/dist/network-CMnEvGJB.js.map +1 -0
- package/dist/{platform-D4wu1eIF.cjs → platform-DNOJjpOm.cjs} +2 -2
- package/dist/{platform-D4wu1eIF.cjs.map → platform-DNOJjpOm.cjs.map} +1 -1
- package/dist/{platform-IHBZGqUe.js → platform-j0uMPwHi.js} +3 -3
- package/dist/{platform-IHBZGqUe.js.map → platform-j0uMPwHi.js.map} +1 -1
- package/dist/{remote-rules-kuDf5gbe.cjs → remote-rules-DgoBJxZL.cjs} +2 -2
- package/dist/{remote-rules-kuDf5gbe.cjs.map → remote-rules-DgoBJxZL.cjs.map} +1 -1
- package/dist/{remote-rules-Bt1XsdEQ.js → remote-rules-UggoZqfP.js} +11 -11
- package/dist/{remote-rules-Bt1XsdEQ.js.map → remote-rules-UggoZqfP.js.map} +1 -1
- package/dist/{sampling-o0VY1mqQ.js → sampling-BLMD8EGM.js} +28 -27
- package/dist/sampling-BLMD8EGM.js.map +1 -0
- package/dist/sampling-MthcVXXU.cjs +2 -0
- package/dist/sampling-MthcVXXU.cjs.map +1 -0
- package/dist/{sanitize-B9UheVKc.js → sanitize-BNwgPj_B.js} +2 -2
- package/dist/{sanitize-B9UheVKc.js.map → sanitize-BNwgPj_B.js.map} +1 -1
- package/dist/{sanitize-DSIP7amZ.cjs → sanitize-BqzPc4Jg.cjs} +2 -2
- package/dist/{sanitize-DSIP7amZ.cjs.map → sanitize-BqzPc4Jg.cjs.map} +1 -1
- package/dist/sender--0_VzPbN.js +1249 -0
- package/dist/sender--0_VzPbN.js.map +1 -0
- package/dist/sender-SPGMqZjD.cjs +3 -0
- package/dist/sender-SPGMqZjD.cjs.map +1 -0
- package/dist/storage/emergency-queue.d.ts +4 -1
- package/dist/storage/eviction.d.ts +40 -0
- package/dist/storage/idb-driver.d.ts +6 -0
- package/dist/storage/indexeddb-storage.d.ts +13 -5
- package/dist/storage/local-storage.d.ts +24 -1
- package/dist/storage/memory-storage.d.ts +7 -0
- package/dist/{storm-Y-yuBhvv.cjs → storm-CTy1dfvs.cjs} +2 -2
- package/dist/{storm-Y-yuBhvv.cjs.map → storm-CTy1dfvs.cjs.map} +1 -1
- package/dist/{storm-BTw0J6eE.js → storm-knaj4GUH.js} +2 -2
- package/dist/{storm-BTw0J6eE.js.map → storm-knaj4GUH.js.map} +1 -1
- package/dist/transport/custom-transport.d.ts +3 -2
- package/dist/transport/exit-flush.d.ts +19 -2
- package/dist/transport/http-transport.d.ts +6 -4
- package/dist/transport/retry-engine.d.ts +9 -3
- package/dist/transport/serializers/otlp-metrics.d.ts +3 -0
- package/dist/transport/serializers/otlp.d.ts +30 -0
- package/dist/transport/serializers/select.d.ts +20 -4
- package/dist/transport/status-transport.d.ts +23 -12
- package/dist/utils/console.d.ts +4 -1
- package/dist/utils/library-request.d.ts +12 -0
- package/package.json +1 -1
- package/dist/constants-Br3b89Wg.cjs +0 -2
- package/dist/constants-Br3b89Wg.cjs.map +0 -1
- package/dist/constants-DM94FjVX.js +0 -96
- package/dist/constants-DM94FjVX.js.map +0 -1
- package/dist/deadline-B5DINjD5.js.map +0 -1
- package/dist/deadline-Cbg2cbUw.cjs +0 -2
- package/dist/deadline-Cbg2cbUw.cjs.map +0 -1
- package/dist/indexeddb-storage-DNdf1fmL.cjs +0 -2
- package/dist/indexeddb-storage-DNdf1fmL.cjs.map +0 -1
- package/dist/indexeddb-storage-n1qkFBGA.js.map +0 -1
- package/dist/journey-CE2EcwHW.cjs +0 -2
- package/dist/journey-CE2EcwHW.cjs.map +0 -1
- package/dist/library-request-C9uJFlbq.cjs +0 -2
- package/dist/library-request-C9uJFlbq.cjs.map +0 -1
- package/dist/library-request-DvhuplAB.js +0 -14
- package/dist/library-request-DvhuplAB.js.map +0 -1
- package/dist/network-BAV7ipyn.cjs +0 -2
- package/dist/network-BAV7ipyn.cjs.map +0 -1
- package/dist/network-D_lloS5t.js +0 -174
- package/dist/network-D_lloS5t.js.map +0 -1
- package/dist/sampling-BI15ds9D.cjs +0 -2
- package/dist/sampling-BI15ds9D.cjs.map +0 -1
- package/dist/sampling-o0VY1mqQ.js.map +0 -1
- package/dist/sender-BnNj9bOX.js +0 -1050
- package/dist/sender-BnNj9bOX.js.map +0 -1
- package/dist/sender-D0OsyB1c.cjs +0 -3
- package/dist/sender-D0OsyB1c.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,69 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
4
4
|
|
|
5
|
+
## [0.9.2] - 2026-10-30
|
|
6
|
+
|
|
7
|
+
### Added - v0.9.2
|
|
8
|
+
|
|
9
|
+
- `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.
|
|
10
|
+
- 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.
|
|
11
|
+
- `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.
|
|
12
|
+
- `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.
|
|
13
|
+
- Sampling and `minLevel` do not drop a point. The console does not print it.
|
|
14
|
+
- 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`.
|
|
15
|
+
- 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`.
|
|
16
|
+
- The record limits do not cut the metric fields of a point, for example the bucket counts. `redact` cannot change these fields.
|
|
17
|
+
- The points of the open interval go out at `flush()`, at `shutdown()` and before the exit flush.
|
|
18
|
+
- The package exports the types `Counter`, `Histogram`, `HistogramOptions`, `InstrumentOptions` and `MetricAttributes`.
|
|
19
|
+
- 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`.
|
|
20
|
+
- `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"`.
|
|
21
|
+
- A `logMetric()` record has the new attribute `metric.attribute_keys`. It names the attributes of the call.
|
|
22
|
+
- `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.
|
|
23
|
+
- 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.
|
|
24
|
+
- 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.
|
|
25
|
+
|
|
26
|
+
### Changed - v0.9.2
|
|
27
|
+
|
|
28
|
+
- `flush()` and the exit flush send the metric records and the other records in separate batches. A batch never holds both kinds.
|
|
29
|
+
- 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.
|
|
30
|
+
- 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.
|
|
31
|
+
|
|
32
|
+
## [0.9.1] - 2026-10-29
|
|
33
|
+
|
|
34
|
+
### Added - v0.9.1
|
|
35
|
+
|
|
36
|
+
- `batching` sets the batch size and the flush interval of the log stream and of the metric stream. The keys are `logFlushIntervalMs`, `logBatchSize`, `metricFlushIntervalMs` and `metricBatchSize`.
|
|
37
|
+
- `retention` sets `maxBatches`, `maxAgeMs` and `maxAttempts` for undelivered batches.
|
|
38
|
+
- With `retention.mode: "until-delivered"`, a stored batch has no age limit and no attempt limit. `maxBatches` still applies. A permanent error still drops the batch.
|
|
39
|
+
- With `retention.mode: "until-delivered"`, a batch that always gets a temporary error stays first in the queue. The batches behind it wait.
|
|
40
|
+
- `limits` sets the 8 size limits of each record: `maxBodyChars`, `maxAttributeChars`, `maxAttributeCount`, `maxStackChars`, `maxDepth`, `maxArrayLength`, `maxNodes` and `maxRecordBytes`. The console uses the same limits.
|
|
41
|
+
- `journey.maxAgeMs` sets the maximum open time of a journey.
|
|
42
|
+
- Each new key has a range. A value outside its range reports `config.invalid`. The value in force stays.
|
|
43
|
+
- `onDrop(summary)` 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.
|
|
44
|
+
- The library joins the losses of one reason in one task into one summary. Each list holds at most 20 different values.
|
|
45
|
+
- The `onDrop` reasons are `buffer_full`, `expired`, `over_capacity`, `quota`, `max_attempts`, `rejected`, `unserializable`, `exit_queue_full`, `load_failed` and `not_stored`.
|
|
46
|
+
- `load_failed` covers the records that wait for the delivery stack when its load fails. It also covers these records when `shutdown()` comes before the load ends. After a failed load, each new record also reports `load_failed`.
|
|
47
|
+
- `not_stored` covers a failed send that storage did not keep. The cause is an IndexedDB write error or `storage: "none"`.
|
|
48
|
+
- The `onDrop` hook runs inside the library request scope and the library console scope. Network capture and console capture skip its requests and its console lines.
|
|
49
|
+
- Do not log through the library in the `onDrop` hook. A record from the hook can evict a stored batch.
|
|
50
|
+
- `onDrop` can report a batch that storage evicts during its send. The server can still receive that batch.
|
|
51
|
+
- The package exports the types `DropSummary` and `LossReason`.
|
|
52
|
+
|
|
53
|
+
### Changed - v0.9.1
|
|
54
|
+
|
|
55
|
+
- A later `configure()` cannot change `batching` or `retention` after the delivery stack loads. It cannot change `limits` or `journey.maxAgeMs` after the first `configure()`. It reports `config.invalid`. The values in force stay.
|
|
56
|
+
- A log call before `configure()` starts a runtime with defaults. The first `configure()` then sets `batching`, `retention`, `limits` and `journey.maxAgeMs` of that runtime.
|
|
57
|
+
- 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. `retention.maxAgeMs` still removes each old batch.
|
|
58
|
+
- The hold buffers keep up to 2000 actions before startup and while the delivery stack loads. The 500-record limit applies only to the other records.
|
|
59
|
+
- A prune that removes expired batches and batches over `retention.maxBatches` reports each group with its own reason. `storage.evicted` and the gap warning record come one time for each group.
|
|
60
|
+
- With `storage: "none"`, a failed send gives the gap warning record. A throttle limits that record.
|
|
61
|
+
- The gzip size budget of the main graph is 24,400 B. It was 23,700 B.
|
|
62
|
+
|
|
63
|
+
### Fixed - v0.9.1
|
|
64
|
+
|
|
65
|
+
- When a keepalive exit fetch fails or throws, the library puts the batch in the emergency queue. The next page load sends it. Before, the library lost the batch.
|
|
66
|
+
- `shutdown()` gives the forward buffer to the bus before the bus stops. Before, a forwarder lost the records that it logged in the same task as `shutdown()`.
|
|
67
|
+
|
|
5
68
|
## [0.9.0] - 2026-10-28
|
|
6
69
|
|
|
7
70
|
### Breaking changes - v0.9.0
|
package/README.md
CHANGED
|
@@ -64,10 +64,10 @@ log.logAction("ORDER_SUBMIT", { orderId: "ORD-1001", qty: 100 });
|
|
|
64
64
|
log.error("pricing call failed", caughtError);
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
- `configure()` is idempotent. A later call updates the runtime singleton in place. You cannot change `storage` or `
|
|
67
|
+
- `configure()` is idempotent. A later call updates the runtime singleton in place. You cannot change `storage`, `identity`, `batching`, `retention`, `limits` or `journey.maxAgeMs` after startup. The library reports that change and ignores it.
|
|
68
68
|
- Call `configure()` from one context in each document. A second call changes `service.name` on the records of every other context. In a composed page, the shell calls `configure()`. Each microfrontend uses its own namespace.
|
|
69
69
|
- You can call `getLogger()` at module top level, before `configure()`. The logger finds the runtime on its first write.
|
|
70
|
-
- A write before the first `configure()` starts a runtime with default settings. It does not throw.
|
|
70
|
+
- A write before the first `configure()` starts a runtime with default settings. It does not throw. The first `configure()` then sets `limits` and `journey.maxAgeMs` of that runtime.
|
|
71
71
|
- After `shutdown()`, every call does nothing until the next `configure()`.
|
|
72
72
|
|
|
73
73
|
### Console Only (No Network)
|
|
@@ -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
|
-
| `
|
|
257
|
-
| `
|
|
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 |
|
|
@@ -286,38 +292,57 @@ The level methods give records with `log.type: "log"`. Records of the library it
|
|
|
286
292
|
|
|
287
293
|
## Configuration Options
|
|
288
294
|
|
|
289
|
-
No key is required. Set `endpoint` to send records. A value of the wrong type reports `config.invalid
|
|
290
|
-
|
|
291
|
-
| Key
|
|
292
|
-
|
|
|
293
|
-
| `endpoint`
|
|
294
|
-
| `
|
|
295
|
-
| `
|
|
296
|
-
| `
|
|
297
|
-
| `
|
|
298
|
-
| `
|
|
299
|
-
| `
|
|
300
|
-
| `
|
|
301
|
-
| `
|
|
302
|
-
| `
|
|
303
|
-
| `
|
|
304
|
-
| `
|
|
305
|
-
| `
|
|
306
|
-
| `sampling.
|
|
307
|
-
| `sampling.
|
|
308
|
-
| `sampling.
|
|
309
|
-
| `sampling.
|
|
310
|
-
| `
|
|
311
|
-
| `bus.
|
|
312
|
-
| `bus.
|
|
313
|
-
| `
|
|
314
|
-
| `
|
|
315
|
-
| `
|
|
316
|
-
| `
|
|
317
|
-
| `
|
|
318
|
-
| `
|
|
319
|
-
| `
|
|
320
|
-
| `
|
|
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()`.
|
|
296
|
+
|
|
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. |
|
|
321
346
|
|
|
322
347
|
### Auto-Capture Options
|
|
323
348
|
|
|
@@ -328,6 +353,8 @@ capture: {
|
|
|
328
353
|
resourceErrors: false, // <img>, <script>, <link> load failures
|
|
329
354
|
fetch: false, // window.fetch duration and status codes
|
|
330
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
|
|
331
358
|
interactions: false, // Element click breadcrumbs
|
|
332
359
|
navigation: false, // Single-page navigation URL changes
|
|
333
360
|
webVitals: false, // Core Web Vitals (LCP, CLS, INP, FCP, TTFB)
|
|
@@ -384,12 +411,14 @@ IndexedDB holds undelivered batches with `storage: "auto"` or `"indexeddb"`.
|
|
|
384
411
|
- **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.
|
|
385
412
|
- **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.
|
|
386
413
|
- **Five correlation ids:** Each record carries `session.id`, `tab.id`, `context.id`, `journey.id` and `trace_id`.
|
|
387
|
-
- **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.
|
|
414
|
+
- **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.
|
|
388
415
|
- **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.
|
|
389
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.
|
|
390
|
-
- **Configuration after startup:** A second `configure()` call merges the new options into the live runtime. The runtime refuses
|
|
417
|
+
- **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:
|
|
391
418
|
- A change to `storage`. The stored batches stay in the adapter that the runtime built at startup.
|
|
392
419
|
- A change to `identity`. The ids exist from startup.
|
|
420
|
+
- A change to `batching` or `retention` after the delivery stack loads. The stack reads them one time.
|
|
421
|
+
- A change to `limits` or `journey.maxAgeMs` after the first `configure()`. The record builder and the journey engine read them one time.
|
|
393
422
|
- An `endpoint` change to `null` or `""` after the delivery stack loads. Without an endpoint, the stored batches would be lost. A change to another endpoint URL is accepted.
|
|
394
423
|
- **Deterministic sampling:** FNV-1a hashing applies one keep rate to a whole journey. An error and an explicit action are always kept.
|
|
395
424
|
|
|
@@ -415,7 +444,8 @@ The ingest server must meet these requirements:
|
|
|
415
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.
|
|
416
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.
|
|
417
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`.
|
|
418
|
-
6. **
|
|
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`.
|
|
419
449
|
|
|
420
450
|
---
|
|
421
451
|
|
|
@@ -428,7 +458,8 @@ npm run verify # Format check, version sync, typecheck, lint, build and tests
|
|
|
428
458
|
```
|
|
429
459
|
|
|
430
460
|
- Vanilla playground: `http://localhost:5173/playground/vanilla/index.html`
|
|
431
|
-
- 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`.
|
|
432
463
|
|
|
433
464
|
### Example Applications
|
|
434
465
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { d as e, mt as t } from "./constants-CQ_D7jIW.js";
|
|
2
|
+
import { i as n } from "./identity-rpEyjvVg.js";
|
|
3
|
+
//#region src/models/batch.ts
|
|
4
|
+
function r(e) {
|
|
5
|
+
if (typeof e != "object" || !e) return !1;
|
|
6
|
+
let t = Reflect.get(e, "id"), n = Reflect.get(e, "createdAt"), r = Reflect.get(e, "attempts"), i = Reflect.get(e, "records");
|
|
7
|
+
return typeof t == "string" && typeof n == "number" && typeof r == "number" && Array.isArray(i);
|
|
8
|
+
}
|
|
9
|
+
function i(e, t) {
|
|
10
|
+
if (e.records.length < 2) return null;
|
|
11
|
+
let r = Math.floor(e.records.length / 2), i = (r) => ({
|
|
12
|
+
id: n(t),
|
|
13
|
+
records: r,
|
|
14
|
+
createdAt: e.createdAt,
|
|
15
|
+
attempts: e.attempts
|
|
16
|
+
});
|
|
17
|
+
return [i(e.records.slice(0, r)), i(e.records.slice(r))];
|
|
18
|
+
}
|
|
19
|
+
function a(e, t) {
|
|
20
|
+
let n = e;
|
|
21
|
+
if (typeof n != "object" || !n) return;
|
|
22
|
+
let r = Reflect.get(n, "attributes");
|
|
23
|
+
if (typeof r == "object" && r) return Reflect.get(r, t);
|
|
24
|
+
}
|
|
25
|
+
function o(n) {
|
|
26
|
+
return a(n, e) === t;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { i, o as n, r, a as t };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=batch-4xKzzSCj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-4xKzzSCj.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"],"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"],"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./constants-Be83LICb.cjs"),t=require("./identity-DXyV86o-.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}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return i}});
|
|
2
|
+
//# sourceMappingURL=batch-cys7e53Q.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-cys7e53Q.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"],"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"],"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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./constants-Br3b89Wg.cjs"),t=require("./deadline-Cbg2cbUw.cjs"),n=require("./journey-CE2EcwHW.cjs"),r=require("./remote-rules-kuDf5gbe.cjs");function i(t){return{p:e.w,m:t}}function a(e){if(typeof e!=`object`||!e)return null;let t=e;if(t.p!==`ui-observability/1`||typeof t.m!=`object`||t.m===null)return null;let n=t.m;return typeof n.t==`string`?n:null}var o=Symbol.for(e.qt),s=`null`;function c(e,t){return e===s?`The bus ignored ${t} from a sandboxed frame. The frame has an opaque origin. Set bus.mode: "sender" in the frame. Add allow-same-origin to the sandbox attribute only for content that you trust.`:`The bus ignored ${t} from ${e}. If you own this origin, add it to bus.trustedOrigins.`}function l(){let e=location.ancestorOrigins;if(e&&e.length>0)return e.item(0);let t=document.referrer;if(t===``)return null;try{return new URL(t).origin}catch{return null}}function u(e,t){if(typeof window>`u`||window.parent===window)return null;let n;try{n=window.parent[o]}catch{return null}if(typeof n?.busAccept!=`function`)return null;let r=n,i=!0;return{kind:`direct`,post(n){i&&t.guard(`bus.send_failed`,`The direct call into the parent runtime failed.`,()=>{r.busAccept(n,e)})},close(){i=!1}}}function d(e,t,n){if(typeof window>`u`||window.parent===window)return null;let r=location.origin;if(r===s)return n.report(`bus.untrusted_origin`,`This frame is sandboxed without allow-same-origin. It has an opaque origin. No parent can trust it. This context sends its own records. Set bus.mode: "sender" in the frame. Add allow-same-origin to the sandbox attribute only for content that you trust.`,{origin:r,type:`parent`}),null;let o=new Set([r,...t]),u=l();if(u===null||!o.has(u))return n.report(`bus.untrusted_origin`,u===null?`The origin of the parent frame is unknown. This context sends its own records.`:`The parent frame is on ${u}. This origin is not in bus.trustedOrigins. This context sends its own records.`,{origin:u??``,type:`parent`}),null;let d=new Set,f=t=>{let r=a(t.data);r&&t.source===window.parent&&(o.has(t.origin)?e(r,{link:`parent`,origin:t.origin}):d.has(t.origin)||(d.add(t.origin),n.report(`bus.untrusted_origin`,c(t.origin,`a message`),{origin:t.origin,type:r.t.slice(0,32)})))};return addEventListener(`message`,f),{kind:`parent`,post(e){n.guard(`bus.send_failed`,`The postMessage call to the parent failed.`,()=>{window.parent.postMessage(i(e),u)})},close(){removeEventListener(`message`,f)}}}function f(e,t,n){if(typeof window>`u`)return null;let r=new Set([location.origin,...t]);r.delete(s);let o=new Map,l=t=>{let i=a(t.data);i&&(r.has(t.origin)?(t.source&&o.set(t.source,t.origin),e(i,{link:`children`,origin:t.origin})):n.report(`bus.untrusted_origin`,c(t.origin,`a message`),{origin:t.origin,type:i.t.slice(0,32)}))};return addEventListener(`message`,l),{kind:`children`,post(e){for(let[t,r]of o){let a=t;a.closed?o.delete(t):n.guard(`bus.send_failed`,`The postMessage call to a child frame failed.`,()=>{a.postMessage(i(e),r)})}},close(){removeEventListener(`message`,l),o.clear()}}}function p(e,t,n){let r=globalThis.BroadcastChannel;if(r===void 0)return null;let o=n.guard(`bus.send_failed`,`The library could not open the BroadcastChannel.`,()=>new r(e));return o?(o.onmessage=e=>{let n=a(e.data);n&&t(n,{link:`broadcast`,origin:`same-origin`})},{kind:`broadcast`,post(e){n.guard(`bus.send_failed`,`The BroadcastChannel.postMessage call failed.`,()=>{o.postMessage(i(e))})},close(){n.guard(`bus.send_failed`,`The library could not close the BroadcastChannel.`,()=>{o.close()})}}):null}function m(e,t,n,r){let o=globalThis.fin?.InterApplicationBus;if(!o)return null;if(!t)return r.report(`openfin.unavailable`,`OpenFin gives no application uuid. The InterApplicationBus link stays closed.`),null;let s=`${e}.${t}`;return r.guardAsync(`bus.send_failed`,`The InterApplicationBus.subscribe call failed.`,()=>o.subscribe({uuid:t},s,e=>{let t=a(e);t&&n(t,{link:`openfin`,origin:`openfin`})})),{kind:`openfin`,post(e){r.guardAsync(`bus.send_failed`,`The InterApplicationBus.publish call failed.`,()=>o.publish(s,i(e)))},close(){}}}function h(e,t){let n=globalThis,r=n.postMessage;return n.WorkerGlobalScope===void 0||!r?null:(n.addEventListener?.(`message`,t=>{let n=a(t.data);n&&e(n,{link:`owner`,origin:`same-origin`})}),{kind:`owner`,post(e){t.guard(`bus.send_failed`,`The postMessage call of the worker failed.`,()=>{r(i(e))})},close(){}})}function g(e,t,n){let r=e=>{let n=a(e.data);n&&t(n,{link:`worker`,origin:`same-origin`})};return e.addEventListener(`message`,r),e.start?.(),{kind:`worker`,post(t){n.guard(`bus.send_failed`,`The postMessage call to a worker failed.`,()=>{e.postMessage(i(t))})},close(){e.removeEventListener(`message`,r)}}}var _={timeoutMs:e.C,maxAttempts:3},v=[`children`,`direct`,`worker`],y=class{config;diagnostics;platform;contextId;tabId;handlers;handshakeOptions;role=`sender`;upstream=null;links=[];openFinLink=null;isOpenFinProvider=!1;resolved=!1;rulesPoll;destroyed=!1;ownerId=null;awaitingWelcome=null;constructor(e,t,n,r,i,a,o=_){this.config=e,this.diagnostics=t,this.platform=n,this.contextId=r,this.tabId=i,this.handlers=a,this.handshakeOptions=o}getRole(){return this.role}isResolved(){return this.resolved}async start(){let{bus:e}=this.config;if(e.mode===`off`)return this.role=`sender`,this.resolved=!0,this.role;if(this.isOpenFinProvider=this.resolveOpenFinProvider(),e.mode===`sender`||e.mode===`forwarder`)return this.role=e.mode,this.openControlLinks(),this.role===`forwarder`&&(this.upstream=this.candidateUpstream(),this.upstream||this.diagnostics.report(`bus.no_owner`,`bus.mode is "forwarder". No owner exists. The library drops the records of this context.`)),this.resolved=!0,this.announce(),this.role;this.openControlLinks();let t=u(this.receive,this.diagnostics);if(t)return this.role=`forwarder`,this.upstream=t,this.resolved=!0,this.diagnostics.report(`bus.role_resolved`,`This context attached directly to the runtime of its same-origin parent.`,{role:`forwarder`,via:`direct`}),this.announce(),this.role;let n=this.candidateUpstream();if(!n)return this.role=`sender`,this.resolved=!0,this.diagnostics.report(`bus.role_resolved`,`No owner exists. This context sends its own records.`,{role:`sender`}),this.announce(),this.role;let r=this.orphanPolicy()===`retry`?this.handshakeOptions.maxAttempts:1,i=!1;for(let e=0;e<r&&!i;e++)i=await this.handshake(n);return this.role=i?`forwarder`:`sender`,this.upstream=i?n:null,i||(n!==this.openFinLink&&n.close(),this.diagnostics.report(`bus.handshake_timeout`,`No owner answered after ${String(r)} attempt(s) of ${String(this.handshakeOptions.timeoutMs)} ms. This context becomes the sender.`,{via:n.kind,crossOrigin:this.isCrossOriginFrame()})),this.diagnostics.report(`bus.role_resolved`,`The bus role is ${this.role}.`,{role:this.role,via:i?n.kind:`none`}),this.resolved=!0,this.announce(),this.role}sendRecords(e){this.upstream?.post({t:`records`,from:this.contextId,records:e})}acceptDirect(e,t){if(e.from===this.contextId)return;let n={link:`direct`,origin:`same-origin`};if(e.t===`hello`)this.canOwn(`direct`)&&t({t:`welcome`,from:this.contextId,to:e.from,tabId:this.tabId},n);else if(e.t===`journey?`){let r=this.handlers.onJourneyRequest();r&&this.journeyLink(`direct`)&&t({t:`journey`,from:this.contextId,to:e.from,journey:r},n)}else e.t===`sampling?`?t(this.rulesAnswer(e.from),n):this.receive(e,n)}attachWorker(e){this.links.push(g(e,this.receive,this.diagnostics))}broadcastJourney(e){this.postJourney({t:`journey`,from:this.contextId,journey:e})}destroy(){this.destroyed=!0,clearInterval(this.rulesPoll),this.rulesPoll=void 0;for(let e of this.allLinks())e.close();this.links.length=0,this.upstream=null,this.ownerId=null,this.openFinLink=null}allLinks(){return!this.upstream||this.links.includes(this.upstream)?this.links:[...this.links,this.upstream]}postOver(e,t){for(let n of this.allLinks())n.kind===e&&n.post(t)}postJourney(e){for(let t of this.allLinks())this.journeyLink(t.kind)&&t.post(e)}receive=(e,t)=>{if(e.from!==this.contextId)switch(e.t){case`hello`:this.canOwn(t.link)&&this.postOver(t.link,{t:`welcome`,from:this.contextId,to:e.from,tabId:this.tabId});break;case`welcome`:if(e.to!==this.contextId)break;this.awaitingWelcome?.link===t.link&&(this.ownerId=e.from,this.awaitingWelcome.settle(!0));break;case`records`:this.role===`sender`?this.handlers.onRecords(e.records):this.upstream&&this.canRelay(t.link)&&this.upstream.post(e);break;case`journey`:this.acceptsJourney(e,t)&&this.applyJourney(e.journey);break;case`journey?`:{let n=this.handlers.onJourneyRequest();n&&this.journeyLink(t.link)&&this.postOver(t.link,{t:`journey`,from:this.contextId,to:e.from,journey:n});break}case`sampling?`:(this.role===`forwarder`?t.link!==this.upstream?.kind:this.canOwn(t.link))&&this.postOver(t.link,this.rulesAnswer(e.from));break;case`sampling`:this.acceptsRules(e.to,t)&&this.applyRules(e.rules);break;case`tab`:t.link===`broadcast`&&e.tabId===this.tabId&&this.contextId>e.from&&this.handlers.onTabConflict()}};canRelay(e){return e===`direct`||e!==this.upstream?.kind}canOwn(e){return this.role===`sender`?e===`openfin`?this.isOpenFinProvider:v.includes(e):!1}resolveOpenFinProvider(){let e=this.config.bus.openFinRole;if(e!==`auto`)return e===`provider`;if(this.platform.platform!==`openfin`&&this.platform.platform!==`openfin_web`)return!1;let t=globalThis.fin?.me;return!t?.identity||t.isView?!1:!!(t.identity.name&&t.identity.name===t.identity.uuid)}orphanPolicy(){return this.isCrossOriginFrame()?`retry`:`promote`}isCrossOriginFrame(){if(typeof window>`u`||window.parent===window)return!1;try{return Reflect.get(window.parent,`location`),!1}catch{return!0}}candidateUpstream(){return this.platform.isWorker?h(this.receive,this.diagnostics):this.platform.isTopLevelDocument?this.platform.platform===`openfin`&&!this.isOpenFinProvider?this.ensureOpenFinLink():null:d(this.receive,this.config.bus.trustedOrigins,this.diagnostics)}openControlLinks(){let t=e=>{e&&this.links.push(e)};this.platform.isTopLevelDocument&&(t(f(this.receive,this.config.bus.trustedOrigins,this.diagnostics)),t(p(e.S,this.receive,this.diagnostics))),(this.platform.platform===`openfin`||this.platform.platform===`openfin_web`)&&t(this.ensureOpenFinLink())}ensureOpenFinLink(){return this.openFinLink??=m(e.S,this.platform.openfinUuid,this.receive,this.diagnostics),this.openFinLink}handshake(e){return new Promise(n=>{let r=!1,i=e=>{r||(r=!0,this.awaitingWelcome=null,clearTimeout(a),n(e))};this.awaitingWelcome={link:e.kind,settle:i};let a=setTimeout(()=>{i(!1)},this.handshakeOptions.timeoutMs);t.r(a),e.post({t:`hello`,from:this.contextId,tabId:this.tabId})})}announce(){this.postOver(`broadcast`,{t:`tab`,from:this.contextId,tabId:this.tabId}),this.postJourney({t:`journey?`,from:this.contextId}),this.pollRules()}journeyScope(){let{scope:e}=this.config.journey;if(e!==`auto`)return e;let{platform:t}=this.platform;return t===`openfin`||t===`openfin_web`?`origin`:`tab`}journeyLink(e){let t=this.journeyScope();return t===`context`?!1:t===`origin`||e!==`broadcast`}acceptsJourney(e,t){return!this.journeyLink(t.link)||e.to!==void 0&&e.to!==this.contextId?!1:this.journeyScope()===`origin`||this.fromOwner(e.from,t.link)}fromOwner(e,t){return this.role!==`forwarder`||t!==this.upstream?.kind?!1:this.ownerId===null||e===this.ownerId}applyJourney(e){if(e===null){this.handlers.onJourney(null);return}let t=n.r(e);t===null?this.diagnostics.report(`record.dropped_malformed`,`The bus dropped a journey message. Its payload is not a journey.`,{type:`journey`}):this.handlers.onJourney(t)}rulesAnswer(e){let t=this.handlers.remote.sampling?.wire()??null;return{t:`sampling`,from:this.contextId,to:e,rules:t}}acceptsRules(e,t){if(this.role!==`forwarder`||e!==this.contextId||t.link!==this.upstream?.kind)return!1;let{origin:n}=t;return t.link===`parent`&&n!==location.origin&&!this.config.bus.trustedOrigins.includes(n)?(this.diagnostics.report(`bus.untrusted_origin`,`The bus ignored sampling rules from ${n}. If you own this origin, add it to bus.trustedOrigins.`,{origin:n,type:`sampling`}),!1):!0}applyRules(e){if(e===null){r.t(this.handlers.remote,this.config,null);return}let t=r.n(e,this.diagnostics);t&&r.t(this.handlers.remote,this.config,t)}pollRules(){let{upstream:n}=this;if(this.destroyed||this.role!==`forwarder`||!n)return;let r=()=>{this.config.sampling.remote&&n.post({t:`sampling?`,from:this.contextId})};r(),this.rulesPoll=setInterval(r,e.kt),t.r(this.rulesPoll)}};exports.Bus=y;
|
|
2
|
-
//# sourceMappingURL=bus-
|
|
1
|
+
const e=require("./constants-Be83LICb.cjs"),t=require("./deadline-XSnm95pg.cjs"),n=require("./journey-BGSyy8Es.cjs"),r=require("./remote-rules-DgoBJxZL.cjs");function i(t){return{p:e.E,m:t}}function a(e){if(typeof e!=`object`||!e)return null;let t=e;if(t.p!==`ui-observability/1`||typeof t.m!=`object`||t.m===null)return null;let n=t.m;return typeof n.t==`string`?n:null}var o=Symbol.for(e.Zt),s=`null`;function c(e,t){return e===s?`The bus ignored ${t} from a sandboxed frame. The frame has an opaque origin. Set bus.mode: "sender" in the frame. Add allow-same-origin to the sandbox attribute only for content that you trust.`:`The bus ignored ${t} from ${e}. If you own this origin, add it to bus.trustedOrigins.`}function l(){let e=location.ancestorOrigins;if(e&&e.length>0)return e.item(0);let t=document.referrer;if(t===``)return null;try{return new URL(t).origin}catch{return null}}function u(e,t){if(typeof window>`u`||window.parent===window)return null;let n;try{n=window.parent[o]}catch{return null}if(typeof n?.busAccept!=`function`)return null;let r=n,i=!0;return{kind:`direct`,post(n){i&&t.guard(`bus.send_failed`,`The direct call into the parent runtime failed.`,()=>{r.busAccept(n,e)})},close(){i=!1}}}function d(e,t,n){if(typeof window>`u`||window.parent===window)return null;let r=location.origin;if(r===s)return n.report(`bus.untrusted_origin`,`This frame is sandboxed without allow-same-origin. It has an opaque origin. No parent can trust it. This context sends its own records. Set bus.mode: "sender" in the frame. Add allow-same-origin to the sandbox attribute only for content that you trust.`,{origin:r,type:`parent`}),null;let o=new Set([r,...t]),u=l();if(u===null||!o.has(u))return n.report(`bus.untrusted_origin`,u===null?`The origin of the parent frame is unknown. This context sends its own records.`:`The parent frame is on ${u}. This origin is not in bus.trustedOrigins. This context sends its own records.`,{origin:u??``,type:`parent`}),null;let d=new Set,f=t=>{let r=a(t.data);r&&t.source===window.parent&&(o.has(t.origin)?e(r,{link:`parent`,origin:t.origin}):d.has(t.origin)||(d.add(t.origin),n.report(`bus.untrusted_origin`,c(t.origin,`a message`),{origin:t.origin,type:r.t.slice(0,32)})))};return addEventListener(`message`,f),{kind:`parent`,post(e){n.guard(`bus.send_failed`,`The postMessage call to the parent failed.`,()=>{window.parent.postMessage(i(e),u)})},close(){removeEventListener(`message`,f)}}}function f(e,t,n){if(typeof window>`u`)return null;let r=new Set([location.origin,...t]);r.delete(s);let o=new Map,l=t=>{let i=a(t.data);i&&(r.has(t.origin)?(t.source&&o.set(t.source,t.origin),e(i,{link:`children`,origin:t.origin})):n.report(`bus.untrusted_origin`,c(t.origin,`a message`),{origin:t.origin,type:i.t.slice(0,32)}))};return addEventListener(`message`,l),{kind:`children`,post(e){for(let[t,r]of o){let a=t;a.closed?o.delete(t):n.guard(`bus.send_failed`,`The postMessage call to a child frame failed.`,()=>{a.postMessage(i(e),r)})}},close(){removeEventListener(`message`,l),o.clear()}}}function p(e,t,n){let r=globalThis.BroadcastChannel;if(r===void 0)return null;let o=n.guard(`bus.send_failed`,`The library could not open the BroadcastChannel.`,()=>new r(e));return o?(o.onmessage=e=>{let n=a(e.data);n&&t(n,{link:`broadcast`,origin:`same-origin`})},{kind:`broadcast`,post(e){n.guard(`bus.send_failed`,`The BroadcastChannel.postMessage call failed.`,()=>{o.postMessage(i(e))})},close(){n.guard(`bus.send_failed`,`The library could not close the BroadcastChannel.`,()=>{o.close()})}}):null}function m(e,t,n,r){let o=globalThis.fin?.InterApplicationBus;if(!o)return null;if(!t)return r.report(`openfin.unavailable`,`OpenFin gives no application uuid. The InterApplicationBus link stays closed.`),null;let s=`${e}.${t}`;return r.guardAsync(`bus.send_failed`,`The InterApplicationBus.subscribe call failed.`,()=>o.subscribe({uuid:t},s,e=>{let t=a(e);t&&n(t,{link:`openfin`,origin:`openfin`})})),{kind:`openfin`,post(e){r.guardAsync(`bus.send_failed`,`The InterApplicationBus.publish call failed.`,()=>o.publish(s,i(e)))},close(){}}}function h(e,t){let n=globalThis,r=n.postMessage;return n.WorkerGlobalScope===void 0||!r?null:(n.addEventListener?.(`message`,t=>{let n=a(t.data);n&&e(n,{link:`owner`,origin:`same-origin`})}),{kind:`owner`,post(e){t.guard(`bus.send_failed`,`The postMessage call of the worker failed.`,()=>{r(i(e))})},close(){}})}function g(e,t,n){let r=e=>{let n=a(e.data);n&&t(n,{link:`worker`,origin:`same-origin`})};return e.addEventListener(`message`,r),e.start?.(),{kind:`worker`,post(t){n.guard(`bus.send_failed`,`The postMessage call to a worker failed.`,()=>{e.postMessage(i(t))})},close(){e.removeEventListener(`message`,r)}}}var _={timeoutMs:e.w,maxAttempts:3},v=[`children`,`direct`,`worker`],y=class{config;diagnostics;platform;contextId;tabId;handlers;handshakeOptions;role=`sender`;upstream=null;links=[];openFinLink=null;isOpenFinProvider=!1;resolved=!1;rulesPoll;destroyed=!1;ownerId=null;awaitingWelcome=null;constructor(e,t,n,r,i,a,o=_){this.config=e,this.diagnostics=t,this.platform=n,this.contextId=r,this.tabId=i,this.handlers=a,this.handshakeOptions=o}getRole(){return this.role}isResolved(){return this.resolved}async start(){let{bus:e}=this.config;if(e.mode===`off`)return this.role=`sender`,this.resolved=!0,this.role;if(this.isOpenFinProvider=this.resolveOpenFinProvider(),e.mode===`sender`||e.mode===`forwarder`)return this.role=e.mode,this.openControlLinks(),this.role===`forwarder`&&(this.upstream=this.candidateUpstream(),this.upstream||this.diagnostics.report(`bus.no_owner`,`bus.mode is "forwarder". No owner exists. The library drops the records of this context.`)),this.resolved=!0,this.announce(),this.role;this.openControlLinks();let t=u(this.receive,this.diagnostics);if(t)return this.role=`forwarder`,this.upstream=t,this.resolved=!0,this.diagnostics.report(`bus.role_resolved`,`This context attached directly to the runtime of its same-origin parent.`,{role:`forwarder`,via:`direct`}),this.announce(),this.role;let n=this.candidateUpstream();if(!n)return this.role=`sender`,this.resolved=!0,this.diagnostics.report(`bus.role_resolved`,`No owner exists. This context sends its own records.`,{role:`sender`}),this.announce(),this.role;let r=this.orphanPolicy()===`retry`?this.handshakeOptions.maxAttempts:1,i=!1;for(let e=0;e<r&&!i;e++)i=await this.handshake(n);return this.role=i?`forwarder`:`sender`,this.upstream=i?n:null,i||(n!==this.openFinLink&&n.close(),this.diagnostics.report(`bus.handshake_timeout`,`No owner answered after ${String(r)} attempt(s) of ${String(this.handshakeOptions.timeoutMs)} ms. This context becomes the sender.`,{via:n.kind,crossOrigin:this.isCrossOriginFrame()})),this.diagnostics.report(`bus.role_resolved`,`The bus role is ${this.role}.`,{role:this.role,via:i?n.kind:`none`}),this.resolved=!0,this.announce(),this.role}sendRecords(e){this.upstream?.post({t:`records`,from:this.contextId,records:e})}acceptDirect(e,t){if(e.from===this.contextId)return;let n={link:`direct`,origin:`same-origin`};if(e.t===`hello`)this.canOwn(`direct`)&&t({t:`welcome`,from:this.contextId,to:e.from,tabId:this.tabId},n);else if(e.t===`journey?`){let r=this.handlers.onJourneyRequest();r&&this.journeyLink(`direct`)&&t({t:`journey`,from:this.contextId,to:e.from,journey:r},n)}else e.t===`sampling?`?t(this.rulesAnswer(e.from),n):this.receive(e,n)}attachWorker(e){this.links.push(g(e,this.receive,this.diagnostics))}broadcastJourney(e){this.postJourney({t:`journey`,from:this.contextId,journey:e})}destroy(){this.destroyed=!0,clearInterval(this.rulesPoll),this.rulesPoll=void 0;for(let e of this.allLinks())e.close();this.links.length=0,this.upstream=null,this.ownerId=null,this.openFinLink=null}allLinks(){return!this.upstream||this.links.includes(this.upstream)?this.links:[...this.links,this.upstream]}postOver(e,t){for(let n of this.allLinks())n.kind===e&&n.post(t)}postJourney(e){for(let t of this.allLinks())this.journeyLink(t.kind)&&t.post(e)}receive=(e,t)=>{if(e.from!==this.contextId)switch(e.t){case`hello`:this.canOwn(t.link)&&this.postOver(t.link,{t:`welcome`,from:this.contextId,to:e.from,tabId:this.tabId});break;case`welcome`:if(e.to!==this.contextId)break;this.awaitingWelcome?.link===t.link&&(this.ownerId=e.from,this.awaitingWelcome.settle(!0));break;case`records`:this.role===`sender`?this.handlers.onRecords(e.records):this.upstream&&this.canRelay(t.link)&&this.upstream.post(e);break;case`journey`:this.acceptsJourney(e,t)&&this.applyJourney(e.journey);break;case`journey?`:{let n=this.handlers.onJourneyRequest();n&&this.journeyLink(t.link)&&this.postOver(t.link,{t:`journey`,from:this.contextId,to:e.from,journey:n});break}case`sampling?`:(this.role===`forwarder`?t.link!==this.upstream?.kind:this.canOwn(t.link))&&this.postOver(t.link,this.rulesAnswer(e.from));break;case`sampling`:this.acceptsRules(e.to,t)&&this.applyRules(e.rules);break;case`tab`:t.link===`broadcast`&&e.tabId===this.tabId&&this.contextId>e.from&&this.handlers.onTabConflict()}};canRelay(e){return e===`direct`||e!==this.upstream?.kind}canOwn(e){return this.role===`sender`?e===`openfin`?this.isOpenFinProvider:v.includes(e):!1}resolveOpenFinProvider(){let e=this.config.bus.openFinRole;if(e!==`auto`)return e===`provider`;if(this.platform.platform!==`openfin`&&this.platform.platform!==`openfin_web`)return!1;let t=globalThis.fin?.me;return!t?.identity||t.isView?!1:!!(t.identity.name&&t.identity.name===t.identity.uuid)}orphanPolicy(){return this.isCrossOriginFrame()?`retry`:`promote`}isCrossOriginFrame(){if(typeof window>`u`||window.parent===window)return!1;try{return Reflect.get(window.parent,`location`),!1}catch{return!0}}candidateUpstream(){return this.platform.isWorker?h(this.receive,this.diagnostics):this.platform.isTopLevelDocument?this.platform.platform===`openfin`&&!this.isOpenFinProvider?this.ensureOpenFinLink():null:d(this.receive,this.config.bus.trustedOrigins,this.diagnostics)}openControlLinks(){let t=e=>{e&&this.links.push(e)};this.platform.isTopLevelDocument&&(t(f(this.receive,this.config.bus.trustedOrigins,this.diagnostics)),t(p(e.C,this.receive,this.diagnostics))),(this.platform.platform===`openfin`||this.platform.platform===`openfin_web`)&&t(this.ensureOpenFinLink())}ensureOpenFinLink(){return this.openFinLink??=m(e.C,this.platform.openfinUuid,this.receive,this.diagnostics),this.openFinLink}handshake(e){return new Promise(n=>{let r=!1,i=e=>{r||(r=!0,this.awaitingWelcome=null,clearTimeout(a),n(e))};this.awaitingWelcome={link:e.kind,settle:i};let a=setTimeout(()=>{i(!1)},this.handshakeOptions.timeoutMs);t.r(a),e.post({t:`hello`,from:this.contextId,tabId:this.tabId})})}announce(){this.postOver(`broadcast`,{t:`tab`,from:this.contextId,tabId:this.tabId}),this.postJourney({t:`journey?`,from:this.contextId}),this.pollRules()}journeyScope(){let{scope:e}=this.config.journey;if(e!==`auto`)return e;let{platform:t}=this.platform;return t===`openfin`||t===`openfin_web`?`origin`:`tab`}journeyLink(e){let t=this.journeyScope();return t===`context`?!1:t===`origin`||e!==`broadcast`}acceptsJourney(e,t){return!this.journeyLink(t.link)||e.to!==void 0&&e.to!==this.contextId?!1:this.journeyScope()===`origin`||this.fromOwner(e.from,t.link)}fromOwner(e,t){return this.role!==`forwarder`||t!==this.upstream?.kind?!1:this.ownerId===null||e===this.ownerId}applyJourney(e){if(e===null){this.handlers.onJourney(null);return}let t=n.r(e);t===null?this.diagnostics.report(`record.dropped_malformed`,`The bus dropped a journey message. Its payload is not a journey.`,{type:`journey`}):this.handlers.onJourney(t)}rulesAnswer(e){let t=this.handlers.remote.sampling?.wire()??null;return{t:`sampling`,from:this.contextId,to:e,rules:t}}acceptsRules(e,t){if(this.role!==`forwarder`||e!==this.contextId||t.link!==this.upstream?.kind)return!1;let{origin:n}=t;return t.link===`parent`&&n!==location.origin&&!this.config.bus.trustedOrigins.includes(n)?(this.diagnostics.report(`bus.untrusted_origin`,`The bus ignored sampling rules from ${n}. If you own this origin, add it to bus.trustedOrigins.`,{origin:n,type:`sampling`}),!1):!0}applyRules(e){if(e===null){r.t(this.handlers.remote,this.config,null);return}let t=r.n(e,this.diagnostics);t&&r.t(this.handlers.remote,this.config,t)}pollRules(){let{upstream:n}=this;if(this.destroyed||this.role!==`forwarder`||!n)return;let r=()=>{this.config.sampling.remote&&n.post({t:`sampling?`,from:this.contextId})};r(),this.rulesPoll=setInterval(r,e.Nt),t.r(this.rulesPoll)}};exports.Bus=y;
|
|
2
|
+
//# sourceMappingURL=bus-B6vzPmQM.cjs.map
|