@utk09/ui-observability 0.5.0 → 0.7.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/CHANGELOG.md +31 -0
- package/README.md +119 -60
- package/dist/bus/bus.d.ts +10 -10
- package/dist/bus/links.d.ts +1 -1
- package/dist/bus-DeZzr2bx.cjs +2 -0
- package/dist/bus-DeZzr2bx.cjs.map +1 -0
- package/dist/{bus-D3OO0OcL.js → bus-DfAbg_pg.js} +19 -19
- package/dist/bus-DfAbg_pg.js.map +1 -0
- package/dist/capture/network.d.ts +2 -2
- package/dist/capture/types.d.ts +10 -10
- package/dist/capture/web-vitals.d.ts +3 -3
- package/dist/constants-C8nZQBmQ.js +86 -0
- package/dist/constants-C8nZQBmQ.js.map +1 -0
- package/dist/constants-IBL_jd5R.cjs +2 -0
- package/dist/constants-IBL_jd5R.cjs.map +1 -0
- package/dist/constants.d.ts +56 -43
- package/dist/core/breadcrumbs.d.ts +14 -14
- package/dist/core/config.d.ts +5 -4
- package/dist/core/context.d.ts +2 -2
- package/dist/core/diagnostics.d.ts +10 -9
- package/dist/core/journey.d.ts +23 -20
- package/dist/core/logger.d.ts +7 -7
- package/dist/core/pipeline.d.ts +34 -29
- package/dist/core/record.d.ts +6 -6
- package/dist/core/runtime.d.ts +20 -18
- package/dist/core/sampling.d.ts +15 -16
- package/dist/core/sender.d.ts +1 -1
- package/dist/{errors-Dme9tz-6.js → errors-4MQyjZVj.js} +4 -4
- package/dist/errors-4MQyjZVj.js.map +1 -0
- package/dist/{errors-DPju_xSI.cjs → errors-CUdShXe7.cjs} +2 -2
- package/dist/errors-CUdShXe7.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.js +136 -115
- package/dist/index.js.map +1 -1
- package/dist/{indexeddb-storage-nxs_rxGx.js → indexeddb-storage-0LtUALBg.js} +16 -16
- package/dist/indexeddb-storage-0LtUALBg.js.map +1 -0
- package/dist/indexeddb-storage-CcEJlq2l.cjs +2 -0
- package/dist/indexeddb-storage-CcEJlq2l.cjs.map +1 -0
- package/dist/{interactions-DP0-rIPJ.cjs → interactions-BMNPQ3WH.cjs} +2 -2
- package/dist/interactions-BMNPQ3WH.cjs.map +1 -0
- package/dist/{interactions-C1romMpE.js → interactions-BaCmoGLB.js} +2 -2
- package/dist/interactions-BaCmoGLB.js.map +1 -0
- package/dist/models/batch.d.ts +12 -9
- package/dist/models/bus.d.ts +12 -13
- package/dist/models/config.d.ts +85 -44
- package/dist/models/log-record.d.ts +12 -10
- package/dist/models/serializer.d.ts +3 -2
- package/dist/models/storage.d.ts +2 -2
- package/dist/network-DBNvxCE3.cjs +2 -0
- package/dist/network-DBNvxCE3.cjs.map +1 -0
- package/dist/{network-au-Tqt1n.js → network-jQ2t8rU4.js} +4 -4
- package/dist/network-jQ2t8rU4.js.map +1 -0
- package/dist/platform-ByQllE_W.cjs +2 -0
- package/dist/platform-ByQllE_W.cjs.map +1 -0
- package/dist/{platform-DMYo3AX3.js → platform-YuByH8A5.js} +8 -8
- package/dist/platform-YuByH8A5.js.map +1 -0
- package/dist/{sampling-ByI5H44E.js → sampling-CbYySsZ1.js} +21 -18
- package/dist/sampling-CbYySsZ1.js.map +1 -0
- package/dist/sampling-Cs50xsZl.cjs +2 -0
- package/dist/sampling-Cs50xsZl.cjs.map +1 -0
- package/dist/{sender-R7lOpyNc.js → sender-BIob8eZz.js} +60 -60
- package/dist/sender-BIob8eZz.js.map +1 -0
- package/dist/sender-iOjzcueM.cjs +3 -0
- package/dist/sender-iOjzcueM.cjs.map +1 -0
- package/dist/storage/emergency-queue.d.ts +2 -2
- package/dist/storage/factory.d.ts +2 -1
- package/dist/storage/idb-driver.d.ts +19 -19
- package/dist/storage/indexeddb-storage.d.ts +18 -17
- package/dist/storage/keys.d.ts +1 -1
- package/dist/storage/local-storage.d.ts +19 -18
- package/dist/storage/memory-storage.d.ts +12 -11
- package/dist/transport/compression.d.ts +2 -2
- package/dist/transport/errors.d.ts +8 -7
- package/dist/transport/exit-flush.d.ts +27 -24
- package/dist/transport/http-transport.d.ts +18 -11
- package/dist/transport/retry-engine.d.ts +33 -28
- package/dist/transport/serializers/ecs.d.ts +1 -1
- package/dist/transport/serializers/otlp.d.ts +1 -1
- package/dist/unref-16maCyKA.js.map +1 -1
- package/dist/unref-CU9Nyz_9.cjs.map +1 -1
- package/dist/utils/console.d.ts +7 -6
- package/dist/utils/identity.d.ts +6 -5
- package/dist/utils/lock.d.ts +4 -4
- package/dist/utils/platform.d.ts +5 -3
- package/dist/utils/sanitize.d.ts +5 -2
- package/dist/utils/sequence.d.ts +2 -2
- package/dist/utils/tracing.d.ts +8 -7
- package/dist/web-vitals-B2FYsEAU.cjs +2 -0
- package/dist/web-vitals-B2FYsEAU.cjs.map +1 -0
- package/dist/{web-vitals-DwWdLBq6.js → web-vitals-DHZ0yA_H.js} +4 -4
- package/dist/web-vitals-DHZ0yA_H.js.map +1 -0
- package/package.json +4 -2
- package/dist/bus-D3OO0OcL.js.map +0 -1
- package/dist/bus-OdRJVUzr.cjs +0 -2
- package/dist/bus-OdRJVUzr.cjs.map +0 -1
- package/dist/constants-B6kdsCzF.js +0 -75
- package/dist/constants-B6kdsCzF.js.map +0 -1
- package/dist/constants-DZH04585.cjs +0 -2
- package/dist/constants-DZH04585.cjs.map +0 -1
- package/dist/errors-DPju_xSI.cjs.map +0 -1
- package/dist/errors-Dme9tz-6.js.map +0 -1
- package/dist/indexeddb-storage-lGdoHGHy.cjs +0 -2
- package/dist/indexeddb-storage-lGdoHGHy.cjs.map +0 -1
- package/dist/indexeddb-storage-nxs_rxGx.js.map +0 -1
- package/dist/interactions-C1romMpE.js.map +0 -1
- package/dist/interactions-DP0-rIPJ.cjs.map +0 -1
- package/dist/network-DDVIJSHd.cjs +0 -2
- package/dist/network-DDVIJSHd.cjs.map +0 -1
- package/dist/network-au-Tqt1n.js.map +0 -1
- package/dist/platform-DMYo3AX3.js.map +0 -1
- package/dist/platform-g99Kn755.cjs +0 -2
- package/dist/platform-g99Kn755.cjs.map +0 -1
- package/dist/sampling-ByI5H44E.js.map +0 -1
- package/dist/sampling-Dui-Fp3u.cjs +0 -2
- package/dist/sampling-Dui-Fp3u.cjs.map +0 -1
- package/dist/sender-R7lOpyNc.js.map +0 -1
- package/dist/sender-vLcbQhiB.cjs +0 -3
- package/dist/sender-vLcbQhiB.cjs.map +0 -1
- package/dist/web-vitals-DM2nvcMJ.cjs +0 -2
- package/dist/web-vitals-DM2nvcMJ.cjs.map +0 -1
- package/dist/web-vitals-DwWdLBq6.js.map +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Diagnostics } from "../core/diagnostics";
|
|
2
2
|
import { type LogBatch } from "../models/batch";
|
|
3
3
|
import type { GapReporter, PruneResult, StorageAdapter, StorageLimits } from "../models/storage";
|
|
4
|
-
/**
|
|
4
|
+
/** This StorageAdapter keeps batches in localStorage. */
|
|
5
5
|
export declare class LocalStorageStorage implements StorageAdapter {
|
|
6
6
|
private readonly limits;
|
|
7
7
|
private readonly diagnostics;
|
|
8
8
|
private readonly onGap?;
|
|
9
|
-
/**
|
|
9
|
+
/** This field holds the storage strategy name. */
|
|
10
10
|
readonly name = "localstorage";
|
|
11
11
|
/**
|
|
12
12
|
* @param limits Storage capacity and retention thresholds.
|
|
@@ -15,79 +15,80 @@ export declare class LocalStorageStorage implements StorageAdapter {
|
|
|
15
15
|
*/
|
|
16
16
|
constructor(limits: StorageLimits, diagnostics: Diagnostics, onGap?: GapReporter | undefined);
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Writes a batch to localStorage. It removes the oldest entries on a quota error.
|
|
19
19
|
* @param batch Batch to store.
|
|
20
20
|
*/
|
|
21
21
|
save(batch: LogBatch): Promise<void>;
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Returns up to `limit` batches in FIFO order. It does not delete them.
|
|
24
24
|
* @param limit Maximum number of batches to retrieve.
|
|
25
25
|
* @returns Promise resolving to an array of valid batches.
|
|
26
26
|
*/
|
|
27
27
|
take(limit: number): Promise<LogBatch[]>;
|
|
28
28
|
/**
|
|
29
|
-
* Deletes
|
|
29
|
+
* Deletes the batch with the given ID from localStorage.
|
|
30
30
|
* @param id Batch identifier.
|
|
31
31
|
*/
|
|
32
32
|
remove(id: string): Promise<void>;
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
34
|
+
* Sets the delivery attempt count of a stored batch. It does not change the key.
|
|
35
35
|
* @param id Batch identifier.
|
|
36
36
|
* @param attempts New absolute attempt count.
|
|
37
37
|
*/
|
|
38
38
|
bumpAttempts(id: string, attempts: number): Promise<void>;
|
|
39
39
|
/**
|
|
40
|
-
* Deletes expired batches
|
|
40
|
+
* Deletes expired batches. It then removes the oldest batches above the
|
|
41
|
+
* capacity limit.
|
|
41
42
|
* @returns Promise resolving to prune summary metrics.
|
|
42
43
|
*/
|
|
43
44
|
prune(): Promise<PruneResult>;
|
|
44
45
|
/**
|
|
45
|
-
* Returns
|
|
46
|
+
* Returns the number of stored batch keys. It does not deserialize the batches.
|
|
46
47
|
* @returns Promise resolving to batch count.
|
|
47
48
|
*/
|
|
48
49
|
count(): Promise<number>;
|
|
49
|
-
/**
|
|
50
|
+
/** This method deletes all batch keys from localStorage. */
|
|
50
51
|
clear(): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
+
/** This method does nothing. localStorage has no connection to close. */
|
|
52
53
|
close(): Promise<void>;
|
|
53
54
|
/**
|
|
54
55
|
* Writes a batch to localStorage.
|
|
55
56
|
* @param batch Batch to store.
|
|
56
|
-
* @param context
|
|
57
|
+
* @param context Text that diagnostics reports when the write fails.
|
|
57
58
|
* @returns True if the write succeeded.
|
|
58
59
|
*/
|
|
59
60
|
private write;
|
|
60
|
-
/**
|
|
61
|
+
/** This method removes the oldest quarter of the store to free quota. It counts the loss. */
|
|
61
62
|
private evictForQuota;
|
|
62
63
|
/**
|
|
63
|
-
* Reports dropped records to diagnostics and
|
|
64
|
+
* Reports dropped records to diagnostics and to the gap handler.
|
|
64
65
|
* @param result Eviction metrics.
|
|
65
66
|
*/
|
|
66
67
|
private reportGap;
|
|
67
68
|
/**
|
|
68
|
-
*
|
|
69
|
+
* Reads and validates the stored batch at a key.
|
|
69
70
|
* @param key Storage key to read.
|
|
70
71
|
* @returns Validated LogBatch or null if missing or malformed.
|
|
71
72
|
*/
|
|
72
73
|
private read;
|
|
73
74
|
/**
|
|
74
|
-
*
|
|
75
|
+
* Finds the storage key that ends with the batch ID.
|
|
75
76
|
* @param id Batch identifier.
|
|
76
77
|
* @returns Matching storage key string or null.
|
|
77
78
|
*/
|
|
78
79
|
private keyOf;
|
|
79
80
|
/**
|
|
80
|
-
* Deletes
|
|
81
|
+
* Deletes a list of storage keys.
|
|
81
82
|
* @param keys Keys to delete.
|
|
82
83
|
*/
|
|
83
84
|
private evict;
|
|
84
85
|
/**
|
|
85
|
-
* Deletes
|
|
86
|
+
* Deletes one storage key inside a guard.
|
|
86
87
|
* @param key Storage key to remove.
|
|
87
88
|
*/
|
|
88
89
|
private removeKey;
|
|
89
90
|
/**
|
|
90
|
-
* Returns all
|
|
91
|
+
* Returns all batch storage keys in sorted order.
|
|
91
92
|
* @returns Sorted array of storage keys.
|
|
92
93
|
*/
|
|
93
94
|
private keys;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { LogBatch } from "../models/batch";
|
|
2
2
|
import type { GapReporter, PruneResult, StorageAdapter, StorageLimits } from "../models/storage";
|
|
3
|
-
/**
|
|
3
|
+
/** This StorageAdapter keeps batches in volatile memory. */
|
|
4
4
|
export declare class MemoryStorage implements StorageAdapter {
|
|
5
5
|
private readonly limits;
|
|
6
6
|
private readonly onGap?;
|
|
7
|
-
/**
|
|
7
|
+
/** This field holds the storage strategy name. */
|
|
8
8
|
readonly name = "memory";
|
|
9
|
-
/**
|
|
9
|
+
/** This array holds the batches in FIFO order. */
|
|
10
10
|
private batches;
|
|
11
11
|
/**
|
|
12
12
|
* @param limits Storage capacity and retention thresholds.
|
|
@@ -14,39 +14,40 @@ export declare class MemoryStorage implements StorageAdapter {
|
|
|
14
14
|
*/
|
|
15
15
|
constructor(limits: StorageLimits, onGap?: GapReporter | undefined);
|
|
16
16
|
/**
|
|
17
|
-
* Appends a batch
|
|
17
|
+
* Appends a batch and applies retention pruning.
|
|
18
18
|
* @param batch Batch to store.
|
|
19
19
|
*/
|
|
20
20
|
save(batch: LogBatch): Promise<void>;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Returns up to `limit` batches in FIFO order. It does not delete them.
|
|
23
23
|
* @param limit Maximum number of batches to retrieve.
|
|
24
24
|
* @returns Promise resolving to an array of batches.
|
|
25
25
|
*/
|
|
26
26
|
take(limit: number): Promise<LogBatch[]>;
|
|
27
27
|
/**
|
|
28
|
-
* Deletes
|
|
28
|
+
* Deletes the batch with the given ID.
|
|
29
29
|
* @param id Batch identifier.
|
|
30
30
|
*/
|
|
31
31
|
remove(id: string): Promise<void>;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Sets the delivery attempt count of a stored batch.
|
|
34
34
|
* @param id Batch identifier.
|
|
35
35
|
* @param attempts New absolute attempt count.
|
|
36
36
|
*/
|
|
37
37
|
bumpAttempts(id: string, attempts: number): Promise<void>;
|
|
38
38
|
/**
|
|
39
|
-
* Removes expired batches
|
|
39
|
+
* Removes expired batches. It then removes the oldest batches above the
|
|
40
|
+
* capacity limit.
|
|
40
41
|
* @returns Promise resolving to prune summary metrics.
|
|
41
42
|
*/
|
|
42
43
|
prune(): Promise<PruneResult>;
|
|
43
44
|
/**
|
|
44
|
-
* Returns
|
|
45
|
+
* Returns the number of stored batches.
|
|
45
46
|
* @returns Promise resolving to batch count.
|
|
46
47
|
*/
|
|
47
48
|
count(): Promise<number>;
|
|
48
|
-
/**
|
|
49
|
+
/** This method deletes all stored batches. */
|
|
49
50
|
clear(): Promise<void>;
|
|
50
|
-
/**
|
|
51
|
+
/** This method deletes all stored batches when the storage closes. */
|
|
51
52
|
close(): Promise<void>;
|
|
52
53
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Compresses a string
|
|
3
|
-
*
|
|
2
|
+
* Compresses a string to gzip bytes with CompressionStream. The result is a
|
|
3
|
+
* Uint8Array on a non-shared ArrayBuffer. fetch accepts this result as BodyInit.
|
|
4
4
|
* @param text Raw serialized payload to compress.
|
|
5
5
|
* @returns Promise resolving to compressed Uint8Array, or null if CompressionStream is unsupported.
|
|
6
6
|
*/
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* offline and timeout
|
|
4
|
-
* too_large splits the batch.
|
|
2
|
+
* The failure kind sets the retry, backoff or drop behavior. The engine retries transient,
|
|
3
|
+
* offline and timeout failures with backoff. A throttled failure waits for the server delay.
|
|
4
|
+
* A too_large failure splits the batch. The engine drops a permanent failure. The server
|
|
5
|
+
* never accepts that batch.
|
|
5
6
|
*/
|
|
6
7
|
export type TransportFailureKind = "transient" | "throttled" | "too_large" | "permanent" | "timeout" | "offline";
|
|
7
|
-
/**
|
|
8
|
+
/** This error records a failed transport attempt, its failure kind and its metadata. */
|
|
8
9
|
export declare class TransportError extends Error {
|
|
9
10
|
readonly kind: TransportFailureKind;
|
|
10
11
|
readonly status?: number | undefined;
|
|
@@ -20,9 +21,9 @@ export declare class TransportError extends Error {
|
|
|
20
21
|
constructor(kind: TransportFailureKind, message: string, status?: number | undefined, retryAfterMs?: number | undefined, maxBytes?: number | undefined);
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
|
-
* Parses HTTP Retry-After
|
|
24
|
-
*
|
|
25
|
-
*
|
|
24
|
+
* Parses an HTTP Retry-After value into a delay in milliseconds. The value
|
|
25
|
+
* can be a number of seconds or an HTTP date. The function clamps a negative delay to zero.
|
|
26
|
+
* A date in the past gives a negative delay.
|
|
26
27
|
* @param header Raw Retry-After header string or null.
|
|
27
28
|
* @returns Non-negative delay in milliseconds, or undefined if invalid or missing.
|
|
28
29
|
*/
|
|
@@ -1,70 +1,73 @@
|
|
|
1
1
|
import type { Diagnostics } from "../core/diagnostics";
|
|
2
2
|
import type { LogBatch } from "../models/batch";
|
|
3
3
|
import type { ResolvedConfig } from "../models/config";
|
|
4
|
-
/**
|
|
4
|
+
/** This type names the lifecycle event or manual action that starts an exit flush. */
|
|
5
5
|
export type ExitReason = "hidden" | "pagehide" | "freeze" | "openfin-close" | "shutdown";
|
|
6
|
-
/**
|
|
6
|
+
/** This interface lists the dependencies of ExitFlush. */
|
|
7
7
|
export interface ExitFlushDeps {
|
|
8
|
-
/**
|
|
8
|
+
/** This field holds the active configuration. */
|
|
9
9
|
config: ResolvedConfig;
|
|
10
|
-
/**
|
|
10
|
+
/** This field holds the diagnostics reporter. */
|
|
11
11
|
diagnostics: Diagnostics;
|
|
12
|
-
/**
|
|
12
|
+
/** This callback drains all buffered and unconfirmed batches into one LogBatch. */
|
|
13
13
|
drainForExit: () => LogBatch | null;
|
|
14
|
-
/**
|
|
14
|
+
/** This callback drains only the buffered records. It does not touch an in-flight batch. */
|
|
15
15
|
drainPending: () => LogBatch | null;
|
|
16
16
|
}
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* This class flushes pending telemetry on document unload. It uses sendBeacon, a keepalive
|
|
19
|
+
* fetch or emergency storage.
|
|
20
|
+
*/
|
|
18
21
|
export declare class ExitFlush {
|
|
19
22
|
private readonly deps;
|
|
20
|
-
/**
|
|
23
|
+
/** This flag is true while the unload listeners are attached. */
|
|
21
24
|
private installed;
|
|
22
|
-
/**
|
|
25
|
+
/** This listener flushes on visibilitychange when the document becomes hidden. */
|
|
23
26
|
private readonly onVisibility;
|
|
24
|
-
/**
|
|
27
|
+
/** This listener flushes on the window pagehide event. */
|
|
25
28
|
private readonly onPageHide;
|
|
26
|
-
/**
|
|
29
|
+
/** This listener flushes on the document freeze event. */
|
|
27
30
|
private readonly onFreeze;
|
|
28
|
-
/**
|
|
31
|
+
/** This listener flushes on the OpenFin close-requested event. */
|
|
29
32
|
private readonly onOpenFinClose;
|
|
30
33
|
/**
|
|
31
34
|
* @param deps Injected configuration, diagnostics, and drain callback.
|
|
32
35
|
*/
|
|
33
36
|
constructor(deps: ExitFlushDeps);
|
|
34
|
-
/**
|
|
37
|
+
/** This method attaches the unload listeners to the document, the window and OpenFin. */
|
|
35
38
|
install(): void;
|
|
36
|
-
/**
|
|
39
|
+
/** This method removes all unload listeners and subscriptions. */
|
|
37
40
|
uninstall(): void;
|
|
38
41
|
/**
|
|
39
|
-
*
|
|
40
|
-
* emergency storage.
|
|
41
|
-
* listener.
|
|
42
|
+
* Drains pending records synchronously. It sends them with a beacon, a
|
|
43
|
+
* keepalive fetch or emergency storage. It never awaits and never throws. The caller is an
|
|
44
|
+
* unload listener.
|
|
42
45
|
* @param reason Trigger reason code.
|
|
43
46
|
*/
|
|
44
47
|
flush(reason: ExitReason): void;
|
|
45
48
|
/**
|
|
46
|
-
* Selects the drain for the reason. `hidden` occurs at each tab switch
|
|
47
|
-
* document continues to run.
|
|
48
|
-
*
|
|
49
|
+
* Selects the drain for the reason. `hidden` occurs at each tab switch. The
|
|
50
|
+
* document continues to run after it. A drain of the in-flight batch here sends it again
|
|
51
|
+
* with a new id. The server cannot deduplicate that second send.
|
|
49
52
|
* @param reason Trigger reason code.
|
|
50
53
|
* @returns Combined LogBatch, or null if no records are pending.
|
|
51
54
|
*/
|
|
52
55
|
private drain;
|
|
53
56
|
/**
|
|
54
|
-
*
|
|
57
|
+
* Parses the configured endpoint URL.
|
|
55
58
|
* @returns URL instance or null if missing or invalid.
|
|
56
59
|
*/
|
|
57
60
|
private endpointUrl;
|
|
58
61
|
/**
|
|
59
|
-
*
|
|
62
|
+
* Sends the payload as text/plain with navigator.sendBeacon.
|
|
60
63
|
* @param url Target endpoint URL with query parameters.
|
|
61
64
|
* @param body Serialized payload string.
|
|
62
65
|
* @returns The answer of the browser.
|
|
63
66
|
*/
|
|
64
67
|
private beacon;
|
|
65
68
|
/**
|
|
66
|
-
*
|
|
67
|
-
* document.
|
|
69
|
+
* Sends a fallback POST with fetch and `keepalive: true`. A keepalive request
|
|
70
|
+
* continues after the document closes. The browser cancels a plain fetch at page close.
|
|
68
71
|
* @param url Target endpoint URL.
|
|
69
72
|
* @param body Serialized payload string.
|
|
70
73
|
* @param reason Trigger reason code.
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { Diagnostics } from "../core/diagnostics";
|
|
2
2
|
import type { LogBatch } from "../models/batch";
|
|
3
3
|
import type { ResolvedConfig } from "../models/config";
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* This class sends serialized log batches over HTTP. It resolves headers, applies gzip
|
|
6
|
+
* compression and classifies errors.
|
|
7
|
+
*/
|
|
5
8
|
export declare class HttpTransport {
|
|
6
9
|
private readonly config;
|
|
7
10
|
private readonly diagnostics;
|
|
8
|
-
/**
|
|
11
|
+
/** This field holds the epoch time in milliseconds when the server throttle ends. */
|
|
9
12
|
private throttledUntil;
|
|
10
13
|
/**
|
|
11
14
|
* @param config Active configuration instance.
|
|
@@ -13,30 +16,34 @@ export declare class HttpTransport {
|
|
|
13
16
|
*/
|
|
14
17
|
constructor(config: ResolvedConfig, diagnostics: Diagnostics);
|
|
15
18
|
/**
|
|
16
|
-
*
|
|
19
|
+
* Sends one log batch over HTTP.
|
|
17
20
|
* @param batch Batch to send.
|
|
18
21
|
* @throws TransportError on transient, throttled, 413, or permanent network failures.
|
|
19
22
|
*/
|
|
20
23
|
send(batch: LogBatch): Promise<void>;
|
|
21
24
|
/**
|
|
22
|
-
* Returns the remaining throttle
|
|
25
|
+
* Returns the remaining throttle delay in milliseconds.
|
|
23
26
|
* @returns Milliseconds remaining in throttle window, or 0 if unthrottled.
|
|
24
27
|
*/
|
|
25
28
|
throttledForMs(): number;
|
|
26
29
|
/**
|
|
27
|
-
* Serializes, encodes
|
|
30
|
+
* Serializes, encodes and sends a batch. It throws a classified TransportError
|
|
31
|
+
* on failure.
|
|
28
32
|
* @param batch Batch to deliver.
|
|
29
|
-
* @param endpoint Ingest URL. The caller reads it one time. A reconfigure during the send
|
|
33
|
+
* @param endpoint Ingest URL. The caller reads it one time. A reconfigure during the send
|
|
34
|
+
* cannot change it.
|
|
30
35
|
*/
|
|
31
36
|
private post;
|
|
32
37
|
/**
|
|
33
|
-
* Compresses the serialized payload
|
|
38
|
+
* Compresses the serialized payload when gzip is enabled. The payload size must
|
|
39
|
+
* be at or above the threshold.
|
|
34
40
|
* @param text Serialized payload string.
|
|
35
41
|
* @returns Promise resolving to original string or compressed byte array.
|
|
36
42
|
*/
|
|
37
43
|
private encodeBody;
|
|
38
44
|
/**
|
|
39
|
-
*
|
|
45
|
+
* Sends the HTTP POST request with a timeout. It maps network errors to
|
|
46
|
+
* TransportError.
|
|
40
47
|
* @param endpoint Ingest URL.
|
|
41
48
|
* @param headers HTTP request headers.
|
|
42
49
|
* @param body Request body string or byte array.
|
|
@@ -45,20 +52,20 @@ export declare class HttpTransport {
|
|
|
45
52
|
*/
|
|
46
53
|
private dispatch;
|
|
47
54
|
/**
|
|
48
|
-
*
|
|
55
|
+
* Converts an HTTP error response into a classified TransportError.
|
|
49
56
|
* @param response Unsuccessful HTTP response.
|
|
50
57
|
* @param batchId Identifier of the rejected batch.
|
|
51
58
|
* @returns Classified TransportError instance.
|
|
52
59
|
*/
|
|
53
60
|
private classify;
|
|
54
61
|
/**
|
|
55
|
-
*
|
|
62
|
+
* Reads the optional maxBytes limit from a 413 response body.
|
|
56
63
|
* @param response HTTP 413 Response instance.
|
|
57
64
|
* @returns Promise resolving to maximum byte limit or undefined.
|
|
58
65
|
*/
|
|
59
66
|
private readMaxBytes;
|
|
60
67
|
/**
|
|
61
|
-
*
|
|
68
|
+
* Resolves the configured static or dynamic request headers.
|
|
62
69
|
* @returns Promise resolving to resolved header map.
|
|
63
70
|
*/
|
|
64
71
|
private resolveHeaders;
|
|
@@ -3,22 +3,25 @@ import { type LogBatch } from "../models/batch";
|
|
|
3
3
|
import type { ResolvedConfig } from "../models/config";
|
|
4
4
|
import type { StorageAdapter } from "../models/storage";
|
|
5
5
|
import type { HttpTransport } from "./http-transport";
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* This class sends persisted offline batches again on a timer. It uses backoff, a cross-tab
|
|
8
|
+
* drain lock and batch splitting.
|
|
9
|
+
*/
|
|
7
10
|
export declare class RetryEngine {
|
|
8
11
|
private readonly storage;
|
|
9
12
|
private readonly transport;
|
|
10
13
|
private readonly diagnostics;
|
|
11
14
|
private readonly config;
|
|
12
15
|
private readonly batchesPerDrain;
|
|
13
|
-
/**
|
|
16
|
+
/** This field holds the active retry timer handle. It is null when no timer is armed. */
|
|
14
17
|
private timer;
|
|
15
|
-
/**
|
|
18
|
+
/** This field counts consecutive failed deliveries. The backoff calculation uses it. */
|
|
16
19
|
private attempt;
|
|
17
|
-
/**
|
|
20
|
+
/** This flag is true while a storage drain runs. */
|
|
18
21
|
private draining;
|
|
19
|
-
/**
|
|
22
|
+
/** This flag is true when the engine is stopped. */
|
|
20
23
|
private stopped;
|
|
21
|
-
/**
|
|
24
|
+
/** This listener runs on the online event. It resets the attempt count and starts a drain. */
|
|
22
25
|
private readonly onOnline;
|
|
23
26
|
/**
|
|
24
27
|
* @param storage Storage adapter holding undelivered batches.
|
|
@@ -28,67 +31,69 @@ export declare class RetryEngine {
|
|
|
28
31
|
* @param batchesPerDrain Maximum batches processed per drain tick.
|
|
29
32
|
*/
|
|
30
33
|
constructor(storage: StorageAdapter, transport: HttpTransport, diagnostics: Diagnostics, config: ResolvedConfig, batchesPerDrain?: number);
|
|
31
|
-
/**
|
|
34
|
+
/** This method starts the engine. It listens for online events and arms the first timer. */
|
|
32
35
|
start(): void;
|
|
33
|
-
/**
|
|
36
|
+
/** This method schedules an earlier retry when storage receives a new offline batch. */
|
|
34
37
|
nudge(): void;
|
|
35
38
|
/**
|
|
36
|
-
*
|
|
37
|
-
* drain
|
|
38
|
-
* server
|
|
39
|
+
* Stores a batch that failed outside the drain loop. It applies the same rules
|
|
40
|
+
* as the drain. It does not store a refused batch whole. A whole batch causes another request
|
|
41
|
+
* with a payload that the server refused.
|
|
39
42
|
* @param batch Rejected batch, with its attempt already counted.
|
|
40
43
|
* @param error Failure thrown by the transport.
|
|
41
44
|
*/
|
|
42
45
|
storeFailed(batch: LogBatch, error: unknown): Promise<void>;
|
|
43
|
-
/**
|
|
46
|
+
/** This method stops the engine. It removes the listener and clears the pending timer. */
|
|
44
47
|
stop(): void;
|
|
45
48
|
/**
|
|
46
|
-
* Clears
|
|
49
|
+
* Clears the pending timer. It then schedules a drain after the delay.
|
|
47
50
|
* @param delayMs Delay duration in milliseconds.
|
|
48
51
|
*/
|
|
49
52
|
private schedule;
|
|
50
53
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
54
|
+
* Sets a deadline on a storage call. A call that does not settle keeps
|
|
55
|
+
* `draining` true. This window then runs no more drains.
|
|
53
56
|
* @param work Storage promise to bound.
|
|
54
57
|
* @returns The value of the promise, or a rejection after the deadline.
|
|
55
58
|
*/
|
|
56
59
|
private bounded;
|
|
57
|
-
/**
|
|
60
|
+
/** This method clears the pending timer when a timer is active. */
|
|
58
61
|
private clearTimer;
|
|
59
62
|
/**
|
|
60
|
-
*
|
|
61
|
-
* jitter, not a fixed offset.
|
|
63
|
+
* Calculates the exponential backoff delay from consecutive failures. It applies
|
|
64
|
+
* full jitter, not a fixed offset. With a fixed offset, tabs that reconnect together send
|
|
65
|
+
* their requests at the same time.
|
|
62
66
|
* @returns Backoff duration in milliseconds.
|
|
63
67
|
*/
|
|
64
68
|
private backoffMs;
|
|
65
|
-
/**
|
|
69
|
+
/** This method runs a drain under the origin-wide Web Lock. */
|
|
66
70
|
private drain;
|
|
67
71
|
/**
|
|
68
|
-
* Processes batches while
|
|
69
|
-
*
|
|
72
|
+
* Processes batches while it holds the Web Lock. It schedules the next tick.
|
|
73
|
+
* It always resolves. A throw leaves the engine idle with no armed timer.
|
|
70
74
|
* @returns Promise resolving to true on completion.
|
|
71
75
|
*/
|
|
72
76
|
private drainLocked;
|
|
73
77
|
/**
|
|
74
|
-
*
|
|
78
|
+
* Tries to deliver one batch. It removes the batch on success. It handles each
|
|
79
|
+
* failure kind on failure.
|
|
75
80
|
* @param batch Log batch to deliver.
|
|
76
|
-
* @returns True to continue
|
|
81
|
+
* @returns True to continue with the next batch. False to stop the current drain.
|
|
77
82
|
*/
|
|
78
83
|
private deliver;
|
|
79
84
|
/**
|
|
80
|
-
* Replaces a stored batch with
|
|
81
|
-
*
|
|
85
|
+
* Replaces a stored batch with the parts that survive its failure. The parts
|
|
86
|
+
* are the split halves, or nothing after a permanent refusal.
|
|
82
87
|
* @param batch Rejected log batch, already held in storage.
|
|
83
88
|
* @param error Failure thrown by the transport.
|
|
84
89
|
*/
|
|
85
90
|
private replaceStored;
|
|
86
91
|
/**
|
|
87
|
-
*
|
|
88
|
-
* refusal keeps nothing
|
|
92
|
+
* Selects the batches to keep after a failure. A 413 response splits the batch
|
|
93
|
+
* in two. A permanent refusal keeps nothing. Each other failure keeps the batch whole.
|
|
89
94
|
* @param batch Rejected log batch.
|
|
90
95
|
* @param error Failure thrown by the transport.
|
|
91
|
-
* @returns Batches to persist
|
|
96
|
+
* @returns Batches to persist. The array is empty when the engine drops the records.
|
|
92
97
|
*/
|
|
93
98
|
private toStorable;
|
|
94
99
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { LogSerializer } from "../../models/serializer";
|
|
2
|
-
/**
|
|
2
|
+
/** This serializer writes log records as Elastic Common Schema (ECS) NDJSON documents. */
|
|
3
3
|
export declare const ecsSerializer: LogSerializer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unref-16maCyKA.js","names":["unrefTimer","timer"],"sources":["../src/utils/unref.ts"],"sourcesContent":["// src/utils/unref.ts\n//\n//
|
|
1
|
+
{"version":3,"file":"unref-16maCyKA.js","names":["unrefTimer","timer"],"sources":["../src/utils/unref.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/** Cross-platform timer handle representing browser numeric IDs or Node Timeout objects. */\nexport type TimerHandle = number | { unref?: () => void };\n\n/**\n * Unreferences a timer handle to prevent it from keeping 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"],"mappings":";AAYA,SAAgBA,EAAW,GAA0B;CACnD,AAAI,OAAOC,KAAU,YACnBA,EAAM,QAAQ;AAElB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unref-CU9Nyz_9.cjs","names":["unrefTimer","timer"],"sources":["../src/utils/unref.ts"],"sourcesContent":["// src/utils/unref.ts\n//\n//
|
|
1
|
+
{"version":3,"file":"unref-CU9Nyz_9.cjs","names":["unrefTimer","timer"],"sources":["../src/utils/unref.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/** Cross-platform timer handle representing browser numeric IDs or Node Timeout objects. */\nexport type TimerHandle = number | { unref?: () => void };\n\n/**\n * Unreferences a timer handle to prevent it from keeping 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"],"mappings":"AAYA,SAAgBA,EAAW,EAA0B,CAC/C,OAAOC,GAAU,UACnBA,EAAM,QAAQ,CAElB"}
|
package/dist/utils/console.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import type { Diagnostics } from "../core/diagnostics";
|
|
2
|
+
import type { ResolvedConsole } from "../models/config";
|
|
2
3
|
import type { LogLevel } from "../models/log-record";
|
|
3
4
|
/** Mirrors log records directly to browser or Node console methods based on severity. */
|
|
4
5
|
export declare class ConsoleSink {
|
|
5
|
-
private
|
|
6
|
+
private settings;
|
|
6
7
|
private diagnostics;
|
|
7
8
|
/**
|
|
8
|
-
* @param
|
|
9
|
+
* @param settings Console level and styles. A null level prints nothing.
|
|
9
10
|
* @param diagnostics Diagnostics reporter.
|
|
10
11
|
*/
|
|
11
|
-
constructor(
|
|
12
|
+
constructor(settings: ResolvedConsole, diagnostics: Diagnostics);
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @param
|
|
14
|
+
* Replaces the console level and styles.
|
|
15
|
+
* @param settings Console level and styles. A null level prints nothing.
|
|
15
16
|
*/
|
|
16
|
-
update(
|
|
17
|
+
update(settings: ResolvedConsole): void;
|
|
17
18
|
/**
|
|
18
19
|
* Tests whether a level clears the console threshold.
|
|
19
20
|
* @param level Severity level of the record.
|
package/dist/utils/identity.d.ts
CHANGED
|
@@ -44,16 +44,17 @@ export declare const BROWSER_STORES: IdentityStores;
|
|
|
44
44
|
export declare function memoryStores(): IdentityStores;
|
|
45
45
|
/**
|
|
46
46
|
* Generates a random lowercase hexadecimal string of the specified byte length.
|
|
47
|
-
*
|
|
47
|
+
* It uses crypto.getRandomValues when it is available. Otherwise it uses Math.random.
|
|
48
48
|
* @param byteLength Number of random bytes to generate.
|
|
49
49
|
* @returns Hexadecimal string of length byteLength * 2.
|
|
50
50
|
*/
|
|
51
51
|
export declare function randomHex(byteLength: number): string;
|
|
52
52
|
/**
|
|
53
53
|
* Generates a unique identifier string using crypto.randomUUID or randomHex fallback.
|
|
54
|
+
* @param diagnostics Diagnostics reporter. It counts a blocked crypto.randomUUID call.
|
|
54
55
|
* @returns UUID or random hex identifier.
|
|
55
56
|
*/
|
|
56
|
-
export declare function newId(): string;
|
|
57
|
+
export declare function newId(diagnostics: Diagnostics): string;
|
|
57
58
|
/**
|
|
58
59
|
* Resolves or initializes session, tab, and context identifiers for the active realm.
|
|
59
60
|
* @param diagnostics Diagnostics reporter.
|
|
@@ -69,9 +70,9 @@ export declare function resolveIdentity(diagnostics: Diagnostics, stores?: Ident
|
|
|
69
70
|
*/
|
|
70
71
|
export declare function persistTabId(tabId: string, diagnostics: Diagnostics, stores: IdentityStores): void;
|
|
71
72
|
/**
|
|
72
|
-
* Writes the
|
|
73
|
-
* The
|
|
74
|
-
* must not
|
|
73
|
+
* Writes the last-seen timestamp of the session. `SESSION_TOUCH_MS` sets the throttle.
|
|
74
|
+
* The instance keeps the throttle state, not the module. Two runtimes in one document
|
|
75
|
+
* must not block the session writes of each other.
|
|
75
76
|
*/
|
|
76
77
|
export declare class SessionTouch {
|
|
77
78
|
private diagnostics;
|