@utk09/ui-observability 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +217 -0
- package/dist/bus/bus.d.ts +134 -0
- package/dist/bus/links.d.ts +106 -0
- package/dist/capture/errors.d.ts +34 -0
- package/dist/capture/interactions.d.ts +29 -0
- package/dist/capture/network.d.ts +40 -0
- package/dist/capture/types.d.ts +78 -0
- package/dist/capture/web-vitals.d.ts +21 -0
- package/dist/constants-D8-4Ged5.cjs +2 -0
- package/dist/constants-D8-4Ged5.cjs.map +1 -0
- package/dist/constants-DbvMIryP.js +110 -0
- package/dist/constants-DbvMIryP.js.map +1 -0
- package/dist/constants.d.ts +339 -0
- package/dist/core/breadcrumbs.d.ts +48 -0
- package/dist/core/config.d.ts +16 -0
- package/dist/core/context.d.ts +35 -0
- package/dist/core/diagnostics.d.ts +76 -0
- package/dist/core/journey.d.ts +112 -0
- package/dist/core/logger.d.ts +117 -0
- package/dist/core/pipeline.d.ts +75 -0
- package/dist/core/record.d.ts +72 -0
- package/dist/core/runtime.d.ts +146 -0
- package/dist/core/sampling.d.ts +9 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +167 -0
- package/dist/index.js +2577 -0
- package/dist/index.js.map +1 -0
- package/dist/indexeddb-storage-DvsvCUlO.cjs +2 -0
- package/dist/indexeddb-storage-DvsvCUlO.cjs.map +1 -0
- package/dist/indexeddb-storage-DwpCDRnX.js +88 -0
- package/dist/indexeddb-storage-DwpCDRnX.js.map +1 -0
- package/dist/models/batch.d.ts +22 -0
- package/dist/models/bus.d.ts +97 -0
- package/dist/models/config.d.ts +528 -0
- package/dist/models/log-record.d.ts +54 -0
- package/dist/models/serializer.d.ts +23 -0
- package/dist/models/storage.d.ts +62 -0
- package/dist/storage/emergency-queue.d.ts +16 -0
- package/dist/storage/factory.d.ts +13 -0
- package/dist/storage/indexeddb-storage.d.ts +69 -0
- package/dist/storage/keys.d.ts +8 -0
- package/dist/storage/local-storage.d.ts +80 -0
- package/dist/storage/memory-storage.d.ts +52 -0
- package/dist/transport/compression.d.ts +7 -0
- package/dist/transport/errors.d.ts +29 -0
- package/dist/transport/exit-flush.d.ts +63 -0
- package/dist/transport/http-transport.d.ts +63 -0
- package/dist/transport/retry-engine.d.ts +69 -0
- package/dist/transport/serializers/ecs.d.ts +3 -0
- package/dist/transport/serializers/otlp.d.ts +3 -0
- package/dist/utils/console.d.ts +24 -0
- package/dist/utils/identity.d.ts +36 -0
- package/dist/utils/lock.d.ts +15 -0
- package/dist/utils/platform.d.ts +36 -0
- package/dist/utils/sanitize.d.ts +47 -0
- package/dist/utils/sequence.d.ts +15 -0
- package/dist/utils/timer.d.ts +19 -0
- package/dist/utils/tracing.d.ts +55 -0
- package/dist/utils/unref.d.ts +9 -0
- package/package.json +106 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [2026] [Authors and contributors of ui-observability]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# @utk09/ui-observability
|
|
2
|
+
|
|
3
|
+
Framework-agnostic UI observability and structured logging for browsers, embedded webviews, and OpenFin desktop containers.
|
|
4
|
+
|
|
5
|
+
Features include automatic batching, compression, persistent offline storage, exponential backoff retries, unload exit flushing, cross-realm bus coordination, and guaranteed never-throw execution. Payloads export as OTLP/JSON over HTTP.
|
|
6
|
+
|
|
7
|
+
> **Status: Early Development.** Public APIs may change between minor releases. Pin exact versions.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @utk09/ui-observability
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Peer Dependencies
|
|
18
|
+
|
|
19
|
+
`web-vitals` (`^4 || ^5 || ^6`) is optional. Install it only when enabling `capture.webVitals`:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
configure({
|
|
23
|
+
endpoint: "https://telemetry.example.com/v1/logs",
|
|
24
|
+
capture: {
|
|
25
|
+
webVitals: true,
|
|
26
|
+
webVitalsLoader: () => import("web-vitals"),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
Initialize once at application startup before logging:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { configure, getLogger } from "@utk09/ui-observability";
|
|
39
|
+
|
|
40
|
+
configure({
|
|
41
|
+
endpoint: "https://telemetry.example.com/v1/logs",
|
|
42
|
+
serviceName: "equities-blotter",
|
|
43
|
+
serviceVersion: "2.4.1",
|
|
44
|
+
environment: "production",
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const log = getLogger("blotter.grid");
|
|
48
|
+
|
|
49
|
+
log.info("grid ready");
|
|
50
|
+
log.logAction("ORDER_SUBMIT", { orderId: "ORD-1001", qty: 100 });
|
|
51
|
+
log.error("pricing call failed", caughtError);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
- `configure()` is idempotent. Re-calling it updates the existing runtime singleton in place.
|
|
55
|
+
- Exactly one context per document calls `configure()`. A second call renames `service.name` on every record the others emit, so in a composed page the shell configures and each microfrontend takes a namespace.
|
|
56
|
+
- Calls before `configure()` record safely to an unconfigured implicit runtime without throwing.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## API Reference
|
|
61
|
+
|
|
62
|
+
### Lifecycle & Setup
|
|
63
|
+
|
|
64
|
+
| Function | Description |
|
|
65
|
+
| ------------------- | ------------------------------------------------------ |
|
|
66
|
+
| `configure(config)` | Initializes or updates the active runtime singleton. |
|
|
67
|
+
| `shutdown()` | Flushes pending records and terminates all subsystems. |
|
|
68
|
+
|
|
69
|
+
### Logging Methods
|
|
70
|
+
|
|
71
|
+
| Function | Description |
|
|
72
|
+
| ---------------------------------------------- | ----------------------------------------------------------------- |
|
|
73
|
+
| `getLogger(namespace, options?)` | Returns a cached `OneLogger` scoped to a namespace. |
|
|
74
|
+
| `trace(msg, payload?)` | Logs a TRACE level record. |
|
|
75
|
+
| `debug(msg, payload?)` | Logs a DEBUG level record. |
|
|
76
|
+
| `info(msg, payload?)` | Logs an INFO level record. |
|
|
77
|
+
| `warn(msg, payload?)` | Logs a WARN level record. |
|
|
78
|
+
| `error(msg, err?, payload?)` | Logs an ERROR record with error instance and breadcrumb snapshot. |
|
|
79
|
+
| `logAction(name, payload?)` | Logs a discrete user action. |
|
|
80
|
+
| `logEvent(name, payload?)` | Logs a domain or lifecycle event. |
|
|
81
|
+
| `logMetric(name, value, unit?, type?, attrs?)` | Logs a metric measurement (`gauge`, `counter`, `histogram`). |
|
|
82
|
+
| `timeSync(label, fn, attrs?)` | Times a synchronous function and emits a duration histogram. |
|
|
83
|
+
| `timeAsync(label, fn, attrs?)` | Times an asynchronous promise and emits a duration histogram. |
|
|
84
|
+
|
|
85
|
+
### Context & Correlation
|
|
86
|
+
|
|
87
|
+
| Function | Description |
|
|
88
|
+
| ------------------------------ | ------------------------------------------------------------- |
|
|
89
|
+
| `setContext(key, value)` | Sets an ambient attribute on all subsequent records. |
|
|
90
|
+
| `setContextMap(values)` | Merges an attribute map into the ambient context. |
|
|
91
|
+
| `removeContext(key)` | Removes an attribute from ambient context. |
|
|
92
|
+
| `startJourney(name, options?)` | Starts a multi-window user journey workflow. |
|
|
93
|
+
| `endJourney()` | Terminates the active journey. |
|
|
94
|
+
| `currentJourney()` | Returns the active `Journey` instance or null. |
|
|
95
|
+
| `getJourneyToken()` | Serializes the active journey into a cross-context URL token. |
|
|
96
|
+
| `adoptJourney(token)` | Adopts a serialized journey token into the current context. |
|
|
97
|
+
| `startTrace()` | Rotates the ambient distributed trace context. |
|
|
98
|
+
| `getTraceHeaders()` | Returns W3C `traceparent` headers for outgoing HTTP requests. |
|
|
99
|
+
| `registerWorker(worker)` | Attaches a Web Worker or MessagePort to the bus. |
|
|
100
|
+
|
|
101
|
+
### Delivery & Diagnostics
|
|
102
|
+
|
|
103
|
+
| Function | Description |
|
|
104
|
+
| ------------------------- | ---------------------------------------------------------- |
|
|
105
|
+
| `flush()` | Flushes pending records in the pipeline or forward buffer. |
|
|
106
|
+
| `getQueueDepth()` | Returns the number of batches waiting in storage. |
|
|
107
|
+
| `getDiagnosticCounters()` | Returns cumulative occurrence counts per diagnostic code. |
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Configuration Options
|
|
112
|
+
|
|
113
|
+
`endpoint` is the only required property.
|
|
114
|
+
|
|
115
|
+
| Key | Default | Description |
|
|
116
|
+
| ---------------------------- | ------------------------- | ------------------------------------------------------------------------------------------ |
|
|
117
|
+
| `endpoint` | _required_ | Target HTTP endpoint URL for log ingestion. |
|
|
118
|
+
| `serviceName` | `""` | Service identifier attached to all records. |
|
|
119
|
+
| `serviceVersion` | `""` | Application version attached to all records. |
|
|
120
|
+
| `environment` | `""` | Deployment environment label (`production`, `staging`). |
|
|
121
|
+
| `enabled` | `true` | Master kill-switch. When `false`, suppresses all logging. |
|
|
122
|
+
| `minLevel` | `"INFO"` | Minimum severity threshold (`TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`). |
|
|
123
|
+
| `streams.logs` | `2000` ms, `100` records | Flush interval and batch limit for standard logs. |
|
|
124
|
+
| `streams.metrics` | `10000` ms, `500` records | Flush interval and batch limit for metrics. |
|
|
125
|
+
| `compression` | `"gzip"` | Compression algorithm (`gzip`, `none`). Applies above `compressionThresholdBytes`, `1024`. |
|
|
126
|
+
| `serializer` | `"otlp"` | Wire format (`otlp`, `ecs`, or custom `LogSerializer`). |
|
|
127
|
+
| `credentials` | `"include"` | Fetch credentials policy. |
|
|
128
|
+
| `headers` | `{}` | Static headers or dynamic header resolver function. |
|
|
129
|
+
| `maxConcurrentRequests` | `2` | Maximum concurrent in-flight HTTP requests. |
|
|
130
|
+
| `requestTimeoutMs` | `15000` | HTTP request timeout in milliseconds. |
|
|
131
|
+
| `storage.strategy` | `"auto"` | Persistence engine (`auto`, `indexeddb`, `localstorage`, `memory`, `none`). |
|
|
132
|
+
| `storage.maxBatches` | `500` | Maximum batches stored offline before FIFO pruning. |
|
|
133
|
+
| `storage.maxAgeMs` | `86400000` (24h) | Maximum offline batch retention in milliseconds. |
|
|
134
|
+
| `storage.maxAttempts` | `5` | Maximum redelivery attempts before dead-letter drop. |
|
|
135
|
+
| `retry.baseDelayMs` | `2000` | Initial exponential backoff delay. |
|
|
136
|
+
| `retry.maxDelayMs` | `60000` | Maximum backoff delay ceiling. |
|
|
137
|
+
| `sampling.defaultRate` | `1` | Keep rate applied when no namespace rule matches. |
|
|
138
|
+
| `sampling.rates` | `{}` | Per-namespace keep rates, longest matching prefix wins. |
|
|
139
|
+
| `sampling.alwaysSampleTypes` | `["action"]` | Record types kept regardless of rate. |
|
|
140
|
+
| `journey.maxAgeMs` | `1800000` (30m) | Maximum journey duration. |
|
|
141
|
+
| `bus.mode` | `"auto"` | Bus role (`auto`, `sender`, `forwarder`, `off`). |
|
|
142
|
+
| `capture` | See below | Browser auto-instrumentation settings. |
|
|
143
|
+
| `limits.maxRecordBytes` | `32768` (32 KB) | Per-record size ceiling before truncation. |
|
|
144
|
+
| `console.enabled` | `false` | Mirrors formatted records to browser devtools. |
|
|
145
|
+
| `redact(record)` | `undefined` | Hook to mutate or drop (`null`) records before ingest. |
|
|
146
|
+
| `onDiagnostic(event)` | `undefined` | Listener for internal diagnostics and telemetry faults. |
|
|
147
|
+
|
|
148
|
+
### Auto-Capture Options
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
capture: {
|
|
152
|
+
errors: true, // Uncaught window.onerror exceptions (default: true)
|
|
153
|
+
rejections: true, // Unhandled promise rejections (default: true)
|
|
154
|
+
resourceErrors: false, // <img>, <script>, <link> load failures
|
|
155
|
+
fetch: false, // window.fetch duration and status codes
|
|
156
|
+
xhr: false, // XMLHttpRequest duration and status codes
|
|
157
|
+
interactions: false, // Element click breadcrumbs
|
|
158
|
+
navigation: false, // Single-page navigation URL changes
|
|
159
|
+
webVitals: false, // Core Web Vitals (LCP, CLS, INP, FCP, TTFB)
|
|
160
|
+
ignoreUrls: [], // URL patterns excluded from network capture
|
|
161
|
+
propagateTraceHeaderTo: [], // Target origins allowed to receive traceparent
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Core Architecture
|
|
168
|
+
|
|
169
|
+
- **Document Singleton:** The runtime pins to `globalThis[Symbol.for("ui-observability.runtime")]`. Federated microfrontends and separate bundles share one ring buffer, sequence generator, and transport.
|
|
170
|
+
- **Single Sender Coordination:** Iframes, Web Workers, and OpenFin views discover the nearest long-lived context and forward records across the bus. That one context handles batching, storage, and network delivery for all of them.
|
|
171
|
+
- **Five Correlation Dimensions:** Every record maps to `session.id`, `tab.id`, `context.id`, `journey.id`, and `trace_id`.
|
|
172
|
+
- **Durability & Exit Flush:** Failed deliveries persist to IndexedDB/LocalStorage and retry with exponential jittered backoff. During `pagehide` or `freeze`, pending records drain via `navigator.sendBeacon` (under a 60 KB threshold) or persist to emergency storage.
|
|
173
|
+
- **Deterministic Journey Sampling:** FNV-1a hashing applies sampling rates consistently across entire journeys. Errors and explicit actions bypass sampling filters.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Ingest Server Requirements
|
|
178
|
+
|
|
179
|
+
Receiving servers must implement the following contract:
|
|
180
|
+
|
|
181
|
+
1. **Protocol & Method:** Accept HTTP `POST` requests with `Content-Type: application/json` or `Content-Type: text/plain;charset=UTF-8` (used by `sendBeacon` to avoid CORS preflights).
|
|
182
|
+
2. **Idempotency & Deduplication:** Deduplicate on `X-UiObs-Batch-Id` header and `uiobs_batch_id` query parameter for at least 24 hours.
|
|
183
|
+
3. **Throttling & CORS:** Return `429` or `503` with a `Retry-After` header, and expose it via `Access-Control-Expose-Headers: retry-after`.
|
|
184
|
+
4. **Payload Handling:**
|
|
185
|
+
- `200`, `202`, or `204`: Accepted.
|
|
186
|
+
- `413`: Payload too large. Prompts client batch splitting.
|
|
187
|
+
- `4xx`: Non-retryable client error. Drops batch.
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Development
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
npm install
|
|
195
|
+
npm run dev # Starts playground, mock ingest server, and iframe host
|
|
196
|
+
npm run verify # Runs format check, typecheck, lint, build, and tests
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
- Vanilla playground: `http://localhost:5173/playground/vanilla/index.html`
|
|
200
|
+
- Mock ingest server: `http://localhost:8787`
|
|
201
|
+
|
|
202
|
+
### Example Applications
|
|
203
|
+
|
|
204
|
+
Build the package before running framework examples:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
npm run build
|
|
208
|
+
npm run example:react # http://localhost:5180
|
|
209
|
+
npm run example:angular # http://localhost:4200
|
|
210
|
+
npm run example:microfrontend # Shell on http://localhost:5191, remotes on 5192/5193
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## License
|
|
216
|
+
|
|
217
|
+
Apache-2.0. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { Diagnostics } from "../core/diagnostics";
|
|
2
|
+
import type { Journey } from "../core/journey";
|
|
3
|
+
import type { BusMessage, BusRole } from "../models/bus";
|
|
4
|
+
import type { ResolvedConfig } from "../models/config";
|
|
5
|
+
import type { LogRecord } from "../models/log-record";
|
|
6
|
+
import type { PlatformMetadata } from "../utils/platform";
|
|
7
|
+
import { type Receive, type WorkerLike } from "./links";
|
|
8
|
+
/** Callbacks for handling records and journey events from connected realms. */
|
|
9
|
+
export interface BusHandlers {
|
|
10
|
+
/** Processes records forwarded from child contexts. */
|
|
11
|
+
onRecords: (records: LogRecord[]) => void;
|
|
12
|
+
/** Applies journey updates received from the control bus. */
|
|
13
|
+
onJourney: (journey: Journey | null) => void;
|
|
14
|
+
/** Returns the active journey for inquiring child contexts. */
|
|
15
|
+
onJourneyRequest: () => Journey | null;
|
|
16
|
+
/** Invoked when a tab identifier collision is detected across windows. */
|
|
17
|
+
onTabConflict: () => void;
|
|
18
|
+
}
|
|
19
|
+
/** Coordinates cross-realm communication, role resolution, and message dispatch. */
|
|
20
|
+
export declare class Bus {
|
|
21
|
+
private readonly config;
|
|
22
|
+
private readonly diagnostics;
|
|
23
|
+
private readonly platform;
|
|
24
|
+
private readonly contextId;
|
|
25
|
+
private readonly tabId;
|
|
26
|
+
private readonly handlers;
|
|
27
|
+
/** Current bus role. Defaults to "sender". */
|
|
28
|
+
private role;
|
|
29
|
+
/** Upstream forwarding link, or null when acting as sender. */
|
|
30
|
+
private upstream;
|
|
31
|
+
/** Open control plane links. */
|
|
32
|
+
private readonly links;
|
|
33
|
+
/** Shared OpenFin InterApplicationBus link instance. */
|
|
34
|
+
private openFinLink;
|
|
35
|
+
/** Indicates whether this context is the OpenFin platform provider. */
|
|
36
|
+
private isOpenFinProvider;
|
|
37
|
+
/** Indicates whether role resolution has completed. */
|
|
38
|
+
private resolved;
|
|
39
|
+
/** Active handshake state awaiting welcome response. */
|
|
40
|
+
private awaitingWelcome;
|
|
41
|
+
/**
|
|
42
|
+
* @param config Active configuration instance.
|
|
43
|
+
* @param diagnostics Diagnostics reporter.
|
|
44
|
+
* @param platform Platform runtime metadata.
|
|
45
|
+
* @param contextId Unique context identifier for loop prevention.
|
|
46
|
+
* @param tabId Tab identifier announced on broadcast channels.
|
|
47
|
+
* @param handlers Callbacks for routed bus events.
|
|
48
|
+
*/
|
|
49
|
+
constructor(config: ResolvedConfig, diagnostics: Diagnostics, platform: PlatformMetadata, contextId: string, tabId: string, handlers: BusHandlers);
|
|
50
|
+
/** Returns the resolved bus role. */
|
|
51
|
+
getRole(): BusRole;
|
|
52
|
+
/** Returns whether role resolution has completed. */
|
|
53
|
+
isResolved(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Resolves bus role and establishes control links.
|
|
56
|
+
* @returns Resolved role.
|
|
57
|
+
*/
|
|
58
|
+
start(): Promise<BusRole>;
|
|
59
|
+
/**
|
|
60
|
+
* Forwards records to the upstream owner if configured.
|
|
61
|
+
* @param records Batch of log records to send.
|
|
62
|
+
*/
|
|
63
|
+
sendRecords(records: LogRecord[]): void;
|
|
64
|
+
/**
|
|
65
|
+
* Synchronously processes direct messages from same-origin child contexts.
|
|
66
|
+
* @param message Received bus message.
|
|
67
|
+
* @param reply Direct response callback.
|
|
68
|
+
*/
|
|
69
|
+
acceptDirect(message: BusMessage, reply: Receive): void;
|
|
70
|
+
/**
|
|
71
|
+
* Connects a worker instance to the bus control plane.
|
|
72
|
+
* @param worker Worker instance.
|
|
73
|
+
*/
|
|
74
|
+
attachWorker(worker: WorkerLike): void;
|
|
75
|
+
/**
|
|
76
|
+
* Broadcasts journey state changes to all connected links.
|
|
77
|
+
* @param journey Active journey or null if ended.
|
|
78
|
+
*/
|
|
79
|
+
broadcastJourney(journey: Journey | null): void;
|
|
80
|
+
/** Closes all open links and clears internal state. */
|
|
81
|
+
destroy(): void;
|
|
82
|
+
/** Returns all unique active links including upstream. */
|
|
83
|
+
private allLinks;
|
|
84
|
+
/** Broadcasts a message across all open links. */
|
|
85
|
+
private post;
|
|
86
|
+
/** Sends a message exclusively over links matching the specified kind. */
|
|
87
|
+
private postOver;
|
|
88
|
+
/** Routes incoming messages to registered handlers or upstream targets. */
|
|
89
|
+
private readonly receive;
|
|
90
|
+
/** Returns whether this context can accept ownership over the given link type. */
|
|
91
|
+
private canOwn;
|
|
92
|
+
/** Resolves whether this context represents the OpenFin platform provider. */
|
|
93
|
+
private resolveOpenFinProvider;
|
|
94
|
+
/** Resolves the handshake orphan policy for the current platform context. */
|
|
95
|
+
private orphanPolicy;
|
|
96
|
+
/** Tests whether the parent window is inaccessible due to cross-origin boundaries. */
|
|
97
|
+
private isCrossOriginFrame;
|
|
98
|
+
/** Identifies the candidate upstream link based on platform hierarchy. */
|
|
99
|
+
private candidateUpstream;
|
|
100
|
+
/** Opens control links supported by the current runtime environment. */
|
|
101
|
+
private openControlLinks;
|
|
102
|
+
/** Returns the singleton OpenFin InterApplicationBus link. */
|
|
103
|
+
private ensureOpenFinLink;
|
|
104
|
+
/**
|
|
105
|
+
* Executes a hello/welcome handshake over candidate link.
|
|
106
|
+
* @param candidate Upstream link candidate.
|
|
107
|
+
* @returns True if welcome response arrived before timeout.
|
|
108
|
+
*/
|
|
109
|
+
private handshake;
|
|
110
|
+
/** Broadcasts tab claim and queries existing journey state. */
|
|
111
|
+
private announce;
|
|
112
|
+
}
|
|
113
|
+
/** Buffers log records during bus role resolution with FIFO overflow eviction. */
|
|
114
|
+
export declare class BootBuffer {
|
|
115
|
+
private readonly config;
|
|
116
|
+
private readonly diagnostics;
|
|
117
|
+
/** Held records in FIFO order. */
|
|
118
|
+
private records;
|
|
119
|
+
/**
|
|
120
|
+
* @param config Active configuration instance.
|
|
121
|
+
* @param diagnostics Diagnostics reporter.
|
|
122
|
+
*/
|
|
123
|
+
constructor(config: ResolvedConfig, diagnostics: Diagnostics);
|
|
124
|
+
/**
|
|
125
|
+
* Buffers a record, dropping the oldest when capacity is exceeded.
|
|
126
|
+
* @param record Record to buffer.
|
|
127
|
+
*/
|
|
128
|
+
push(record: LogRecord): void;
|
|
129
|
+
/**
|
|
130
|
+
* Drains and returns all buffered records in FIFO order.
|
|
131
|
+
* @returns Buffered log records.
|
|
132
|
+
*/
|
|
133
|
+
release(): LogRecord[];
|
|
134
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Diagnostics } from "../core/diagnostics";
|
|
2
|
+
import { type BusMessage, type LinkKind, type MessageSource } from "../models/bus";
|
|
3
|
+
/** Bidirectional communication channel for bus message transport. */
|
|
4
|
+
export interface Link {
|
|
5
|
+
/** Channel transport kind. */
|
|
6
|
+
readonly kind: LinkKind;
|
|
7
|
+
/**
|
|
8
|
+
* Sends a message over the channel without throwing.
|
|
9
|
+
* @param message Bus message to transmit.
|
|
10
|
+
*/
|
|
11
|
+
post(message: BusMessage): void;
|
|
12
|
+
/** Releases listeners, subscriptions, or channels held open by the link. */
|
|
13
|
+
close(): void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Callback invoked when a bus message arrives on a link.
|
|
17
|
+
* @param message Received bus message.
|
|
18
|
+
* @param source Origin and link metadata.
|
|
19
|
+
*/
|
|
20
|
+
export type Receive = (message: BusMessage, source: MessageSource) => void;
|
|
21
|
+
/** Interface exposed on global symbol by same-origin parent runtimes. */
|
|
22
|
+
export interface DirectHost {
|
|
23
|
+
/**
|
|
24
|
+
* Accepts a message directly from a child frame and replies synchronously.
|
|
25
|
+
* @param message Child bus message.
|
|
26
|
+
* @param reply Callback for synchronous response.
|
|
27
|
+
*/
|
|
28
|
+
busAccept(message: BusMessage, reply: Receive): void;
|
|
29
|
+
}
|
|
30
|
+
/** Message port or dedicated/shared worker interface. */
|
|
31
|
+
export interface WorkerLike {
|
|
32
|
+
/**
|
|
33
|
+
* Sends a message to the worker or port.
|
|
34
|
+
* @param message Payload to send.
|
|
35
|
+
*/
|
|
36
|
+
postMessage(message: unknown): void;
|
|
37
|
+
/**
|
|
38
|
+
* Subscribes to incoming message events.
|
|
39
|
+
* @param type Event name ("message").
|
|
40
|
+
* @param listener Event handler callback.
|
|
41
|
+
*/
|
|
42
|
+
addEventListener(type: "message", listener: (event: MessageEvent) => void): void;
|
|
43
|
+
/**
|
|
44
|
+
* Unsubscribes from message events.
|
|
45
|
+
* @param type Event name ("message").
|
|
46
|
+
* @param listener Event handler to remove.
|
|
47
|
+
*/
|
|
48
|
+
removeEventListener(type: "message", listener: (event: MessageEvent) => void): void;
|
|
49
|
+
/** Starts message delivery on MessagePort instances. */
|
|
50
|
+
start?: () => void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Establishes direct synchronous communication with a same-origin parent runtime.
|
|
54
|
+
* @param receive Callback for parent replies.
|
|
55
|
+
* @param diagnostics Diagnostics reporter.
|
|
56
|
+
* @returns Direct link, or null if parent is inaccessible or lacks a runtime.
|
|
57
|
+
*/
|
|
58
|
+
export declare function createDirectLink(receive: Receive, diagnostics: Diagnostics): Link | null;
|
|
59
|
+
/**
|
|
60
|
+
* Creates a postMessage link to the parent window.
|
|
61
|
+
* @param receive Callback for incoming parent messages.
|
|
62
|
+
* @param diagnostics Diagnostics reporter.
|
|
63
|
+
* @returns Link to parent window, or null if running in top-level window.
|
|
64
|
+
*/
|
|
65
|
+
export declare function createParentLink(receive: Receive, diagnostics: Diagnostics): Link | null;
|
|
66
|
+
/**
|
|
67
|
+
* Creates a link listening to child frames with origin allowlist filtering.
|
|
68
|
+
* @param receive Callback for messages from authorized child frames.
|
|
69
|
+
* @param trustedOrigins Additional origins allowed to communicate.
|
|
70
|
+
* @param diagnostics Diagnostics reporter.
|
|
71
|
+
* @returns Children link, or null in non-window environments.
|
|
72
|
+
*/
|
|
73
|
+
export declare function createChildrenLink(receive: Receive, trustedOrigins: string[], diagnostics: Diagnostics): Link | null;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a same-origin BroadcastChannel link for cross-tab control messages.
|
|
76
|
+
* @param channelName BroadcastChannel identifier.
|
|
77
|
+
* @param receive Callback for incoming cross-tab messages.
|
|
78
|
+
* @param diagnostics Diagnostics reporter.
|
|
79
|
+
* @returns Broadcast link, or null if unsupported.
|
|
80
|
+
*/
|
|
81
|
+
export declare function createBroadcastLink(channelName: string, receive: Receive, diagnostics: Diagnostics): Link | null;
|
|
82
|
+
/**
|
|
83
|
+
* Creates an OpenFin InterApplicationBus link across desktop views and applications.
|
|
84
|
+
* @param topic InterApplicationBus topic identifier.
|
|
85
|
+
* @param receive Callback for received topic messages.
|
|
86
|
+
* @param diagnostics Diagnostics reporter.
|
|
87
|
+
* @returns OpenFin link, or null if InterApplicationBus is unavailable.
|
|
88
|
+
*/
|
|
89
|
+
export declare function createOpenFinLink(topic: string, receive: Receive, diagnostics: Diagnostics): Link | null;
|
|
90
|
+
/**
|
|
91
|
+
* Creates the worker-side link pointing at the document that created this
|
|
92
|
+
* worker. Emits `kind: "owner"`.
|
|
93
|
+
* @param receive Callback for incoming messages from the owning document.
|
|
94
|
+
* @param diagnostics Diagnostics reporter.
|
|
95
|
+
* @returns Owner link, or null outside a DedicatedWorkerGlobalScope.
|
|
96
|
+
*/
|
|
97
|
+
export declare function createOwnerLink(receive: Receive, diagnostics: Diagnostics): Link | null;
|
|
98
|
+
/**
|
|
99
|
+
* Creates the document-side link pointing at one attached worker or port.
|
|
100
|
+
* Emits `kind: "worker"`.
|
|
101
|
+
* @param worker Target worker instance or MessagePort.
|
|
102
|
+
* @param receive Callback for messages from the worker.
|
|
103
|
+
* @param diagnostics Diagnostics reporter.
|
|
104
|
+
* @returns Document-to-worker link.
|
|
105
|
+
*/
|
|
106
|
+
export declare function createWorkerLink(worker: WorkerLike, receive: Receive, diagnostics: Diagnostics): Link;
|