@utk09/ui-observability 0.9.3 → 0.9.5
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 +90 -0
- package/README.md +199 -96
- package/dist/batch-BQFtb3i5.cjs +2 -0
- package/dist/batch-BQFtb3i5.cjs.map +1 -0
- package/dist/{batch-DDgxg16_.js → batch-BUJh-1jZ.js} +6 -4
- package/dist/batch-BUJh-1jZ.js.map +1 -0
- package/dist/bus/bus.d.ts +76 -2
- package/dist/bus/links.d.ts +9 -2
- package/dist/bus/validation.d.ts +7 -0
- package/dist/bus-BW6N-pY8.cjs +2 -0
- package/dist/bus-BW6N-pY8.cjs.map +1 -0
- package/dist/bus-DeOPHWaD.js +647 -0
- package/dist/bus-DeOPHWaD.js.map +1 -0
- package/dist/capture/network.d.ts +1 -0
- package/dist/capture/storm.d.ts +2 -1
- package/dist/capture/types.d.ts +5 -0
- package/dist/capture/web-socket.d.ts +40 -0
- package/dist/{console-BSusX_M-.cjs → console-Ce6heqZZ.cjs} +2 -2
- package/dist/console-Ce6heqZZ.cjs.map +1 -0
- package/dist/{console-Dv5GfaNn.js → console-DbAZYJuy.js} +4 -4
- package/dist/console-DbAZYJuy.js.map +1 -0
- package/dist/constants-CN7GE1Lt.js +246 -0
- package/dist/constants-CN7GE1Lt.js.map +1 -0
- package/dist/constants-CW-MlHdY.cjs +2 -0
- package/dist/constants-CW-MlHdY.cjs.map +1 -0
- package/dist/constants.d.ts +63 -11
- package/dist/context-storage-BjzeBSxH.cjs +2 -0
- package/dist/context-storage-BjzeBSxH.cjs.map +1 -0
- package/dist/context-storage-DxZf4Gfh.js +52 -0
- package/dist/context-storage-DxZf4Gfh.js.map +1 -0
- package/dist/core/breadcrumbs.d.ts +10 -3
- package/dist/core/context.d.ts +2 -0
- package/dist/core/diagnostics.d.ts +11 -3
- package/dist/core/journey.d.ts +7 -0
- package/dist/core/meter.d.ts +25 -2
- package/dist/core/pipeline.d.ts +41 -6
- package/dist/core/record.d.ts +42 -9
- package/dist/core/remote-sampling.d.ts +7 -3
- package/dist/core/runtime.d.ts +153 -6
- package/dist/core/sampling.d.ts +35 -2
- package/dist/core/sender.d.ts +43 -1
- package/dist/core/spans.d.ts +34 -0
- 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/emergency-queue-BYUyDHGD.js +69 -0
- package/dist/emergency-queue-BYUyDHGD.js.map +1 -0
- package/dist/emergency-queue-Cs1hrjsC.cjs +2 -0
- package/dist/emergency-queue-Cs1hrjsC.cjs.map +1 -0
- package/dist/{errors-DCZWcHkd.js → errors-BhC7HTSt.js} +8 -9
- package/dist/errors-BhC7HTSt.js.map +1 -0
- package/dist/errors-CgY633cG.cjs +3 -0
- package/dist/errors-CgY633cG.cjs.map +1 -0
- package/dist/factory-C5TujXlU.js +280 -0
- package/dist/factory-C5TujXlU.js.map +1 -0
- package/dist/factory-CNj4DH3n.cjs +2 -0
- package/dist/factory-CNj4DH3n.cjs.map +1 -0
- package/dist/fixed-window-CtaFHanJ.js +12 -0
- package/dist/fixed-window-CtaFHanJ.js.map +1 -0
- package/dist/fixed-window-CvESpFYV.cjs +2 -0
- package/dist/fixed-window-CvESpFYV.cjs.map +1 -0
- package/dist/identity-8vKkyAWm.js +103 -0
- package/dist/identity-8vKkyAWm.js.map +1 -0
- package/dist/identity-Da9TkuKd.cjs +2 -0
- package/dist/identity-Da9TkuKd.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +66 -6
- package/dist/index.js +1253 -595
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-storage-BTfIFRHF.cjs +2 -0
- package/dist/indexeddb-storage-BTfIFRHF.cjs.map +1 -0
- package/dist/{indexeddb-storage-T9YIYVYC.js → indexeddb-storage-CCA1LvtO.js} +45 -30
- package/dist/indexeddb-storage-CCA1LvtO.js.map +1 -0
- package/dist/{interactions-BLH_tX87.js → interactions-BUDLxbv1.js} +16 -12
- package/dist/interactions-BUDLxbv1.js.map +1 -0
- package/dist/interactions-NHbLKrqe.cjs +2 -0
- package/dist/interactions-NHbLKrqe.cjs.map +1 -0
- package/dist/{journey-yALMEWF7.js → journey-BUJ4WJxP.js} +37 -34
- package/dist/journey-BUJ4WJxP.js.map +1 -0
- package/dist/journey-B_tTnvac.cjs +2 -0
- package/dist/journey-B_tTnvac.cjs.map +1 -0
- package/dist/keys-BHhw_0Wh.cjs +2 -0
- package/dist/keys-BHhw_0Wh.cjs.map +1 -0
- package/dist/keys-D5r_GH9q.js +17 -0
- package/dist/keys-D5r_GH9q.js.map +1 -0
- package/dist/{library-request-CQD4HUiP.js → library-request-BKOcaKtQ.js} +3 -3
- package/dist/{library-request-CQD4HUiP.js.map → library-request-BKOcaKtQ.js.map} +1 -1
- package/dist/{library-request-BcAxuwsf.cjs → library-request-BaZOi4eg.cjs} +2 -2
- package/dist/{library-request-BcAxuwsf.cjs.map → library-request-BaZOi4eg.cjs.map} +1 -1
- package/dist/{long-frames-D4Bm3Zkz.cjs → long-frames-CF3qiSAX.cjs} +2 -2
- package/dist/long-frames-CF3qiSAX.cjs.map +1 -0
- package/dist/{long-frames-DD_Um9_4.js → long-frames-DI5ypfAF.js} +5 -5
- package/dist/long-frames-DI5ypfAF.js.map +1 -0
- package/dist/models/batch.d.ts +4 -0
- package/dist/models/bus.d.ts +32 -9
- package/dist/models/config.d.ts +401 -12
- package/dist/models/drop.d.ts +1 -1
- package/dist/models/health.d.ts +27 -0
- package/dist/models/log-record.d.ts +1 -1
- package/dist/models/plugin.d.ts +47 -0
- package/dist/models/stats.d.ts +11 -0
- package/dist/models/storage.d.ts +13 -0
- package/dist/network-CF8UO5PK.cjs +2 -0
- package/dist/network-CF8UO5PK.cjs.map +1 -0
- package/dist/{network--GoE7_Or.js → network-DdzXDI3J.js} +47 -31
- package/dist/network-DdzXDI3J.js.map +1 -0
- package/dist/openfin-BwEN0uj4.js.map +1 -1
- package/dist/openfin-DtH2f7zX.cjs.map +1 -1
- package/dist/{platform-GaM6h7XM.js → platform-Bw1btWCT.js} +21 -10
- package/dist/platform-Bw1btWCT.js.map +1 -0
- package/dist/platform-DBSKTvFn.cjs +2 -0
- package/dist/platform-DBSKTvFn.cjs.map +1 -0
- package/dist/remote-rules-DIcC5vVC.js +91 -0
- package/dist/remote-rules-DIcC5vVC.js.map +1 -0
- package/dist/remote-rules-DpFmOef2.cjs +2 -0
- package/dist/remote-rules-DpFmOef2.cjs.map +1 -0
- package/dist/sampling-BVjspJWu.cjs +2 -0
- package/dist/sampling-BVjspJWu.cjs.map +1 -0
- package/dist/sampling-Cm3WhI0a.js +76 -0
- package/dist/sampling-Cm3WhI0a.js.map +1 -0
- package/dist/{sanitize-DP0xDPrt.js → sanitize-C-ahCFsG.js} +2 -2
- package/dist/{sanitize-DP0xDPrt.js.map → sanitize-C-ahCFsG.js.map} +1 -1
- package/dist/{sanitize--_e4oOPX.cjs → sanitize-DHucKGdi.cjs} +2 -2
- package/dist/{sanitize--_e4oOPX.cjs.map → sanitize-DHucKGdi.cjs.map} +1 -1
- package/dist/sender-D3fRCR8d.cjs +3 -0
- package/dist/sender-D3fRCR8d.cjs.map +1 -0
- package/dist/sender-DUUmSglb.js +1163 -0
- package/dist/sender-DUUmSglb.js.map +1 -0
- package/dist/storage/context-storage.d.ts +89 -0
- package/dist/storage/emergency-queue.d.ts +9 -1
- package/dist/storage/factory.d.ts +7 -1
- package/dist/storage/idb-driver.d.ts +13 -0
- package/dist/storage/indexeddb-storage.d.ts +13 -0
- package/dist/storage/local-storage.d.ts +21 -1
- package/dist/storage/memory-storage.d.ts +13 -0
- package/dist/storage-BA9RqRO-.cjs +2 -0
- package/dist/storage-BA9RqRO-.cjs.map +1 -0
- package/dist/storage-w7Tslvlq.js +17 -0
- package/dist/storage-w7Tslvlq.js.map +1 -0
- package/dist/storm-CNZjsw4T.cjs +2 -0
- package/dist/storm-CNZjsw4T.cjs.map +1 -0
- package/dist/storm-Daq2jGHU.js +10 -0
- package/dist/storm-Daq2jGHU.js.map +1 -0
- package/dist/transport/exit-flush.d.ts +6 -0
- package/dist/transport/http-transport.d.ts +2 -1
- package/dist/transport/retry-engine.d.ts +7 -2
- package/dist/transport/serializers/otlp-traces.d.ts +3 -0
- package/dist/transport/serializers/select.d.ts +8 -5
- package/dist/transport/status-transport.d.ts +24 -0
- package/dist/types-BR9t_w28.js +8 -0
- package/dist/types-BR9t_w28.js.map +1 -0
- package/dist/types-C7WNpnG1.cjs +2 -0
- package/dist/types-C7WNpnG1.cjs.map +1 -0
- package/dist/utils/fixed-window.d.ts +9 -0
- package/dist/utils/identity.d.ts +20 -2
- package/dist/utils/lock.d.ts +8 -0
- package/dist/utils/openfin.d.ts +1 -1
- package/dist/utils/platform.d.ts +10 -0
- package/dist/utils/tracing.d.ts +82 -4
- package/dist/web-socket-BacvKOvD.cjs +2 -0
- package/dist/web-socket-BacvKOvD.cjs.map +1 -0
- package/dist/web-socket-CpsD8WAa.js +105 -0
- package/dist/web-socket-CpsD8WAa.js.map +1 -0
- package/package.json +1 -1
- package/dist/batch-D5qvsMQ_.cjs +0 -2
- package/dist/batch-D5qvsMQ_.cjs.map +0 -1
- package/dist/batch-DDgxg16_.js.map +0 -1
- package/dist/bus-C6RwKzPW.js +0 -478
- package/dist/bus-C6RwKzPW.js.map +0 -1
- package/dist/bus-WPVDFw2y.cjs +0 -2
- package/dist/bus-WPVDFw2y.cjs.map +0 -1
- package/dist/console-BSusX_M-.cjs.map +0 -1
- package/dist/console-Dv5GfaNn.js.map +0 -1
- package/dist/constants-Cb92egPS.cjs +0 -2
- package/dist/constants-Cb92egPS.cjs.map +0 -1
- package/dist/constants-DhH6VI5a.js +0 -144
- package/dist/constants-DhH6VI5a.js.map +0 -1
- package/dist/deadline-CUrH0Hd8.cjs +0 -2
- package/dist/deadline-CUrH0Hd8.cjs.map +0 -1
- package/dist/deadline-DeqXEliN.js +0 -31
- package/dist/deadline-DeqXEliN.js.map +0 -1
- package/dist/errors-DCZWcHkd.js.map +0 -1
- package/dist/errors-ERu-su8m.cjs +0 -3
- package/dist/errors-ERu-su8m.cjs.map +0 -1
- package/dist/fixed-window-BR0bu32Y.cjs +0 -2
- package/dist/fixed-window-BR0bu32Y.cjs.map +0 -1
- package/dist/fixed-window-Re7jIRJH.js +0 -9
- package/dist/fixed-window-Re7jIRJH.js.map +0 -1
- package/dist/identity-C1WLItSl.cjs +0 -2
- package/dist/identity-C1WLItSl.cjs.map +0 -1
- package/dist/identity-Di-QXGCC.js +0 -88
- package/dist/identity-Di-QXGCC.js.map +0 -1
- package/dist/indexeddb-storage-DX18p39D.cjs +0 -2
- package/dist/indexeddb-storage-DX18p39D.cjs.map +0 -1
- package/dist/indexeddb-storage-T9YIYVYC.js.map +0 -1
- package/dist/interactions-BLH_tX87.js.map +0 -1
- package/dist/interactions-_hfOerfC.cjs +0 -2
- package/dist/interactions-_hfOerfC.cjs.map +0 -1
- package/dist/journey-BRUj0hqD.cjs +0 -2
- package/dist/journey-BRUj0hqD.cjs.map +0 -1
- package/dist/journey-yALMEWF7.js.map +0 -1
- package/dist/long-frames-D4Bm3Zkz.cjs.map +0 -1
- package/dist/long-frames-DD_Um9_4.js.map +0 -1
- package/dist/network--GoE7_Or.js.map +0 -1
- package/dist/network-DcuS2H1P.cjs +0 -2
- package/dist/network-DcuS2H1P.cjs.map +0 -1
- package/dist/platform-GaM6h7XM.js.map +0 -1
- package/dist/platform-kIL5AZB7.cjs +0 -2
- package/dist/platform-kIL5AZB7.cjs.map +0 -1
- package/dist/remote-rules-6ePq8CrI.js +0 -84
- package/dist/remote-rules-6ePq8CrI.js.map +0 -1
- package/dist/remote-rules-CI3gbRCL.cjs +0 -2
- package/dist/remote-rules-CI3gbRCL.cjs.map +0 -1
- package/dist/sampling-C-M8p3FK.cjs +0 -2
- package/dist/sampling-C-M8p3FK.cjs.map +0 -1
- package/dist/sampling-Ud_WiuU9.js +0 -65
- package/dist/sampling-Ud_WiuU9.js.map +0 -1
- package/dist/sender-BESHz6my.cjs +0 -3
- package/dist/sender-BESHz6my.cjs.map +0 -1
- package/dist/sender-BUBWLn5i.js +0 -1244
- package/dist/sender-BUBWLn5i.js.map +0 -1
- package/dist/storm-DhHGHhOc.cjs +0 -2
- package/dist/storm-DhHGHhOc.cjs.map +0 -1
- package/dist/storm-OD5J6Ylm.js +0 -10
- package/dist/storm-OD5J6Ylm.js.map +0 -1
package/dist/core/runtime.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { Receive, WorkerLike } from "../bus/links";
|
|
2
2
|
import type { BusMessage } from "../models/bus";
|
|
3
|
-
import type {
|
|
3
|
+
import type { FrameOptions, SourceOptions } from "../models/bus";
|
|
4
|
+
import type { ObservabilityConfig, ResolvedConfig, SecurityContextUpdate, SecurityContextRotationOptions } from "../models/config";
|
|
4
5
|
import type { InstrumentDef, MetricAttributes } from "../models/metric";
|
|
5
6
|
import { type LogRecord } from "../models/log-record";
|
|
7
|
+
import type { DeliveryStats } from "../models/stats";
|
|
8
|
+
import type { ObservabilityHealth } from "../models/health";
|
|
6
9
|
import { ConsoleSink } from "../utils/console";
|
|
7
10
|
import { type Identity } from "../utils/identity";
|
|
8
11
|
import { type PlatformMetadata } from "../utils/platform";
|
|
@@ -15,7 +18,33 @@ import { JourneyEngine } from "./journey";
|
|
|
15
18
|
import { RecordBuilder } from "./record";
|
|
16
19
|
/** Manages subsystem lifecycles, bus coordination and record delivery. */
|
|
17
20
|
export declare class ObservabilityRuntime {
|
|
18
|
-
|
|
21
|
+
/** True while the runtime changes the security context. */
|
|
22
|
+
private rotating;
|
|
23
|
+
/** True while the runtime collects the last records of the old context. */
|
|
24
|
+
private closingContext;
|
|
25
|
+
/** Version of another SDK copy that owns the page runtime, or null. */
|
|
26
|
+
private mismatchVersion;
|
|
27
|
+
/** True if the configured context id differs from the owner context id. */
|
|
28
|
+
private contextMismatch;
|
|
29
|
+
/** Current context change. Shutdown waits for this promise. */
|
|
30
|
+
private rotation?;
|
|
31
|
+
/** Memory store kept for later context changes. */
|
|
32
|
+
private memoryStorage?;
|
|
33
|
+
/** True if the app supplied a context id at startup. */
|
|
34
|
+
private explicitSecurityContext;
|
|
35
|
+
/** True after this forwarder takes a context id from its owner. */
|
|
36
|
+
private ownerAdopted;
|
|
37
|
+
/**
|
|
38
|
+
* Checks if a security context change is in progress.
|
|
39
|
+
* @returns True until the current change completes.
|
|
40
|
+
*/
|
|
41
|
+
isRotating(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Locks or unlocks configuration at the request of the app. Other code of this origin can
|
|
44
|
+
* call this method. The lock does not control access.
|
|
45
|
+
* @param locked True to refuse changes through configure().
|
|
46
|
+
*/
|
|
47
|
+
setConfigurationLocked(locked: boolean): void;
|
|
19
48
|
/**
|
|
20
49
|
* Runtime of this copy of the library when another version owns the page runtime.
|
|
21
50
|
* It stays off the global key.
|
|
@@ -105,12 +134,31 @@ export declare class ObservabilityRuntime {
|
|
|
105
134
|
private readonly journeyOptions;
|
|
106
135
|
/** False in a runtime that an early log call started. The first configure() then sets limits. */
|
|
107
136
|
private tunablesLocked;
|
|
137
|
+
/**
|
|
138
|
+
* True for a console-only runtime. It sends nothing, joins no bus and installs no capture.
|
|
139
|
+
* Another version of the library on the page, or a server, makes it console-only.
|
|
140
|
+
*/
|
|
141
|
+
private readonly degraded;
|
|
142
|
+
/** True after the report of a destination on a server. The runtime reports it one time. */
|
|
143
|
+
private serverReported;
|
|
144
|
+
/**
|
|
145
|
+
* Ends the root span of a forwarder when its document unloads. The exit flush ends it only in
|
|
146
|
+
* the sender. Without this, the client spans of a frame or a view have no parent.
|
|
147
|
+
*/
|
|
148
|
+
private readonly onPageHide;
|
|
108
149
|
/**
|
|
109
150
|
* @param input Initial consumer configuration options.
|
|
110
|
-
* @param
|
|
111
|
-
* no capture.
|
|
151
|
+
* @param mismatch True for a console-only runtime next to another version.
|
|
112
152
|
*/
|
|
113
153
|
private constructor();
|
|
154
|
+
/**
|
|
155
|
+
* Adds a breadcrumb from app code. It copies the data now. A later change of the object of the
|
|
156
|
+
* app then does not change the trail.
|
|
157
|
+
* @param message Description of the event. A JavaScript caller can pass a value that is not a
|
|
158
|
+
* string. The library converts it.
|
|
159
|
+
* @param data Optional metadata.
|
|
160
|
+
*/
|
|
161
|
+
addBreadcrumb(message: unknown, data?: Record<string, unknown>): void;
|
|
114
162
|
/**
|
|
115
163
|
* Adds a value to a counter or a histogram. The meter sends one point at each interval.
|
|
116
164
|
* @param def Definition of the instrument.
|
|
@@ -118,6 +166,12 @@ export declare class ObservabilityRuntime {
|
|
|
118
166
|
* @param attributes Attribute set of the value.
|
|
119
167
|
*/
|
|
120
168
|
recordMetric(def: InstrumentDef, value: number, attributes?: MetricAttributes): void;
|
|
169
|
+
/**
|
|
170
|
+
* Builds and emits the record of one span. The console does not print it. minLevel does not
|
|
171
|
+
* drop it. The trace engine sampled the trace before the span existed.
|
|
172
|
+
* @param span The span data.
|
|
173
|
+
*/
|
|
174
|
+
private recordSpan;
|
|
121
175
|
/**
|
|
122
176
|
* Builds and emits the record of one aggregated point. The console does not print it.
|
|
123
177
|
* @param name Metric name.
|
|
@@ -125,12 +179,20 @@ export declare class ObservabilityRuntime {
|
|
|
125
179
|
* @param fields Metric fields of the point. The record limits do not cut them.
|
|
126
180
|
*/
|
|
127
181
|
private emitPoint;
|
|
182
|
+
/**
|
|
183
|
+
* Checks the source policy before a direct child link opens.
|
|
184
|
+
* @param source Child window.
|
|
185
|
+
* @param origin Origin of the child window.
|
|
186
|
+
* @returns True if the bus permits this source.
|
|
187
|
+
*/
|
|
188
|
+
readonly busCanAccept: (source: Window, origin: string) => boolean;
|
|
128
189
|
/**
|
|
129
190
|
* Receives direct messages from same-origin child frames.
|
|
130
191
|
* @param message Inbound bus message.
|
|
131
192
|
* @param reply Direct response callback.
|
|
193
|
+
* @param source Window of the child frame.
|
|
132
194
|
*/
|
|
133
|
-
readonly busAccept: (message: BusMessage, reply: Receive) => void;
|
|
195
|
+
readonly busAccept: (message: BusMessage, reply: Receive, source?: Window) => void;
|
|
134
196
|
/**
|
|
135
197
|
* Returns the runtime on the global key of this realm. Another copy of the library can own it.
|
|
136
198
|
* @returns Pinned runtime instance or null.
|
|
@@ -173,6 +235,24 @@ export declare class ObservabilityRuntime {
|
|
|
173
235
|
* @param input Partial configuration to merge.
|
|
174
236
|
*/
|
|
175
237
|
private reconfigure;
|
|
238
|
+
/**
|
|
239
|
+
* Tests if the runtime runs on a server, for example Node during server-side rendering.
|
|
240
|
+
* @returns True on Node.
|
|
241
|
+
*/
|
|
242
|
+
private onServer;
|
|
243
|
+
/**
|
|
244
|
+
* Removes the delivery settings from the input of a console-only runtime. On a server, it
|
|
245
|
+
* reports a destination one time.
|
|
246
|
+
* @param input Consumer configuration options.
|
|
247
|
+
* @returns The options that the runtime accepts.
|
|
248
|
+
*/
|
|
249
|
+
private allowed;
|
|
250
|
+
/**
|
|
251
|
+
* Removes delivery and identity changes while isolation is on. The other settings still apply.
|
|
252
|
+
* @param input Consumer configuration options.
|
|
253
|
+
* @returns The options without the refused delivery or identity changes.
|
|
254
|
+
*/
|
|
255
|
+
private keepRouting;
|
|
176
256
|
/**
|
|
177
257
|
* Restores the startup tunables in the next config. A part of the runtime reads each tunable
|
|
178
258
|
* one time. A later change has no effect. The runtime then refuses it.
|
|
@@ -250,6 +330,17 @@ export declare class ObservabilityRuntime {
|
|
|
250
330
|
private installCaptures;
|
|
251
331
|
/** Uninstalls the active capture modules. */
|
|
252
332
|
private uninstallCaptures;
|
|
333
|
+
/**
|
|
334
|
+
* Imports the WebSocket capture plugin. A failed import reports and skips it.
|
|
335
|
+
* @returns Promise that resolves to the class, or undefined if the import failed.
|
|
336
|
+
*/
|
|
337
|
+
private loadWebSocket;
|
|
338
|
+
/**
|
|
339
|
+
* Wraps a plugin as a capture module. The plugin gets public tools only.
|
|
340
|
+
* @param plugin Plugin of the app, or a built-in plugin.
|
|
341
|
+
* @returns The capture module.
|
|
342
|
+
*/
|
|
343
|
+
private pluginCapture;
|
|
253
344
|
/**
|
|
254
345
|
* Imports one capture module. A failed import reports and skips that module only.
|
|
255
346
|
* @param name Capture module name.
|
|
@@ -260,7 +351,14 @@ export declare class ObservabilityRuntime {
|
|
|
260
351
|
* Attaches a Web Worker or MessagePort to the bus for record forwarding.
|
|
261
352
|
* @param worker Target Worker or MessagePort instance.
|
|
262
353
|
*/
|
|
263
|
-
registerWorker(worker: WorkerLike): void;
|
|
354
|
+
registerWorker(worker: WorkerLike, options?: SourceOptions): () => void;
|
|
355
|
+
/**
|
|
356
|
+
* Registers a frame after the bus loads. Early removal cancels the registration.
|
|
357
|
+
* @param frame Child frame or window.
|
|
358
|
+
* @param options Expected origin and source permissions.
|
|
359
|
+
* @returns Function that removes this registration.
|
|
360
|
+
*/
|
|
361
|
+
registerFrame(frame: HTMLIFrameElement | Window, options: FrameOptions): () => void;
|
|
264
362
|
/** Flushes pending telemetry, unregisters listeners, and unpins the runtime instance. */
|
|
265
363
|
destroy(): Promise<void>;
|
|
266
364
|
/**
|
|
@@ -317,6 +415,55 @@ export declare class ObservabilityRuntime {
|
|
|
317
415
|
private readonly reportGap;
|
|
318
416
|
/** Makes and stores a new tab ID after a tab ID collision. */
|
|
319
417
|
private regenerateTabId;
|
|
418
|
+
/**
|
|
419
|
+
* Starts a new session in this context. It sends the open metric points, starts a new trace,
|
|
420
|
+
* ends the active journey and clears the breadcrumbs. Other tabs read the new id at their next
|
|
421
|
+
* startup.
|
|
422
|
+
*/
|
|
423
|
+
newSession(): void;
|
|
424
|
+
/**
|
|
425
|
+
* Closes the work of the old session and starts the given session.
|
|
426
|
+
* @param sessionId Id of the session to start.
|
|
427
|
+
*/
|
|
428
|
+
private resetSession;
|
|
429
|
+
/**
|
|
430
|
+
* Changes the delivery context in one operation. A second change must wait for this change.
|
|
431
|
+
* @param update New identity, delivery settings and context attributes.
|
|
432
|
+
* @param options Rule for records of the old context and the flush deadline.
|
|
433
|
+
* @returns Promise that resolves when the change completes. Invalid settings reject it.
|
|
434
|
+
*/
|
|
435
|
+
rotateSecurityContext(update: SecurityContextUpdate, options?: SecurityContextRotationOptions): Promise<void>;
|
|
436
|
+
/**
|
|
437
|
+
* Checks new settings, stops old delivery and starts the new context.
|
|
438
|
+
* @param update New identity, delivery settings and attributes.
|
|
439
|
+
* @param pending Rule for the old records.
|
|
440
|
+
* @param timeoutMs Maximum wait for an old-context flush, in milliseconds.
|
|
441
|
+
* @returns Promise that resolves when the context change completes.
|
|
442
|
+
*/
|
|
443
|
+
private rotateContext;
|
|
444
|
+
/**
|
|
445
|
+
* Moves the records of the old context into the new context.
|
|
446
|
+
* @param live Records that were in memory. They go through the live buffer.
|
|
447
|
+
* @param stored Batches that were stored. The new sender stores them again.
|
|
448
|
+
* @returns Promise that resolves when the stored batches are stored again.
|
|
449
|
+
*/
|
|
450
|
+
private carry;
|
|
451
|
+
/**
|
|
452
|
+
* Reads the state of this runtime. It does not wait for startup or the sender to load.
|
|
453
|
+
* @returns State, delivery counts and policies. The facade adds the logger cache counts.
|
|
454
|
+
*/
|
|
455
|
+
health(): Promise<Omit<ObservabilityHealth, "loggerCache">>;
|
|
456
|
+
/**
|
|
457
|
+
* Reads the delivery state of this context.
|
|
458
|
+
* @returns Promise that resolves to the counts and the time of the last accepted send.
|
|
459
|
+
*/
|
|
460
|
+
stats(): Promise<DeliveryStats>;
|
|
461
|
+
/**
|
|
462
|
+
* Removes stored records of one context or all contexts in the application namespace.
|
|
463
|
+
* @param scope Part of storage to clear.
|
|
464
|
+
* @returns Promise that resolves when removal completes.
|
|
465
|
+
*/
|
|
466
|
+
clearPersisted(scope: "context" | "namespace"): Promise<void>;
|
|
320
467
|
/**
|
|
321
468
|
* Counts the batches held in storage after a failed or deferred delivery.
|
|
322
469
|
* @returns Promise that resolves to the number of stored batches. A forwarder stores
|
package/dist/core/sampling.d.ts
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
import type { ResolvedConfig } from "../models/config";
|
|
2
|
-
import type { LogRecord } from "../models/log-record";
|
|
2
|
+
import type { LogLevel, LogRecord } from "../models/log-record";
|
|
3
3
|
import type { RemoteRules } from "./remote-sampling";
|
|
4
|
+
/** Value of the longest prefix that matches a namespace. */
|
|
5
|
+
interface PrefixMatch<T> {
|
|
6
|
+
/** Value of the prefix, for example a rate or a level. */
|
|
7
|
+
value: T;
|
|
8
|
+
/** Length of the prefix. */
|
|
9
|
+
length: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Finds the longest prefix in a map that matches a namespace.
|
|
13
|
+
* For example, trading.ticks overrides trading.
|
|
14
|
+
* @param namespace Target application namespace.
|
|
15
|
+
* @param values Value for each namespace prefix.
|
|
16
|
+
* @returns The match, or undefined if no prefix matches.
|
|
17
|
+
*/
|
|
18
|
+
export declare function longestPrefix<T>(namespace: string, values: Record<string, T>): PrefixMatch<T> | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Finds the minimum level of a namespace in the config. The longest matching prefix of
|
|
21
|
+
* `minLevels` wins. A namespace with no match uses `minLevel`.
|
|
22
|
+
* @param namespace Target application namespace.
|
|
23
|
+
* @param config Active configuration instance.
|
|
24
|
+
* @returns The minimum level of the namespace.
|
|
25
|
+
*/
|
|
26
|
+
export declare function levelFor(namespace: string, config: ResolvedConfig): LogLevel;
|
|
27
|
+
/**
|
|
28
|
+
* Decides if sampling keeps a key at a rate. One key always gives the same result.
|
|
29
|
+
* @param key Journey ID or trace ID.
|
|
30
|
+
* @param rate Sampling rate, 0..1.
|
|
31
|
+
* @returns True if sampling keeps the key.
|
|
32
|
+
*/
|
|
33
|
+
export declare function sampleKey(key: string, rate: number): boolean;
|
|
4
34
|
/** Fields that sampling reads. The caller knows all of them before it builds a record. */
|
|
5
35
|
export interface SampleInput {
|
|
6
36
|
/** Severity level of the entry. */
|
|
@@ -46,7 +76,10 @@ export declare class ErrorCeiling {
|
|
|
46
76
|
/**
|
|
47
77
|
* Checks a record against the limit. It counts only ERROR and FATAL records.
|
|
48
78
|
* @param record Record about to enter a stream.
|
|
79
|
+
* @param limit Maximum records in one window. Set 0 for no limit.
|
|
80
|
+
* @param windowMs Rate limit window, in milliseconds.
|
|
49
81
|
* @returns False when the window has no allowance left. The caller must drop the record.
|
|
50
82
|
*/
|
|
51
|
-
allow(record: LogRecord): boolean;
|
|
83
|
+
allow(record: LogRecord, limit?: number, windowMs?: number): boolean;
|
|
52
84
|
}
|
|
85
|
+
export {};
|
package/dist/core/sender.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import type { LogBatch } from "../models/batch";
|
|
1
2
|
import type { ResolvedConfig } from "../models/config";
|
|
2
3
|
import type { LossReporter } from "../models/drop";
|
|
3
4
|
import type { LogRecord } from "../models/log-record";
|
|
4
|
-
import {
|
|
5
|
+
import type { DeliveryStats } from "../models/stats";
|
|
6
|
+
import { type GapReporter, type StorageAdapter } from "../models/storage";
|
|
5
7
|
import type { Diagnostics } from "./diagnostics";
|
|
6
8
|
import type { RemoteSlot } from "./remote-sampling";
|
|
7
9
|
/** Inputs to build the delivery stack. */
|
|
8
10
|
export interface SenderDeps {
|
|
11
|
+
/** Memory store that this runtime keeps when the security context changes. */
|
|
12
|
+
storage?: StorageAdapter;
|
|
13
|
+
onStorage?: (storage: StorageAdapter) => void;
|
|
9
14
|
/** Active configuration instance. */
|
|
10
15
|
config: ResolvedConfig;
|
|
11
16
|
/** Diagnostics reporter. */
|
|
@@ -26,12 +31,18 @@ export declare class Sender {
|
|
|
26
31
|
private readonly pipeline;
|
|
27
32
|
private readonly exitFlush;
|
|
28
33
|
private readonly diagnostics;
|
|
34
|
+
private readonly transport;
|
|
35
|
+
/** True after retire(). A late emergency import then does not wake the retry engine. */
|
|
36
|
+
private retired;
|
|
37
|
+
/** Emergency queue import. retire() waits for it before it reads storage. */
|
|
38
|
+
private emergencyImport;
|
|
29
39
|
/**
|
|
30
40
|
* @param storage Storage adapter for undelivered batches.
|
|
31
41
|
* @param retry Retry engine for stored batches.
|
|
32
42
|
* @param pipeline Pipeline that batches records.
|
|
33
43
|
* @param exitFlush Handler that sends pending records on unload.
|
|
34
44
|
* @param diagnostics Diagnostics reporter.
|
|
45
|
+
* @param transport Transport of the pipeline and the retry engine.
|
|
35
46
|
*/
|
|
36
47
|
private constructor();
|
|
37
48
|
/**
|
|
@@ -51,11 +62,23 @@ export declare class Sender {
|
|
|
51
62
|
* @returns Promise that resolves when the pipeline sends or stores each batch.
|
|
52
63
|
*/
|
|
53
64
|
flush(): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Removes stored normal and emergency batches without sending them.
|
|
67
|
+
* @param scope Part of storage to clear.
|
|
68
|
+
* @param contextId Active delivery context id.
|
|
69
|
+
* @returns Promise that resolves when removal completes.
|
|
70
|
+
*/
|
|
71
|
+
clearPersisted(scope: "context" | "namespace", contextId: string): Promise<void>;
|
|
54
72
|
/**
|
|
55
73
|
* Counts the batches held in storage.
|
|
56
74
|
* @returns Promise that resolves to the batch count, or 0 if storage fails.
|
|
57
75
|
*/
|
|
58
76
|
queueDepth(): Promise<number>;
|
|
77
|
+
/**
|
|
78
|
+
* Reads the delivery state of the pipeline and the transport.
|
|
79
|
+
* @returns Records that wait, records in requests and the last accepted send.
|
|
80
|
+
*/
|
|
81
|
+
stats(): Omit<DeliveryStats, "stored">;
|
|
59
82
|
/**
|
|
60
83
|
* Sends pending records with a normal flush, then with the exit flush. Then it stops all
|
|
61
84
|
* timers and listeners. Then it closes storage. The normal flush keeps the headers, gzip
|
|
@@ -63,6 +86,25 @@ export declare class Sender {
|
|
|
63
86
|
* @returns Promise that resolves when storage closes.
|
|
64
87
|
*/
|
|
65
88
|
destroy(): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Stops this sender before a new delivery identity takes effect. It does not run exit delivery.
|
|
91
|
+
* @param policy Rule for the old records.
|
|
92
|
+
* @param timeoutMs Maximum wait for a flush, in milliseconds.
|
|
93
|
+
* @param contextId Identity of the old delivery context.
|
|
94
|
+
* @returns Records that were in memory, and the batches that were stored, after the delivery attempt.
|
|
95
|
+
*/
|
|
96
|
+
retire(policy: "discard" | "flush" | "retain" | "carry", timeoutMs: number, contextId: string): Promise<{
|
|
97
|
+
buffered: LogRecord[];
|
|
98
|
+
stored: LogBatch[];
|
|
99
|
+
}>;
|
|
100
|
+
/**
|
|
101
|
+
* Stores batches of an earlier context under this context. Then the retry engine sends them.
|
|
102
|
+
* The live buffer does not take them. A large backlog would exceed its budget.
|
|
103
|
+
* @param batches Stored batches of the earlier context.
|
|
104
|
+
* @param contextId Identity of this delivery context.
|
|
105
|
+
* @returns Promise that resolves when the batches are stored.
|
|
106
|
+
*/
|
|
107
|
+
adopt(batches: readonly LogBatch[], contextId: string): Promise<void>;
|
|
66
108
|
/**
|
|
67
109
|
* Moves the batches of the emergency queue into storage, then wakes the retry engine.
|
|
68
110
|
* The previous page load parked them during its unload.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { EndedTrace } from "../utils/tracing";
|
|
2
|
+
/** One span that the runtime records. */
|
|
3
|
+
export interface SpanData {
|
|
4
|
+
/** Span name. */
|
|
5
|
+
name: string;
|
|
6
|
+
/** "internal" for a root span, "client" for a request. */
|
|
7
|
+
kind: "internal" | "client";
|
|
8
|
+
/** Trace ID. */
|
|
9
|
+
traceId: string;
|
|
10
|
+
/** Span ID. */
|
|
11
|
+
spanId: string;
|
|
12
|
+
/** Span ID of the parent, or "" for a root span. */
|
|
13
|
+
parentSpanId: string;
|
|
14
|
+
/** Start time in epoch milliseconds. */
|
|
15
|
+
startMs: number;
|
|
16
|
+
/** End time in epoch milliseconds. */
|
|
17
|
+
endMs: number;
|
|
18
|
+
/** True for a failed operation. */
|
|
19
|
+
error: boolean;
|
|
20
|
+
/** Attributes of the span. */
|
|
21
|
+
attributes: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Builds the root span of an ambient trace that ended.
|
|
25
|
+
* @param ended The trace.
|
|
26
|
+
* @returns The span data.
|
|
27
|
+
*/
|
|
28
|
+
export declare function rootSpan(ended: EndedTrace): SpanData;
|
|
29
|
+
/**
|
|
30
|
+
* Builds the span fields of a span record. The record limits do not cut them.
|
|
31
|
+
* @param span The span data.
|
|
32
|
+
* @returns The fields.
|
|
33
|
+
*/
|
|
34
|
+
export declare function spanFields(span: SpanData): Record<string, unknown>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/utils/unref.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
typeof e != "number" && e.unref?.();
|
|
4
|
+
}
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/utils/deadline.ts
|
|
7
|
+
var t = class extends Error {
|
|
8
|
+
constructor(e) {
|
|
9
|
+
super(`The operation took longer than ${String(e)} ms.`), this.name = "DeadlineError";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
function n(n, r) {
|
|
13
|
+
let i, a = new Promise((n, a) => {
|
|
14
|
+
let o = setTimeout(() => {
|
|
15
|
+
a(new t(r));
|
|
16
|
+
}, r);
|
|
17
|
+
i = o, e(o);
|
|
18
|
+
});
|
|
19
|
+
return Promise.race([n, a]).finally(() => {
|
|
20
|
+
clearTimeout(i);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { n, e as r, t };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=deadline-5_PecIl5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deadline-5_PecIl5.js","names":["unrefTimer","timer","DeadlineError","ms","withDeadline","expire","deadline","work"],"sources":["../src/utils/unref.ts","../src/utils/deadline.ts"],"sourcesContent":["// src/utils/unref.ts\n//\n// Unreferences timer handles in Node and browser environments. A pending timer\n// keeps a Node process alive under SSR and in tests.\n\n/** Timer handle. It is a number in a browser and a Timeout object in Node. */\nexport type TimerHandle = number | { unref?: () => void };\n\n/**\n * Unreferences a timer handle. A pending timer then does not keep a Node.js process alive.\n * @param timer Timer handle returned by setTimeout.\n */\nexport function unrefTimer(timer: TimerHandle): void {\n if (typeof timer !== \"number\") {\n timer.unref?.();\n }\n}\n","// src/utils/deadline.ts\n//\n// Sets a deadline for a promise that can stay pending. A pending promise raises no\n// diagnostics event. Without a deadline, its caller waits forever and keeps its slot.\n\nimport { unrefTimer } from \"./unref\";\n\n/** Error of a promise that did not settle before its deadline. */\nexport class DeadlineError extends Error {\n /**\n * @param ms Deadline in milliseconds.\n */\n constructor(ms: number) {\n super(`The operation took longer than ${String(ms)} ms.`);\n this.name = \"DeadlineError\";\n }\n}\n\n/**\n * Rejects when a promise does not settle within a deadline.\n * @param work Promise to bound.\n * @param ms Deadline in milliseconds.\n * @returns The value of the promise, or a rejection after the deadline.\n */\nexport function withDeadline<T>(work: Promise<T>, ms: number): Promise<T> {\n let expire: ReturnType<typeof setTimeout> | undefined;\n\n const deadline = new Promise<never>((_resolve, reject) => {\n const timer = setTimeout(() => {\n reject(new DeadlineError(ms));\n }, ms);\n\n expire = timer;\n unrefTimer(timer);\n });\n\n // Clear the timer on success and on failure. If not, each storage call leaves an armed timer.\n return Promise.race([work, deadline]).finally(() => {\n clearTimeout(expire);\n });\n}\n"],"mappings":";AAYA,SAAgBA,EAAW,GAA0B;CACnD,AAAI,OAAOC,KAAU,YACnBA,EAAM,QAAQ;AAElB;;;ACRA,IAAaC,IAAb,cAAmC,MAAM;CAIvC,YAAY,GAAY;EAEtB,AADA,MAAM,kCAAkC,OAAOC,CAAE,EAAE,KAAK,GACxD,KAAK,OAAO;CACd;AACF;AAQA,SAAgBC,EAAgB,GAAkB,GAAwB;CACxE,IAAIC,GAEEC,IAAW,IAAI,SAAgB,GAAU,MAAW;EACxD,IAAML,IAAQ,iBAAiB;GAC7B,EAAO,IAAIC,EAAcC,CAAE,CAAC;EAC9B,GAAGA,CAAE;EAGL,AADA,IAASF,GACTD,EAAWC,CAAK;CAClB,CAAC;CAGD,OAAO,QAAQ,KAAK,CAACM,GAAMD,CAAQ,CAAC,CAAC,CAAC,cAAc;EAClD,aAAaD,CAAM;CACrB,CAAC;AACH"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e){typeof e!=`number`&&e.unref?.()}var t=class extends Error{constructor(e){super(`The operation took longer than ${String(e)} ms.`),this.name=`DeadlineError`}};function n(n,r){let i,a=new Promise((n,a)=>{let o=setTimeout(()=>{a(new t(r))},r);i=o,e(o)});return Promise.race([n,a]).finally(()=>{clearTimeout(i)})}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return t}});
|
|
2
|
+
//# sourceMappingURL=deadline-XSnm95pg.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deadline-XSnm95pg.cjs","names":["unrefTimer","timer","DeadlineError","ms","withDeadline","expire","deadline","reject","work"],"sources":["../src/utils/unref.ts","../src/utils/deadline.ts"],"sourcesContent":["// src/utils/unref.ts\n//\n// Unreferences timer handles in Node and browser environments. A pending timer\n// keeps a Node process alive under SSR and in tests.\n\n/** Timer handle. It is a number in a browser and a Timeout object in Node. */\nexport type TimerHandle = number | { unref?: () => void };\n\n/**\n * Unreferences a timer handle. A pending timer then does not keep a Node.js process alive.\n * @param timer Timer handle returned by setTimeout.\n */\nexport function unrefTimer(timer: TimerHandle): void {\n if (typeof timer !== \"number\") {\n timer.unref?.();\n }\n}\n","// src/utils/deadline.ts\n//\n// Sets a deadline for a promise that can stay pending. A pending promise raises no\n// diagnostics event. Without a deadline, its caller waits forever and keeps its slot.\n\nimport { unrefTimer } from \"./unref\";\n\n/** Error of a promise that did not settle before its deadline. */\nexport class DeadlineError extends Error {\n /**\n * @param ms Deadline in milliseconds.\n */\n constructor(ms: number) {\n super(`The operation took longer than ${String(ms)} ms.`);\n this.name = \"DeadlineError\";\n }\n}\n\n/**\n * Rejects when a promise does not settle within a deadline.\n * @param work Promise to bound.\n * @param ms Deadline in milliseconds.\n * @returns The value of the promise, or a rejection after the deadline.\n */\nexport function withDeadline<T>(work: Promise<T>, ms: number): Promise<T> {\n let expire: ReturnType<typeof setTimeout> | undefined;\n\n const deadline = new Promise<never>((_resolve, reject) => {\n const timer = setTimeout(() => {\n reject(new DeadlineError(ms));\n }, ms);\n\n expire = timer;\n unrefTimer(timer);\n });\n\n // Clear the timer on success and on failure. If not, each storage call leaves an armed timer.\n return Promise.race([work, deadline]).finally(() => {\n clearTimeout(expire);\n });\n}\n"],"mappings":"AAYA,SAAgBA,EAAW,EAA0B,CAC/C,OAAOC,GAAU,UACnBA,EAAM,QAAQ,CAElB,CCRA,IAAaC,EAAb,cAAmC,KAAM,CAIvC,YAAY,EAAY,CACtB,MAAM,kCAAkC,OAAOC,CAAE,EAAE,KAAK,EACxD,KAAK,KAAO,eACd,CACF,EAQA,SAAgBC,EAAgB,EAAkB,EAAwB,CACxE,IAAIC,EAEEC,EAAW,IAAI,SAAgB,EAAU,IAAW,CACxD,IAAML,EAAQ,eAAiB,CAC7BM,EAAO,IAAIL,EAAcC,CAAE,CAAC,CAC9B,EAAGA,CAAE,EAEL,EAASF,EACTD,EAAWC,CAAK,CAClB,CAAC,EAGD,OAAO,QAAQ,KAAK,CAACO,EAAMF,CAAQ,CAAC,CAAC,CAAC,YAAc,CAClD,aAAaD,CAAM,CACrB,CAAC,CACH"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { G as e, cn as t } from "./constants-CN7GE1Lt.js";
|
|
2
|
+
import { n } from "./deadline-5_PecIl5.js";
|
|
3
|
+
import { i as r } from "./batch-BUJh-1jZ.js";
|
|
4
|
+
import { n as i, t as a } from "./keys-D5r_GH9q.js";
|
|
5
|
+
//#region src/utils/lock.ts
|
|
6
|
+
function o(e, t, n, { skipIfBusy: r = !0 } = {}) {
|
|
7
|
+
let i = globalThis.navigator?.locks;
|
|
8
|
+
return i?.request ? t.guardAsync("storage.degraded", `The library could not get the lock ${e}.`, () => i.request(e, { ifAvailable: r }, (e) => e ? n() : Promise.resolve(void 0))) : n();
|
|
9
|
+
}
|
|
10
|
+
function s(e, t) {
|
|
11
|
+
return t ? `${e}:${encodeURIComponent(t)}` : e;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/storage/emergency-queue.ts
|
|
15
|
+
function c(e, t) {
|
|
16
|
+
let n = t.guard("storage.degraded", "An emergency entry is not valid JSON. The library dropped it.", () => JSON.parse(e));
|
|
17
|
+
return n === void 0 ? null : r(n) ? n : (t.report("storage.degraded", "An emergency entry is not a batch. The library dropped it."), null);
|
|
18
|
+
}
|
|
19
|
+
async function l(e, r, a, o) {
|
|
20
|
+
let s = 0;
|
|
21
|
+
for (let l of i(o, r)) {
|
|
22
|
+
let i = r.guard("storage.unavailable", "The library could not read the emergency queue.", () => {
|
|
23
|
+
let e = localStorage.getItem(l), t = e ? c(e, r) : null;
|
|
24
|
+
return t && !a(t) ? null : (localStorage.removeItem(l), t);
|
|
25
|
+
});
|
|
26
|
+
if (i) try {
|
|
27
|
+
await n(e.save(i), t), s++;
|
|
28
|
+
} catch (e) {
|
|
29
|
+
r.report("storage.degraded", "The library could not recover an emergency batch.", { key: l }, e);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return s;
|
|
33
|
+
}
|
|
34
|
+
function u(e, t, n) {
|
|
35
|
+
let r = p(e.persistenceNamespace), o = `writing the emergency queue, ${String(e.records.length)} records`, s = [], l = t.guard("storage.quota_exceeded", o, () => {
|
|
36
|
+
let n = i(r, t);
|
|
37
|
+
for (let e of n.slice(0, Math.max(0, n.length - 20 + 1))) {
|
|
38
|
+
let n = c(String(localStorage.getItem(e)), t);
|
|
39
|
+
n !== null && s.push(n), localStorage.removeItem(e);
|
|
40
|
+
}
|
|
41
|
+
return localStorage.setItem(a(r, e), JSON.stringify(e)), !0;
|
|
42
|
+
});
|
|
43
|
+
t.guard("pipeline.crashed", "The loss report of the emergency queue failed.", () => {
|
|
44
|
+
if (s.length > 0) {
|
|
45
|
+
let e = s.flatMap((e) => e.records);
|
|
46
|
+
n?.("exit_queue_full", e, s.map((e) => e.id));
|
|
47
|
+
}
|
|
48
|
+
l !== !0 && n?.("quota", e.records, [e.id]);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async function d(e, t, n = () => !0, r = "") {
|
|
52
|
+
return await o(s("ui-observability.emergency", r), t, () => l(e, t, n, p(r)), { skipIfBusy: !1 }) ?? 0;
|
|
53
|
+
}
|
|
54
|
+
function f(e, t, n = "", r = !1) {
|
|
55
|
+
let a = p(n);
|
|
56
|
+
t.guard("storage.unavailable", "The library could not clear the retired emergency queue.", () => {
|
|
57
|
+
for (let n of i(a, t)) {
|
|
58
|
+
let i = localStorage.getItem(n);
|
|
59
|
+
i && (r || c(i, t)?.routingContextId === e) && localStorage.removeItem(n);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function p(t = "") {
|
|
64
|
+
return t ? `ui-observability:namespaced:${encodeURIComponent(t)}:emergency:` : e;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { f as clearEmergencyContext, d as drainEmergencyQueue, o as n, u as saveToEmergencyQueue, s as t };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=emergency-queue-BYUyDHGD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emergency-queue-BYUyDHGD.js","names":["EMERGENCY_STORAGE_KEY_PREFIX","STORAGE_DEADLINE_MS","isLogBatch","keysWithPrefix","batchKey","withDrainLock","locks","diagnostics","name","skipIfBusy","lock","fn","lockName","namespace","readBatch","parsed","raw","importAll","moved","key","prefix","batch","value","accepts","withDeadline","storage","error","saveToEmergencyQueue","emergencyPrefix","context","evicted","saved","keys","old","dropped","records","one","onLoss","drainEmergencyQueue","clearEmergencyContext","all","id"],"sources":["../src/utils/lock.ts","../src/storage/emergency-queue.ts"],"sourcesContent":["// src/utils/lock.ts\n//\n// Coordinates origin-wide batch draining operations using the Web Locks API.\n// Without the lock, every window on the origin drains and sends the same batches.\n\nimport type { Diagnostics } from \"../core/diagnostics\";\n\n/** Lock grant object, or null when the lock is not available. */\ntype LockGrant = { name: string } | null;\n\n/** Structural interface for navigator.locks operations. */\ninterface LockManagerLike {\n /**\n * Requests a lock and executes a callback under the acquired lock grant.\n * @param name Lock name.\n * @param options Lock request options.\n * @param callback Callback that runs with the lock grant.\n */\n request<T>(\n name: string,\n options: { ifAvailable?: boolean },\n callback: (lock: LockGrant) => Promise<T>,\n ): Promise<T>;\n}\n\n/**\n * Executes an asynchronous function under a Web Locks API origin-wide lock.\n * It runs the task directly when the Web Locks API is not available.\n * @param name Origin-scoped lock identifier.\n * @param diagnostics Diagnostics reporter.\n * @param fn Asynchronous task to execute while holding the lock.\n * @param options Lock acquisition options.\n * @param options.skipIfBusy When true, the task does not run if another context holds the lock.\n * @returns Promise of the task result. It resolves to undefined when another context holds the\n * lock. A caller that reads undefined as a task result stops rescheduling.\n */\nexport function withDrainLock<T>(\n name: string,\n diagnostics: Diagnostics,\n fn: () => Promise<T>,\n { skipIfBusy = true }: { skipIfBusy?: boolean } = {},\n): Promise<T | undefined> {\n const locks = (globalThis as { navigator?: { locks?: LockManagerLike } }).navigator?.locks;\n\n // Run the task without a lock when the Web Locks API is not available.\n if (!locks?.request) {\n return fn();\n }\n\n return diagnostics.guardAsync(\n \"storage.degraded\",\n `The library could not get the lock ${name}.`,\n () =>\n locks.request(name, { ifAvailable: skipIfBusy }, (lock) =>\n lock ? fn() : Promise.resolve(undefined),\n ),\n );\n}\n\n/**\n * Gives the lock name of one application namespace. Two namespaces on one origin then do not wait for each other.\n * Without it, the retry pass of one application skips while the other holds the lock.\n * @param name Base lock name.\n * @param namespace Application storage namespace. An empty value keeps the base name.\n * @returns Lock name for this namespace.\n */\nexport function lockName(name: string, namespace: string): string {\n return namespace ? `${name}:${encodeURIComponent(namespace)}` : name;\n}\n","// src/storage/emergency-queue.ts\n//\n// This module keeps a synchronous localStorage queue. It holds oversized batches during unload.\n// Startup recovers them. The code is synchronous and never throws. It runs while the browser\n// destroys the document. No promise settles at that time.\n\nimport {\n EMERGENCY_LOCK_NAME,\n EMERGENCY_MAX_ENTRIES,\n EMERGENCY_STORAGE_KEY_PREFIX,\n STORAGE_DEADLINE_MS,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { isLogBatch, type LogBatch } from \"../models/batch\";\nimport type { LossReporter } from \"../models/drop\";\nimport type { StorageAdapter } from \"../models/storage\";\nimport { withDeadline } from \"../utils/deadline\";\nimport { lockName, withDrainLock } from \"../utils/lock\";\nimport { batchKey, keysWithPrefix } from \"./keys\";\n\n/**\n * Parses a raw storage string and validates it as a LogBatch.\n * @param raw Raw serialized storage string.\n * @param diagnostics Diagnostics reporter.\n * @returns Validated LogBatch or null if unparseable or malformed.\n */\nfunction readBatch(raw: string, diagnostics: Diagnostics): LogBatch | null {\n const parsed = diagnostics.guard(\n \"storage.degraded\",\n \"An emergency entry is not valid JSON. The library dropped it.\",\n () => JSON.parse(raw) as unknown,\n );\n\n // The guard above already reported a parse failure.\n if (parsed === undefined) {\n return null;\n }\n\n if (!isLogBatch(parsed)) {\n diagnostics.report(\n \"storage.degraded\",\n \"An emergency entry is not a batch. The library dropped it.\",\n );\n return null;\n }\n\n return parsed;\n}\n\n/**\n * Imports all emergency queue entries into the target adapter in FIFO order.\n * @param storage Destination storage adapter.\n * @param diagnostics Diagnostics reporter.\n * @returns Total number of recovered batches.\n */\nasync function importAll(\n storage: StorageAdapter,\n diagnostics: Diagnostics,\n accepts: (batch: LogBatch) => boolean,\n prefix: string,\n): Promise<number> {\n let moved = 0;\n\n for (const key of keysWithPrefix(prefix, diagnostics)) {\n // Read and remove the key in one synchronous step, before the async save. A second window\n // that imports at the same time cannot take the same batch. Parse each entry one time.\n // A batch of another context stays in the queue.\n const batch = diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not read the emergency queue.\",\n (): LogBatch | null => {\n const value = localStorage.getItem(key);\n const parsed = value ? readBatch(value, diagnostics) : null;\n if (parsed && !accepts(parsed)) {\n return null;\n }\n localStorage.removeItem(key);\n return parsed;\n },\n );\n\n if (!batch) {\n continue;\n }\n\n try {\n // Set a deadline. This code runs during startup. A save that does not settle keeps the\n // runtime not ready. Each record then goes to the boot buffer.\n await withDeadline(storage.save(batch), STORAGE_DEADLINE_MS);\n moved++;\n } catch (error) {\n diagnostics.report(\n \"storage.degraded\",\n \"The library could not recover an emergency batch.\",\n { key },\n error,\n );\n }\n }\n\n return moved;\n}\n\n/**\n * Writes an unsent batch to the emergency queue synchronously during unload.\n * @param batch Oversized log batch.\n * @param diagnostics Diagnostics reporter.\n * @param onLoss Receives the records of the old entries that the queue drops, and of a\n * batch that the store refuses.\n */\nexport function saveToEmergencyQueue(\n batch: LogBatch,\n diagnostics: Diagnostics,\n onLoss?: LossReporter,\n): void {\n // Name the record count. A full localStorage drops this batch permanently. Removal of\n // emergency keys cannot free quota that the keys of other applications use.\n const prefix = emergencyPrefix(batch.persistenceNamespace);\n const context = `writing the emergency queue, ${String(batch.records.length)} records`;\n const evicted: LogBatch[] = [];\n\n const saved = diagnostics.guard(\"storage.quota_exceeded\", context, () => {\n const keys = keysWithPrefix(prefix, diagnostics);\n\n // Remove the oldest entries to keep the queue within its capacity.\n for (const old of keys.slice(0, Math.max(0, keys.length - EMERGENCY_MAX_ENTRIES + 1))) {\n // A key that another window removed gives null. readBatch then rejects it.\n const dropped = readBatch(String(localStorage.getItem(old)), diagnostics);\n if (dropped !== null) {\n evicted.push(dropped);\n }\n localStorage.removeItem(old);\n }\n\n localStorage.setItem(batchKey(prefix, batch), JSON.stringify(batch));\n return true;\n });\n\n // The exit flush calls this function. A throw here skips the shutdown of the sender.\n diagnostics.guard(\"pipeline.crashed\", \"The loss report of the emergency queue failed.\", () => {\n if (evicted.length > 0) {\n const records = evicted.flatMap((one) => one.records);\n onLoss?.(\n \"exit_queue_full\",\n records,\n evicted.map((one) => one.id),\n );\n }\n\n if (saved !== true) {\n onLoss?.(\"quota\", batch.records, [batch.id]);\n }\n });\n}\n\n/**\n * Recovers the batches that earlier shutdowns saved to emergency storage.\n * @param storage Destination storage adapter.\n * @param diagnostics Diagnostics reporter.\n * @returns Promise that resolves to the number of recovered batches.\n */\nexport async function drainEmergencyQueue(\n storage: StorageAdapter,\n diagnostics: Diagnostics,\n accepts: (batch: LogBatch) => boolean = () => true,\n namespace = \"\",\n): Promise<number> {\n const moved = await withDrainLock(\n lockName(EMERGENCY_LOCK_NAME, namespace),\n diagnostics,\n () => importAll(storage, diagnostics, accepts, emergencyPrefix(namespace)),\n { skipIfBusy: false },\n );\n\n return moved ?? 0;\n}\n\n/**\n * Removes emergency entries of one context, or all entries in its namespace.\n * @param id Delivery context id.\n * @param diagnostics Diagnostics reporter.\n * @param namespace Application storage namespace.\n * @param all True to remove entries of all contexts in this namespace.\n */\nexport function clearEmergencyContext(\n id: string,\n diagnostics: Diagnostics,\n namespace = \"\",\n all = false,\n): void {\n const prefix = emergencyPrefix(namespace);\n diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not clear the retired emergency queue.\",\n () => {\n for (const key of keysWithPrefix(prefix, diagnostics)) {\n const raw = localStorage.getItem(key);\n if (raw && (all || readBatch(raw, diagnostics)?.routingContextId === id))\n localStorage.removeItem(key);\n }\n },\n );\n}\n\n/**\n * Gives the emergency storage prefix of one application namespace.\n * @param namespace Application namespace. An empty value uses the previous prefix.\n * @returns Prefix for this application emergency queue.\n */\nfunction emergencyPrefix(namespace = \"\"): string {\n return namespace\n ? `ui-observability:namespaced:${encodeURIComponent(namespace)}:emergency:`\n : EMERGENCY_STORAGE_KEY_PREFIX;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./constants-CW-MlHdY.cjs"),t=require("./deadline-XSnm95pg.cjs"),n=require("./batch-BQFtb3i5.cjs"),r=require("./keys-BHhw_0Wh.cjs");function i(e,t,n,{skipIfBusy:r=!0}={}){let i=globalThis.navigator?.locks;return i?.request?t.guardAsync(`storage.degraded`,`The library could not get the lock ${e}.`,()=>i.request(e,{ifAvailable:r},e=>e?n():Promise.resolve(void 0))):n()}function a(e,t){return t?`${e}:${encodeURIComponent(t)}`:e}function o(e,t){let r=t.guard(`storage.degraded`,`An emergency entry is not valid JSON. The library dropped it.`,()=>JSON.parse(e));return r===void 0?null:n.i(r)?r:(t.report(`storage.degraded`,`An emergency entry is not a batch. The library dropped it.`),null)}async function s(n,i,a,s){let c=0;for(let l of r.n(s,i)){let r=i.guard(`storage.unavailable`,`The library could not read the emergency queue.`,()=>{let e=localStorage.getItem(l),t=e?o(e,i):null;return t&&!a(t)?null:(localStorage.removeItem(l),t)});if(r)try{await t.n(n.save(r),e.cn),c++}catch(e){i.report(`storage.degraded`,`The library could not recover an emergency batch.`,{key:l},e)}}return c}function c(e,t,n){let i=d(e.persistenceNamespace),a=`writing the emergency queue, ${String(e.records.length)} records`,s=[],c=t.guard(`storage.quota_exceeded`,a,()=>{let n=r.n(i,t);for(let e of n.slice(0,Math.max(0,n.length-20+1))){let n=o(String(localStorage.getItem(e)),t);n!==null&&s.push(n),localStorage.removeItem(e)}return localStorage.setItem(r.t(i,e),JSON.stringify(e)),!0});t.guard(`pipeline.crashed`,`The loss report of the emergency queue failed.`,()=>{if(s.length>0){let e=s.flatMap(e=>e.records);n?.(`exit_queue_full`,e,s.map(e=>e.id))}c!==!0&&n?.(`quota`,e.records,[e.id])})}async function l(e,t,n=()=>!0,r=``){return await i(a(`ui-observability.emergency`,r),t,()=>s(e,t,n,d(r)),{skipIfBusy:!1})??0}function u(e,t,n=``,i=!1){let a=d(n);t.guard(`storage.unavailable`,`The library could not clear the retired emergency queue.`,()=>{for(let n of r.n(a,t)){let r=localStorage.getItem(n);r&&(i||o(r,t)?.routingContextId===e)&&localStorage.removeItem(n)}})}function d(t=``){return t?`ui-observability:namespaced:${encodeURIComponent(t)}:emergency:`:e.G}exports.clearEmergencyContext=u,exports.drainEmergencyQueue=l,exports.n=i,exports.saveToEmergencyQueue=c,exports.t=a;
|
|
2
|
+
//# sourceMappingURL=emergency-queue-Cs1hrjsC.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emergency-queue-Cs1hrjsC.cjs","names":["isLogBatch","keysWithPrefix","withDeadline","STORAGE_DEADLINE_MS","batchKey","EMERGENCY_STORAGE_KEY_PREFIX","require_constants","require_deadline","require_batch","require_keys","withDrainLock","locks","diagnostics","name","skipIfBusy","lock","fn","lockName","namespace","readBatch","parsed","raw","importAll","moved","key","prefix","batch","value","accepts","storage","error","saveToEmergencyQueue","emergencyPrefix","context","evicted","saved","keys","old","dropped","records","one","onLoss","drainEmergencyQueue","clearEmergencyContext","all","id"],"sources":["../src/utils/lock.ts","../src/storage/emergency-queue.ts"],"sourcesContent":["// src/utils/lock.ts\n//\n// Coordinates origin-wide batch draining operations using the Web Locks API.\n// Without the lock, every window on the origin drains and sends the same batches.\n\nimport type { Diagnostics } from \"../core/diagnostics\";\n\n/** Lock grant object, or null when the lock is not available. */\ntype LockGrant = { name: string } | null;\n\n/** Structural interface for navigator.locks operations. */\ninterface LockManagerLike {\n /**\n * Requests a lock and executes a callback under the acquired lock grant.\n * @param name Lock name.\n * @param options Lock request options.\n * @param callback Callback that runs with the lock grant.\n */\n request<T>(\n name: string,\n options: { ifAvailable?: boolean },\n callback: (lock: LockGrant) => Promise<T>,\n ): Promise<T>;\n}\n\n/**\n * Executes an asynchronous function under a Web Locks API origin-wide lock.\n * It runs the task directly when the Web Locks API is not available.\n * @param name Origin-scoped lock identifier.\n * @param diagnostics Diagnostics reporter.\n * @param fn Asynchronous task to execute while holding the lock.\n * @param options Lock acquisition options.\n * @param options.skipIfBusy When true, the task does not run if another context holds the lock.\n * @returns Promise of the task result. It resolves to undefined when another context holds the\n * lock. A caller that reads undefined as a task result stops rescheduling.\n */\nexport function withDrainLock<T>(\n name: string,\n diagnostics: Diagnostics,\n fn: () => Promise<T>,\n { skipIfBusy = true }: { skipIfBusy?: boolean } = {},\n): Promise<T | undefined> {\n const locks = (globalThis as { navigator?: { locks?: LockManagerLike } }).navigator?.locks;\n\n // Run the task without a lock when the Web Locks API is not available.\n if (!locks?.request) {\n return fn();\n }\n\n return diagnostics.guardAsync(\n \"storage.degraded\",\n `The library could not get the lock ${name}.`,\n () =>\n locks.request(name, { ifAvailable: skipIfBusy }, (lock) =>\n lock ? fn() : Promise.resolve(undefined),\n ),\n );\n}\n\n/**\n * Gives the lock name of one application namespace. Two namespaces on one origin then do not wait for each other.\n * Without it, the retry pass of one application skips while the other holds the lock.\n * @param name Base lock name.\n * @param namespace Application storage namespace. An empty value keeps the base name.\n * @returns Lock name for this namespace.\n */\nexport function lockName(name: string, namespace: string): string {\n return namespace ? `${name}:${encodeURIComponent(namespace)}` : name;\n}\n","// src/storage/emergency-queue.ts\n//\n// This module keeps a synchronous localStorage queue. It holds oversized batches during unload.\n// Startup recovers them. The code is synchronous and never throws. It runs while the browser\n// destroys the document. No promise settles at that time.\n\nimport {\n EMERGENCY_LOCK_NAME,\n EMERGENCY_MAX_ENTRIES,\n EMERGENCY_STORAGE_KEY_PREFIX,\n STORAGE_DEADLINE_MS,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { isLogBatch, type LogBatch } from \"../models/batch\";\nimport type { LossReporter } from \"../models/drop\";\nimport type { StorageAdapter } from \"../models/storage\";\nimport { withDeadline } from \"../utils/deadline\";\nimport { lockName, withDrainLock } from \"../utils/lock\";\nimport { batchKey, keysWithPrefix } from \"./keys\";\n\n/**\n * Parses a raw storage string and validates it as a LogBatch.\n * @param raw Raw serialized storage string.\n * @param diagnostics Diagnostics reporter.\n * @returns Validated LogBatch or null if unparseable or malformed.\n */\nfunction readBatch(raw: string, diagnostics: Diagnostics): LogBatch | null {\n const parsed = diagnostics.guard(\n \"storage.degraded\",\n \"An emergency entry is not valid JSON. The library dropped it.\",\n () => JSON.parse(raw) as unknown,\n );\n\n // The guard above already reported a parse failure.\n if (parsed === undefined) {\n return null;\n }\n\n if (!isLogBatch(parsed)) {\n diagnostics.report(\n \"storage.degraded\",\n \"An emergency entry is not a batch. The library dropped it.\",\n );\n return null;\n }\n\n return parsed;\n}\n\n/**\n * Imports all emergency queue entries into the target adapter in FIFO order.\n * @param storage Destination storage adapter.\n * @param diagnostics Diagnostics reporter.\n * @returns Total number of recovered batches.\n */\nasync function importAll(\n storage: StorageAdapter,\n diagnostics: Diagnostics,\n accepts: (batch: LogBatch) => boolean,\n prefix: string,\n): Promise<number> {\n let moved = 0;\n\n for (const key of keysWithPrefix(prefix, diagnostics)) {\n // Read and remove the key in one synchronous step, before the async save. A second window\n // that imports at the same time cannot take the same batch. Parse each entry one time.\n // A batch of another context stays in the queue.\n const batch = diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not read the emergency queue.\",\n (): LogBatch | null => {\n const value = localStorage.getItem(key);\n const parsed = value ? readBatch(value, diagnostics) : null;\n if (parsed && !accepts(parsed)) {\n return null;\n }\n localStorage.removeItem(key);\n return parsed;\n },\n );\n\n if (!batch) {\n continue;\n }\n\n try {\n // Set a deadline. This code runs during startup. A save that does not settle keeps the\n // runtime not ready. Each record then goes to the boot buffer.\n await withDeadline(storage.save(batch), STORAGE_DEADLINE_MS);\n moved++;\n } catch (error) {\n diagnostics.report(\n \"storage.degraded\",\n \"The library could not recover an emergency batch.\",\n { key },\n error,\n );\n }\n }\n\n return moved;\n}\n\n/**\n * Writes an unsent batch to the emergency queue synchronously during unload.\n * @param batch Oversized log batch.\n * @param diagnostics Diagnostics reporter.\n * @param onLoss Receives the records of the old entries that the queue drops, and of a\n * batch that the store refuses.\n */\nexport function saveToEmergencyQueue(\n batch: LogBatch,\n diagnostics: Diagnostics,\n onLoss?: LossReporter,\n): void {\n // Name the record count. A full localStorage drops this batch permanently. Removal of\n // emergency keys cannot free quota that the keys of other applications use.\n const prefix = emergencyPrefix(batch.persistenceNamespace);\n const context = `writing the emergency queue, ${String(batch.records.length)} records`;\n const evicted: LogBatch[] = [];\n\n const saved = diagnostics.guard(\"storage.quota_exceeded\", context, () => {\n const keys = keysWithPrefix(prefix, diagnostics);\n\n // Remove the oldest entries to keep the queue within its capacity.\n for (const old of keys.slice(0, Math.max(0, keys.length - EMERGENCY_MAX_ENTRIES + 1))) {\n // A key that another window removed gives null. readBatch then rejects it.\n const dropped = readBatch(String(localStorage.getItem(old)), diagnostics);\n if (dropped !== null) {\n evicted.push(dropped);\n }\n localStorage.removeItem(old);\n }\n\n localStorage.setItem(batchKey(prefix, batch), JSON.stringify(batch));\n return true;\n });\n\n // The exit flush calls this function. A throw here skips the shutdown of the sender.\n diagnostics.guard(\"pipeline.crashed\", \"The loss report of the emergency queue failed.\", () => {\n if (evicted.length > 0) {\n const records = evicted.flatMap((one) => one.records);\n onLoss?.(\n \"exit_queue_full\",\n records,\n evicted.map((one) => one.id),\n );\n }\n\n if (saved !== true) {\n onLoss?.(\"quota\", batch.records, [batch.id]);\n }\n });\n}\n\n/**\n * Recovers the batches that earlier shutdowns saved to emergency storage.\n * @param storage Destination storage adapter.\n * @param diagnostics Diagnostics reporter.\n * @returns Promise that resolves to the number of recovered batches.\n */\nexport async function drainEmergencyQueue(\n storage: StorageAdapter,\n diagnostics: Diagnostics,\n accepts: (batch: LogBatch) => boolean = () => true,\n namespace = \"\",\n): Promise<number> {\n const moved = await withDrainLock(\n lockName(EMERGENCY_LOCK_NAME, namespace),\n diagnostics,\n () => importAll(storage, diagnostics, accepts, emergencyPrefix(namespace)),\n { skipIfBusy: false },\n );\n\n return moved ?? 0;\n}\n\n/**\n * Removes emergency entries of one context, or all entries in its namespace.\n * @param id Delivery context id.\n * @param diagnostics Diagnostics reporter.\n * @param namespace Application storage namespace.\n * @param all True to remove entries of all contexts in this namespace.\n */\nexport function clearEmergencyContext(\n id: string,\n diagnostics: Diagnostics,\n namespace = \"\",\n all = false,\n): void {\n const prefix = emergencyPrefix(namespace);\n diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not clear the retired emergency queue.\",\n () => {\n for (const key of keysWithPrefix(prefix, diagnostics)) {\n const raw = localStorage.getItem(key);\n if (raw && (all || readBatch(raw, diagnostics)?.routingContextId === id))\n localStorage.removeItem(key);\n }\n },\n );\n}\n\n/**\n * Gives the emergency storage prefix of one application namespace.\n * @param namespace Application namespace. An empty value uses the previous prefix.\n * @returns Prefix for this application emergency queue.\n */\nfunction emergencyPrefix(namespace = \"\"): string {\n return namespace\n ? `ui-observability:namespaced:${encodeURIComponent(namespace)}:emergency:`\n : EMERGENCY_STORAGE_KEY_PREFIX;\n}\n"],"mappings":"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"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import "./constants-DhH6VI5a.js";
|
|
2
1
|
import { r as e } from "./error-like-Ywo5uRHo.js";
|
|
3
|
-
import { i as t } from "./platform-
|
|
4
|
-
import { t as n } from "./storm-
|
|
2
|
+
import { i as t } from "./platform-Bw1btWCT.js";
|
|
3
|
+
import { t as n } from "./storm-Daq2jGHU.js";
|
|
5
4
|
//#region src/capture/errors.ts
|
|
6
5
|
function r(t) {
|
|
7
6
|
if (e(t)) {
|
|
@@ -39,7 +38,7 @@ var i = class {
|
|
|
39
38
|
let n = e.target, r = n?.src ?? n?.href ?? "";
|
|
40
39
|
if (n !== null && n !== globalThis && r !== "") {
|
|
41
40
|
if (!this.ctx.config.capture.resourceErrors) return;
|
|
42
|
-
let e = this.ctx.config.capture.fullUrls
|
|
41
|
+
let e = t(r, this.ctx.config.capture.fullUrls, this.ctx.config.capture.urlTransform, this.ctx.diagnostics);
|
|
43
42
|
this.ctx.breadcrumbs.push({
|
|
44
43
|
t: Date.now(),
|
|
45
44
|
category: "http",
|
|
@@ -54,7 +53,7 @@ var i = class {
|
|
|
54
53
|
if (!this.ctx.config.capture.errors) return;
|
|
55
54
|
let i = e, a = i.message === "" ? "unknown error" : i.message, o = i.error ?? Error(a);
|
|
56
55
|
this.report("window.onerror", o, {
|
|
57
|
-
"error.source": i.filename,
|
|
56
|
+
"error.source": t(i.filename, this.ctx.config.capture.fullUrls, this.ctx.config.capture.urlTransform, this.ctx.diagnostics),
|
|
58
57
|
"error.line": i.lineno,
|
|
59
58
|
"error.column": i.colno
|
|
60
59
|
});
|
|
@@ -63,12 +62,12 @@ var i = class {
|
|
|
63
62
|
this.ctx.config.capture.rejections && this.report("unhandledrejection", e.reason, { "error.type": "unhandledrejection" });
|
|
64
63
|
};
|
|
65
64
|
report(e, t, i) {
|
|
66
|
-
if (!n(this.window,
|
|
65
|
+
if (!n(this.window, this.ctx.config.capturePolicy.errorsPerWindow, this.ctx.diagnostics, "errors", this.ctx.config.capturePolicy.windowMs)) return;
|
|
67
66
|
let a = Date.now(), { message: o, key: s } = this.ctx.diagnostics.guard("capture.record_failed", "The library could not read the error reason. It records the error without its message.", () => r(t)) ?? {
|
|
68
67
|
message: "",
|
|
69
68
|
key: `${typeof t}||`
|
|
70
69
|
}, c = this.seen.get(s);
|
|
71
|
-
if (c && a - c.at <
|
|
70
|
+
if (c && a - c.at < this.ctx.config.capturePolicy.errorDedupeMs) {
|
|
72
71
|
c.count++, c.at = a;
|
|
73
72
|
return;
|
|
74
73
|
}
|
|
@@ -76,7 +75,7 @@ var i = class {
|
|
|
76
75
|
if (this.seen.delete(s), this.seen.set(s, {
|
|
77
76
|
at: a,
|
|
78
77
|
count: 1
|
|
79
|
-
}), this.seen.size >
|
|
78
|
+
}), this.ctx.config.capturePolicy.maxErrorSignatures > 0 && this.seen.size > this.ctx.config.capturePolicy.maxErrorSignatures) {
|
|
80
79
|
let [e] = this.seen.keys();
|
|
81
80
|
this.seen.delete(e);
|
|
82
81
|
}
|
|
@@ -91,4 +90,4 @@ var i = class {
|
|
|
91
90
|
//#endregion
|
|
92
91
|
export { i as ErrorCapture };
|
|
93
92
|
|
|
94
|
-
//# sourceMappingURL=errors-
|
|
93
|
+
//# sourceMappingURL=errors-BhC7HTSt.js.map
|