@utk09/ui-observability 0.8.0 → 0.9.1
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 +95 -0
- package/README.md +75 -48
- package/dist/batch-DEK4bv9N.js +31 -0
- package/dist/batch-DEK4bv9N.js.map +1 -0
- package/dist/batch-DEVFs28i.cjs +2 -0
- package/dist/batch-DEVFs28i.cjs.map +1 -0
- package/dist/bus/bus.d.ts +46 -12
- package/dist/bus/links.d.ts +6 -3
- package/dist/bus-DNFvTkif.cjs +2 -0
- package/dist/bus-DNFvTkif.cjs.map +1 -0
- package/dist/{bus-DPDrlUBY.js → bus-HVQ8E72V.js} +128 -71
- package/dist/bus-HVQ8E72V.js.map +1 -0
- package/dist/capture/interactions.d.ts +7 -6
- package/dist/capture/network.d.ts +23 -9
- package/dist/capture/types.d.ts +3 -3
- package/dist/console-C9Y639mn.js +82 -0
- package/dist/console-C9Y639mn.js.map +1 -0
- package/dist/console-DssDxq1B.cjs +2 -0
- package/dist/console-DssDxq1B.cjs.map +1 -0
- package/dist/constants-N99w84xy.js +117 -0
- package/dist/constants-N99w84xy.js.map +1 -0
- package/dist/constants-X86IDwkC.cjs +2 -0
- package/dist/constants-X86IDwkC.cjs.map +1 -0
- package/dist/constants.d.ts +36 -18
- package/dist/core/diagnostics.d.ts +2 -2
- package/dist/core/drops.d.ts +29 -0
- package/dist/core/hold-buffer.d.ts +27 -0
- package/dist/core/journey.d.ts +16 -4
- package/dist/core/logger.d.ts +6 -2
- package/dist/core/pipeline.d.ts +20 -16
- package/dist/core/record.d.ts +11 -6
- package/dist/core/remote-sampling.d.ts +1 -1
- package/dist/core/runtime.d.ts +87 -23
- package/dist/core/sender.d.ts +19 -11
- 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/error-like-Ywo5uRHo.js +19 -0
- package/dist/error-like-Ywo5uRHo.js.map +1 -0
- package/dist/error-like-gGRx2s36.cjs +2 -0
- package/dist/error-like-gGRx2s36.cjs.map +1 -0
- package/dist/errors-BTWuVnHZ.cjs +3 -0
- package/dist/errors-BTWuVnHZ.cjs.map +1 -0
- package/dist/{errors-Dnc-X4Ec.js → errors-CQusIGWJ.js} +39 -20
- package/dist/errors-CQusIGWJ.js.map +1 -0
- package/dist/global-scope-BN-Io_yv.cjs.map +1 -1
- package/dist/global-scope-dp2jADRl.js.map +1 -1
- package/dist/identity-B1GDS1Tb.cjs +2 -0
- package/dist/identity-B1GDS1Tb.cjs.map +1 -0
- package/dist/identity-D4DPjTM9.js +88 -0
- package/dist/identity-D4DPjTM9.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -4
- package/dist/index.js +720 -446
- package/dist/index.js.map +1 -1
- package/dist/{indexeddb-storage-uD4oaRMc.js → indexeddb-storage-B8SGUzSV.js} +88 -59
- package/dist/indexeddb-storage-B8SGUzSV.js.map +1 -0
- package/dist/indexeddb-storage-ukzC82dm.cjs +2 -0
- package/dist/indexeddb-storage-ukzC82dm.cjs.map +1 -0
- package/dist/interactions-CcxrVzpg.cjs +2 -0
- package/dist/interactions-CcxrVzpg.cjs.map +1 -0
- package/dist/{interactions-igKTAJvj.js → interactions-CnjfQgw3.js} +22 -19
- package/dist/interactions-CnjfQgw3.js.map +1 -0
- package/dist/journey-DjvDzHyp.js +163 -0
- package/dist/journey-DjvDzHyp.js.map +1 -0
- package/dist/journey-DxlfdFJV.cjs +2 -0
- package/dist/journey-DxlfdFJV.cjs.map +1 -0
- package/dist/{library-request-Br_T09Bn.cjs → library-request-BZ1ekVtl.cjs} +2 -2
- package/dist/{library-request-Br_T09Bn.cjs.map → library-request-BZ1ekVtl.cjs.map} +1 -1
- package/dist/{library-request-Dt0fXhcn.js → library-request-C8kc5YWv.js} +2 -2
- package/dist/{library-request-Dt0fXhcn.js.map → library-request-C8kc5YWv.js.map} +1 -1
- package/dist/{long-frames-DahhqM6u.cjs → long-frames-BGik_Yhy.cjs} +2 -2
- package/dist/{long-frames-DahhqM6u.cjs.map → long-frames-BGik_Yhy.cjs.map} +1 -1
- package/dist/{long-frames-6pnjWSSR.js → long-frames-CZk3XOkH.js} +3 -3
- package/dist/{long-frames-6pnjWSSR.js.map → long-frames-CZk3XOkH.js.map} +1 -1
- package/dist/models/batch.d.ts +15 -1
- package/dist/models/bus.d.ts +7 -4
- package/dist/models/config.d.ts +189 -12
- package/dist/models/drop.d.ts +39 -0
- package/dist/models/log-record.d.ts +12 -6
- package/dist/models/storage.d.ts +15 -3
- package/dist/network-51iicpLl.js +174 -0
- package/dist/network-51iicpLl.js.map +1 -0
- package/dist/network-jBbjyAJP.cjs +2 -0
- package/dist/network-jBbjyAJP.cjs.map +1 -0
- package/dist/patch-BX8KrPCT.cjs +2 -0
- package/dist/patch-BX8KrPCT.cjs.map +1 -0
- package/dist/patch-CCWfuEY7.js +9 -0
- package/dist/patch-CCWfuEY7.js.map +1 -0
- package/dist/platform-Cjts-8k8.js +48 -0
- package/dist/platform-Cjts-8k8.js.map +1 -0
- package/dist/{platform-D_XkVIF6.cjs → platform-DW3GFIUE.cjs} +2 -2
- package/dist/platform-DW3GFIUE.cjs.map +1 -0
- package/dist/{remote-rules-rJJZKVG8.cjs → remote-rules-ByS34k4e.cjs} +2 -2
- package/dist/remote-rules-ByS34k4e.cjs.map +1 -0
- package/dist/{remote-rules-5UA23alm.js → remote-rules-M-XZ1xbe.js} +14 -14
- package/dist/remote-rules-M-XZ1xbe.js.map +1 -0
- package/dist/sampling-BN3Oi6SV.js +63 -0
- package/dist/sampling-BN3Oi6SV.js.map +1 -0
- package/dist/sampling-b2ck5X98.cjs +2 -0
- package/dist/sampling-b2ck5X98.cjs.map +1 -0
- package/dist/sanitize-DKp5MRsa.cjs +2 -0
- package/dist/sanitize-DKp5MRsa.cjs.map +1 -0
- package/dist/sanitize-Dwj9JCkI.js +123 -0
- package/dist/sanitize-Dwj9JCkI.js.map +1 -0
- package/dist/{sender-G6v4Uqi4.js → sender-BBY0IcUo.js} +439 -322
- package/dist/sender-BBY0IcUo.js.map +1 -0
- package/dist/sender-BXoAZKum.cjs +3 -0
- package/dist/sender-BXoAZKum.cjs.map +1 -0
- package/dist/storage/emergency-queue.d.ts +5 -2
- package/dist/storage/eviction.d.ts +40 -0
- package/dist/storage/factory.d.ts +1 -1
- package/dist/storage/idb-driver.d.ts +7 -1
- package/dist/storage/indexeddb-storage.d.ts +13 -5
- package/dist/storage/local-storage.d.ts +27 -4
- package/dist/storage/memory-storage.d.ts +10 -3
- package/dist/{storm-BtzgLOCX.cjs → storm-CKuaBp7i.cjs} +2 -2
- package/dist/{storm-BtzgLOCX.cjs.map → storm-CKuaBp7i.cjs.map} +1 -1
- package/dist/{storm-DJkEZP_8.js → storm-DhtL2eVr.js} +2 -2
- package/dist/{storm-DJkEZP_8.js.map → storm-DhtL2eVr.js.map} +1 -1
- package/dist/transport/compression.d.ts +1 -1
- package/dist/transport/exit-flush.d.ts +27 -17
- package/dist/transport/http-transport.d.ts +61 -7
- package/dist/transport/retry-engine.d.ts +12 -8
- package/dist/transport/status-transport.d.ts +8 -3
- package/dist/utils/console.d.ts +5 -2
- package/dist/utils/error-like.d.ts +25 -0
- package/dist/utils/global-scope.d.ts +1 -1
- package/dist/utils/identity.d.ts +1 -1
- package/dist/utils/library-console.d.ts +1 -1
- package/dist/utils/library-request.d.ts +1 -1
- package/dist/utils/patch.d.ts +9 -0
- package/dist/utils/platform.d.ts +3 -3
- package/dist/utils/sequence.d.ts +0 -5
- package/dist/utils/timer.d.ts +1 -1
- package/dist/utils/tracing.d.ts +3 -3
- package/dist/utils/unref.d.ts +2 -2
- package/dist/{web-vitals-DHZ0yA_H.js → web-vitals-Bflr5jSA.js} +4 -2
- package/dist/web-vitals-Bflr5jSA.js.map +1 -0
- package/dist/web-vitals-DFuoTQbZ.cjs +2 -0
- package/dist/web-vitals-DFuoTQbZ.cjs.map +1 -0
- package/package.json +2 -2
- package/dist/bus-CUXRY0JR.cjs +0 -2
- package/dist/bus-CUXRY0JR.cjs.map +0 -1
- package/dist/bus-DPDrlUBY.js.map +0 -1
- package/dist/console-CNljJict.js +0 -81
- package/dist/console-CNljJict.js.map +0 -1
- package/dist/console-PKzc-FmR.cjs +0 -2
- package/dist/console-PKzc-FmR.cjs.map +0 -1
- package/dist/constants-B28fDv2F.cjs +0 -2
- package/dist/constants-B28fDv2F.cjs.map +0 -1
- package/dist/constants-Bu49bm39.js +0 -93
- package/dist/constants-Bu49bm39.js.map +0 -1
- package/dist/errors-C78ZTjet.cjs +0 -3
- package/dist/errors-C78ZTjet.cjs.map +0 -1
- package/dist/errors-Dnc-X4Ec.js.map +0 -1
- package/dist/indexeddb-storage-D0p3iMD0.cjs +0 -2
- package/dist/indexeddb-storage-D0p3iMD0.cjs.map +0 -1
- package/dist/indexeddb-storage-uD4oaRMc.js.map +0 -1
- package/dist/interactions-CsE2y_fQ.cjs +0 -2
- package/dist/interactions-CsE2y_fQ.cjs.map +0 -1
- package/dist/interactions-igKTAJvj.js.map +0 -1
- package/dist/network-CZ0aFUsy.cjs +0 -2
- package/dist/network-CZ0aFUsy.cjs.map +0 -1
- package/dist/network-aSNbwpue.js +0 -112
- package/dist/network-aSNbwpue.js.map +0 -1
- package/dist/platform-BwbMRwHm.js +0 -48
- package/dist/platform-BwbMRwHm.js.map +0 -1
- package/dist/platform-D_XkVIF6.cjs.map +0 -1
- package/dist/remote-rules-5UA23alm.js.map +0 -1
- package/dist/remote-rules-rJJZKVG8.cjs.map +0 -1
- package/dist/sampling-E4x92Nn2.cjs +0 -2
- package/dist/sampling-E4x92Nn2.cjs.map +0 -1
- package/dist/sampling-J1eahbfT.js +0 -160
- package/dist/sampling-J1eahbfT.js.map +0 -1
- package/dist/sanitize-BMhh8ghJ.cjs +0 -2
- package/dist/sanitize-BMhh8ghJ.cjs.map +0 -1
- package/dist/sanitize-UJ-4Lb0n.js +0 -114
- package/dist/sanitize-UJ-4Lb0n.js.map +0 -1
- package/dist/sender-B6ufz26f.cjs +0 -3
- package/dist/sender-B6ufz26f.cjs.map +0 -1
- package/dist/sender-G6v4Uqi4.js.map +0 -1
- package/dist/unref-16maCyKA.js +0 -8
- package/dist/unref-16maCyKA.js.map +0 -1
- package/dist/unref-CU9Nyz_9.cjs +0 -2
- package/dist/unref-CU9Nyz_9.cjs.map +0 -1
- package/dist/web-vitals-B2FYsEAU.cjs +0 -2
- package/dist/web-vitals-B2FYsEAU.cjs.map +0 -1
- package/dist/web-vitals-DHZ0yA_H.js.map +0 -1
|
@@ -21,7 +21,7 @@ export declare class MemoryStorage implements StorageAdapter {
|
|
|
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
|
-
* @returns Promise
|
|
24
|
+
* @returns Promise that resolves to an array of batches.
|
|
25
25
|
*/
|
|
26
26
|
take(limit: number): Promise<LogBatch[]>;
|
|
27
27
|
/**
|
|
@@ -38,12 +38,19 @@ export declare class MemoryStorage implements StorageAdapter {
|
|
|
38
38
|
/**
|
|
39
39
|
* Removes expired batches. It then removes the oldest batches above the
|
|
40
40
|
* capacity limit.
|
|
41
|
-
* @returns Promise
|
|
41
|
+
* @returns Promise that resolves to prune summary metrics.
|
|
42
42
|
*/
|
|
43
43
|
prune(): Promise<PruneResult>;
|
|
44
|
+
/**
|
|
45
|
+
* Adds dropped batches to the prune result. It reports them with their own reason.
|
|
46
|
+
* @param result Prune result of all rules.
|
|
47
|
+
* @param reason Rule that dropped the batches.
|
|
48
|
+
* @param dropped The dropped batches.
|
|
49
|
+
*/
|
|
50
|
+
private report;
|
|
44
51
|
/**
|
|
45
52
|
* Returns the number of stored batches.
|
|
46
|
-
* @returns Promise
|
|
53
|
+
* @returns Promise that resolves to batch count.
|
|
47
54
|
*/
|
|
48
55
|
count(): Promise<number>;
|
|
49
56
|
/** This method deletes all stored batches. */
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./constants-
|
|
2
|
-
//# sourceMappingURL=storm-
|
|
1
|
+
const e=require("./constants-X86IDwkC.cjs");function t(t,n,r,i){let a=Date.now();return(a<t.start||a-t.start>1e4)&&(t.start=a,t.count=0),t.count++,t.count<=n||(r.report(`capture.rate_limited`,`More than ${String(n)} ${i} occurred in ${String(e.W)} ms. The library ignores the other ${i} in this window.`),!1)}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return t}});
|
|
2
|
+
//# sourceMappingURL=storm-CKuaBp7i.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storm-
|
|
1
|
+
{"version":3,"file":"storm-CKuaBp7i.cjs","names":["ERROR_STORM_WINDOW_MS","require_constants","allowInWindow","now","window","limit","diagnostics","what"],"sources":["../src/capture/storm.ts"],"sourcesContent":["// src/capture/storm.ts\n//\n// Fixed-window rate limit for the capture modules. A render loop that throws or freezes\n// makes thousands of events each second. Sending all of them floods the ingest endpoint.\n\nimport { ERROR_STORM_WINDOW_MS } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\n\n/** State of one fixed window. Captures that share a limit share one object. */\nexport interface StormWindow {\n /** Start of the current window, in epoch milliseconds. */\n start: number;\n /** Events counted in the current window. */\n count: number;\n}\n\n/**\n * Counts one event in a fixed window. It reports each event over the limit.\n * @param window Window state to change.\n * @param limit Maximum events in each window.\n * @param diagnostics Diagnostics reporter.\n * @param what Plural name of the events, for the diagnostic message.\n * @returns False when the window has no allowance left. The caller must drop the event.\n */\nexport function allowInWindow(\n window: StormWindow,\n limit: number,\n diagnostics: Diagnostics,\n what: string,\n): boolean {\n const now = Date.now();\n\n // Guard against a clock that moves back. The window then never ends.\n if (now < window.start || now - window.start > ERROR_STORM_WINDOW_MS) {\n window.start = now;\n window.count = 0;\n }\n\n window.count++;\n\n if (window.count <= limit) {\n return true;\n }\n\n diagnostics.report(\n \"capture.rate_limited\",\n `More than ${String(limit)} ${what} occurred in ${String(ERROR_STORM_WINDOW_MS)} ms. The library ignores the other ${what} in this window.`,\n );\n return false;\n}\n"],"mappings":"4CAwBA,SAAgBE,EACd,EACA,EACA,EACA,EACS,CACT,IAAMC,EAAM,KAAK,IAAI,EAkBrB,OAfIA,EAAMC,EAAO,OAASD,EAAMC,EAAO,MAAA,OACrC,EAAO,MAAQD,EACf,EAAO,MAAQ,GAGjB,EAAO,QAEHC,EAAO,OAASC,IAIpBC,EAAY,OACV,uBACA,aAAa,OAAOD,CAAK,EAAE,GAAGE,EAAK,eAAe,OAAOP,EAAAA,CAAqB,EAAE,qCAAqCO,EAAK,iBAC5H,EACO,GACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { W as e } from "./constants-N99w84xy.js";
|
|
2
2
|
//#region src/capture/storm.ts
|
|
3
3
|
function t(t, n, r, i) {
|
|
4
4
|
let a = Date.now();
|
|
@@ -7,4 +7,4 @@ function t(t, n, r, i) {
|
|
|
7
7
|
//#endregion
|
|
8
8
|
export { t };
|
|
9
9
|
|
|
10
|
-
//# sourceMappingURL=storm-
|
|
10
|
+
//# sourceMappingURL=storm-DhtL2eVr.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storm-
|
|
1
|
+
{"version":3,"file":"storm-DhtL2eVr.js","names":["ERROR_STORM_WINDOW_MS","allowInWindow","now","window","limit","diagnostics","what"],"sources":["../src/capture/storm.ts"],"sourcesContent":["// src/capture/storm.ts\n//\n// Fixed-window rate limit for the capture modules. A render loop that throws or freezes\n// makes thousands of events each second. Sending all of them floods the ingest endpoint.\n\nimport { ERROR_STORM_WINDOW_MS } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\n\n/** State of one fixed window. Captures that share a limit share one object. */\nexport interface StormWindow {\n /** Start of the current window, in epoch milliseconds. */\n start: number;\n /** Events counted in the current window. */\n count: number;\n}\n\n/**\n * Counts one event in a fixed window. It reports each event over the limit.\n * @param window Window state to change.\n * @param limit Maximum events in each window.\n * @param diagnostics Diagnostics reporter.\n * @param what Plural name of the events, for the diagnostic message.\n * @returns False when the window has no allowance left. The caller must drop the event.\n */\nexport function allowInWindow(\n window: StormWindow,\n limit: number,\n diagnostics: Diagnostics,\n what: string,\n): boolean {\n const now = Date.now();\n\n // Guard against a clock that moves back. The window then never ends.\n if (now < window.start || now - window.start > ERROR_STORM_WINDOW_MS) {\n window.start = now;\n window.count = 0;\n }\n\n window.count++;\n\n if (window.count <= limit) {\n return true;\n }\n\n diagnostics.report(\n \"capture.rate_limited\",\n `More than ${String(limit)} ${what} occurred in ${String(ERROR_STORM_WINDOW_MS)} ms. The library ignores the other ${what} in this window.`,\n );\n return false;\n}\n"],"mappings":";;AAwBA,SAAgBC,EACd,GACA,GACA,GACA,GACS;CACT,IAAMC,IAAM,KAAK,IAAI;CAkBrB,QAfIA,IAAMC,EAAO,SAASD,IAAMC,EAAO,QAAA,SACrC,EAAO,QAAQD,GACf,EAAO,QAAQ,IAGjB,EAAO,SAEHC,EAAO,SAASC,MAIpBC,EAAY,OACV,wBACA,aAAa,OAAOD,CAAK,EAAE,GAAGE,EAAK,eAAe,OAAON,CAAqB,EAAE,qCAAqCM,EAAK,iBAC5H,GACO;AACT"}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Compresses a string to gzip bytes with CompressionStream. The result is a
|
|
3
3
|
* Uint8Array on a non-shared ArrayBuffer. fetch accepts this result as BodyInit.
|
|
4
4
|
* @param text Raw serialized payload to compress.
|
|
5
|
-
* @returns Promise
|
|
5
|
+
* @returns Promise that resolves to the gzip bytes, or null without CompressionStream.
|
|
6
6
|
*/
|
|
7
7
|
export declare function gzip(text: string): Promise<Uint8Array<ArrayBuffer> | null>;
|
|
@@ -1,6 +1,7 @@
|
|
|
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
|
+
import type { LossReporter } from "../models/drop";
|
|
4
5
|
/** This type names the lifecycle event or manual action that starts an exit flush. */
|
|
5
6
|
export type ExitReason = "hidden" | "pagehide" | "freeze" | "openfin-close" | "shutdown";
|
|
6
7
|
/** This interface lists the dependencies of ExitFlush. */
|
|
@@ -11,8 +12,18 @@ export interface ExitFlushDeps {
|
|
|
11
12
|
diagnostics: Diagnostics;
|
|
12
13
|
/** This callback drains all buffered and unconfirmed batches into one LogBatch. */
|
|
13
14
|
drainForExit: () => LogBatch | null;
|
|
14
|
-
/**
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* This callback runs a normal flush with headers, gzip and retry. A hidden document uses it.
|
|
17
|
+
* It does not touch an in-flight batch.
|
|
18
|
+
*/
|
|
19
|
+
flushAlive: () => void | Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* This callback gives the headers that the HTTP transport sent last, or undefined.
|
|
22
|
+
* sendBeacon cannot set a header. With headers, the exit flush uses a keepalive fetch.
|
|
23
|
+
*/
|
|
24
|
+
exitHeaders: () => Record<string, string> | undefined;
|
|
25
|
+
/** This callback receives the records that the exit flush loses. */
|
|
26
|
+
onLoss?: LossReporter;
|
|
16
27
|
}
|
|
17
28
|
/**
|
|
18
29
|
* This class flushes pending telemetry on document unload. It uses sendBeacon, a keepalive
|
|
@@ -20,7 +31,7 @@ export interface ExitFlushDeps {
|
|
|
20
31
|
*/
|
|
21
32
|
export declare class ExitFlush {
|
|
22
33
|
private readonly deps;
|
|
23
|
-
/** This flag is true while the
|
|
34
|
+
/** This flag is true while the library listens for the unload events. */
|
|
24
35
|
private installed;
|
|
25
36
|
/** This listener flushes on visibilitychange when the document becomes hidden. */
|
|
26
37
|
private readonly onVisibility;
|
|
@@ -40,34 +51,28 @@ export declare class ExitFlush {
|
|
|
40
51
|
uninstall(): void;
|
|
41
52
|
/**
|
|
42
53
|
* Drains pending records synchronously. It sends them with a beacon, a
|
|
43
|
-
* keepalive fetch or emergency storage.
|
|
44
|
-
* unload listener.
|
|
45
|
-
* @param reason
|
|
54
|
+
* keepalive fetch or emergency storage. A hidden document gets a normal flush. It never
|
|
55
|
+
* awaits and never throws. The caller is an unload listener.
|
|
56
|
+
* @param reason Reason code of the flush.
|
|
46
57
|
*/
|
|
47
58
|
flush(reason: ExitReason): void;
|
|
59
|
+
/** Runs the normal flush of a hidden document. It reports a flush that throws or rejects. */
|
|
60
|
+
private flushAlive;
|
|
48
61
|
/**
|
|
49
62
|
* Gives the pending records to the exit hook of a custom transport. A page that closes cannot
|
|
50
63
|
* wait for the async transport. Without a hook, or when the hook refuses the batch, the batch
|
|
51
64
|
* goes to the emergency queue. The next page load sends it.
|
|
52
|
-
* @param reason
|
|
65
|
+
* @param reason Reason code of the flush.
|
|
53
66
|
* @param onExit Synchronous exit hook of the custom transport.
|
|
54
67
|
*/
|
|
55
68
|
private flushCustom;
|
|
56
69
|
/**
|
|
57
70
|
* Serializes the exit batch. It reports a serializer that throws.
|
|
58
71
|
* @param batch Batch to serialize.
|
|
59
|
-
* @param reason
|
|
72
|
+
* @param reason Reason code of the flush.
|
|
60
73
|
* @returns The serialized batch, or undefined if the serializer threw.
|
|
61
74
|
*/
|
|
62
75
|
private serialize;
|
|
63
|
-
/**
|
|
64
|
-
* Selects the drain for the reason. `hidden` occurs at each tab switch. The
|
|
65
|
-
* document continues to run after it. A drain of the in-flight batch here sends it again
|
|
66
|
-
* with a new id. The server cannot deduplicate that second send.
|
|
67
|
-
* @param reason Trigger reason code.
|
|
68
|
-
* @returns Combined LogBatch, or null if no records are pending.
|
|
69
|
-
*/
|
|
70
|
-
private drain;
|
|
71
76
|
/**
|
|
72
77
|
* Parses the configured endpoint URL.
|
|
73
78
|
* @returns URL instance or null if missing or invalid.
|
|
@@ -83,9 +88,14 @@ export declare class ExitFlush {
|
|
|
83
88
|
/**
|
|
84
89
|
* Sends a fallback POST with fetch and `keepalive: true`. A keepalive request
|
|
85
90
|
* continues after the document closes. The browser cancels a plain fetch at page close.
|
|
91
|
+
* A failed fetch parks the batch in the emergency queue. The server drops a second copy by
|
|
92
|
+
* its batch id.
|
|
86
93
|
* @param url Target endpoint URL.
|
|
94
|
+
* @param batch Batch in the payload.
|
|
87
95
|
* @param body Serialized payload string.
|
|
88
|
-
* @param reason
|
|
96
|
+
* @param reason Reason code of the flush.
|
|
97
|
+
* @param headers Builds the request headers. Without custom headers, only a text/plain
|
|
98
|
+
* content type. A header value outside ISO-8859-1 makes the Headers constructor throw.
|
|
89
99
|
*/
|
|
90
100
|
private keepaliveFetch;
|
|
91
101
|
}
|
|
@@ -5,25 +5,68 @@ import { StatusTransport } from "./status-transport";
|
|
|
5
5
|
* compression and classifies errors.
|
|
6
6
|
*/
|
|
7
7
|
export declare class HttpTransport extends StatusTransport {
|
|
8
|
+
/**
|
|
9
|
+
* Headers that the headers() function gave last. The exit flush sends them only while that
|
|
10
|
+
* function and the endpoint are in force. A tenant switch must not send the old token to the
|
|
11
|
+
* new endpoint.
|
|
12
|
+
*/
|
|
13
|
+
private cachedHeaders;
|
|
8
14
|
/**
|
|
9
15
|
* Sends one log batch over HTTP.
|
|
10
16
|
* @param batch Batch to send.
|
|
17
|
+
* @param onKeepalive Runs when a request of the batch starts with keepalive.
|
|
11
18
|
* @throws TransportError on transient, throttled, 413, or permanent network failures.
|
|
12
19
|
*/
|
|
13
|
-
send(batch: LogBatch): Promise<void>;
|
|
20
|
+
send(batch: LogBatch, onKeepalive?: () => void): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Gives the headers for the exit flush. A closing document cannot await headers().
|
|
23
|
+
* @returns The static headers, the headers that the function in force gave last, or undefined.
|
|
24
|
+
*/
|
|
25
|
+
lastHeaders(): Record<string, string> | undefined;
|
|
14
26
|
/**
|
|
15
27
|
* Serializes, encodes and sends a batch. It throws a classified TransportError
|
|
16
28
|
* on failure.
|
|
17
29
|
* @param batch Batch to deliver.
|
|
18
30
|
* @param endpoint Ingest URL. The caller reads it one time. A reconfigure during the send
|
|
19
31
|
* cannot change it.
|
|
32
|
+
* @param onKeepalive Runs when a request of the batch starts with keepalive.
|
|
20
33
|
*/
|
|
21
34
|
private post;
|
|
22
35
|
/**
|
|
23
|
-
*
|
|
36
|
+
* Tests if a status rejects the credentials.
|
|
37
|
+
* @param status HTTP status code.
|
|
38
|
+
* @returns True for 401 and 403.
|
|
39
|
+
*/
|
|
40
|
+
private rejectsCredentials;
|
|
41
|
+
/**
|
|
42
|
+
* Resolves the headers, encodes the body and sends one request. One deadline covers the
|
|
43
|
+
* three steps. Without it, a headers() that never settles holds a dispatch slot forever.
|
|
44
|
+
* @param batch Batch to deliver.
|
|
45
|
+
* @param endpoint Ingest URL.
|
|
46
|
+
* @param serialized Serialized batch.
|
|
47
|
+
* @param onKeepalive Runs when the request starts with keepalive.
|
|
48
|
+
* @returns Promise that resolves to the HTTP Response.
|
|
49
|
+
* @throws TransportError on timeout or network failure.
|
|
50
|
+
*/
|
|
51
|
+
private attempt;
|
|
52
|
+
/**
|
|
53
|
+
* Waits for a step until the deadline.
|
|
54
|
+
* @param work Step to wait for. It does not reject. Only the deadline rejects here.
|
|
55
|
+
* @param deadline Epoch time in milliseconds at which the request times out.
|
|
56
|
+
* @returns Promise that resolves to the value of the step.
|
|
57
|
+
* @throws TransportError of kind "timeout" at the deadline.
|
|
58
|
+
*/
|
|
59
|
+
private before;
|
|
60
|
+
/**
|
|
61
|
+
* Reports a timeout and builds its error.
|
|
62
|
+
* @returns TransportError of kind "timeout".
|
|
63
|
+
*/
|
|
64
|
+
private timeout;
|
|
65
|
+
/**
|
|
66
|
+
* Compresses the serialized payload when the config sets gzip. The payload size must
|
|
24
67
|
* be at or above the threshold.
|
|
25
68
|
* @param text Serialized payload string.
|
|
26
|
-
* @returns Promise
|
|
69
|
+
* @returns Promise that resolves to original string or compressed byte array.
|
|
27
70
|
*/
|
|
28
71
|
private encodeBody;
|
|
29
72
|
/**
|
|
@@ -32,19 +75,30 @@ export declare class HttpTransport extends StatusTransport {
|
|
|
32
75
|
* @param endpoint Ingest URL.
|
|
33
76
|
* @param headers HTTP request headers.
|
|
34
77
|
* @param body Request body string or byte array.
|
|
35
|
-
* @
|
|
78
|
+
* @param deadline Epoch time in milliseconds at which the request times out.
|
|
79
|
+
* @param keepalive True if the request continues after unload.
|
|
80
|
+
* @returns Promise that resolves to the HTTP Response.
|
|
36
81
|
* @throws TransportError on network failure, timeout, or offline status.
|
|
37
82
|
*/
|
|
38
83
|
private dispatch;
|
|
84
|
+
/**
|
|
85
|
+
* Tests if a send uses keepalive. A mobile OS can stop a hidden page with no pagehide.
|
|
86
|
+
* A keepalive request continues after that. The browser limits the keepalive bodies in flight.
|
|
87
|
+
* @param body Request body string or byte array.
|
|
88
|
+
* @returns True for a hidden document and a body of BEACON_LIMIT_BYTES or less.
|
|
89
|
+
*/
|
|
90
|
+
private keepalive;
|
|
39
91
|
/**
|
|
40
92
|
* Reads the optional maxBytes limit from a 413 response body.
|
|
41
93
|
* @param response HTTP 413 Response instance.
|
|
42
|
-
* @returns Promise
|
|
94
|
+
* @returns Promise that resolves to maximum byte limit or undefined.
|
|
43
95
|
*/
|
|
44
96
|
private readMaxBytes;
|
|
45
97
|
/**
|
|
46
|
-
* Resolves the configured static or dynamic request headers.
|
|
47
|
-
*
|
|
98
|
+
* Resolves the configured static or dynamic request headers. It keeps the headers that
|
|
99
|
+
* headers() gave, for the exit flush.
|
|
100
|
+
* @param endpoint Ingest URL of the send.
|
|
101
|
+
* @returns Promise that resolves to resolved header map.
|
|
48
102
|
*/
|
|
49
103
|
private resolveHeaders;
|
|
50
104
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
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
|
-
import type {
|
|
4
|
+
import type { LossReporter } from "../models/drop";
|
|
5
|
+
import { type StorageAdapter } from "../models/storage";
|
|
5
6
|
import type { BatchTransport } from "./status-transport";
|
|
6
7
|
/**
|
|
7
8
|
* This class sends persisted offline batches again on a timer. It uses backoff, a cross-tab
|
|
@@ -11,16 +12,18 @@ export declare class RetryEngine {
|
|
|
11
12
|
private readonly storage;
|
|
12
13
|
private readonly transport;
|
|
13
14
|
private readonly diagnostics;
|
|
14
|
-
private readonly config;
|
|
15
15
|
private readonly batchesPerDrain;
|
|
16
|
-
|
|
16
|
+
private readonly onLoss;
|
|
17
|
+
/** This field holds the active retry timer handle. It is null when no timer runs. */
|
|
17
18
|
private timer;
|
|
18
19
|
/** This field counts consecutive failed deliveries. The backoff calculation uses it. */
|
|
19
20
|
private attempt;
|
|
20
21
|
/** This flag is true while a storage drain runs. */
|
|
21
22
|
private draining;
|
|
22
|
-
/** This flag is true
|
|
23
|
+
/** This flag is true after stop(). */
|
|
23
24
|
private stopped;
|
|
25
|
+
/** Attempt limit of a stored batch. Retention cannot change after the delivery stack loads. */
|
|
26
|
+
private readonly maxAttempts;
|
|
24
27
|
/** This listener runs on the online event. It resets the attempt count and starts a drain. */
|
|
25
28
|
private readonly onOnline;
|
|
26
29
|
/**
|
|
@@ -29,8 +32,9 @@ export declare class RetryEngine {
|
|
|
29
32
|
* @param diagnostics Diagnostics reporter.
|
|
30
33
|
* @param config Active configuration instance.
|
|
31
34
|
* @param batchesPerDrain Maximum batches processed per drain tick.
|
|
35
|
+
* @param onLoss Receives the records of each batch that the engine drops.
|
|
32
36
|
*/
|
|
33
|
-
constructor(storage: StorageAdapter, transport: BatchTransport, diagnostics: Diagnostics, config: ResolvedConfig, batchesPerDrain?: number);
|
|
37
|
+
constructor(storage: StorageAdapter, transport: BatchTransport, diagnostics: Diagnostics, config: ResolvedConfig, batchesPerDrain?: number, onLoss?: LossReporter);
|
|
34
38
|
/** This method starts the engine. It listens for online events and arms the first timer. */
|
|
35
39
|
start(): void;
|
|
36
40
|
/** This method schedules an earlier retry when storage receives a new offline batch. */
|
|
@@ -71,12 +75,12 @@ export declare class RetryEngine {
|
|
|
71
75
|
/**
|
|
72
76
|
* Processes batches while it holds the Web Lock. It schedules the next tick.
|
|
73
77
|
* It always resolves. A throw leaves the engine idle with no armed timer.
|
|
74
|
-
* @returns Promise
|
|
78
|
+
* @returns Promise that resolves to true on completion.
|
|
75
79
|
*/
|
|
76
80
|
private drainLocked;
|
|
77
81
|
/**
|
|
78
|
-
* Tries to deliver one batch. It removes the batch on success.
|
|
79
|
-
*
|
|
82
|
+
* Tries to deliver one batch. It removes the batch on success. On failure, it applies the
|
|
83
|
+
* rule for the failure kind.
|
|
80
84
|
* @param batch Log batch to deliver.
|
|
81
85
|
* @returns True to continue with the next batch. False to stop the current drain.
|
|
82
86
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
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
|
+
import type { LossReporter } from "../models/drop";
|
|
4
5
|
import type { SerializedBatch } from "../models/serializer";
|
|
5
6
|
import { TransportError } from "./errors";
|
|
6
7
|
/** The two operations that the pipeline and the retry engine use. */
|
|
@@ -8,9 +9,10 @@ export interface BatchTransport {
|
|
|
8
9
|
/**
|
|
9
10
|
* Sends one batch.
|
|
10
11
|
* @param batch Batch to send.
|
|
12
|
+
* @param onKeepalive Runs when a request of the batch starts with keepalive.
|
|
11
13
|
* @throws TransportError when the batch is not accepted.
|
|
12
14
|
*/
|
|
13
|
-
send(batch: LogBatch): Promise<void>;
|
|
15
|
+
send(batch: LogBatch, onKeepalive?: () => void): Promise<void>;
|
|
14
16
|
/**
|
|
15
17
|
* Returns the remaining throttle delay.
|
|
16
18
|
* @returns Milliseconds until the throttle ends, or 0.
|
|
@@ -31,20 +33,23 @@ export declare abstract class StatusTransport implements BatchTransport {
|
|
|
31
33
|
protected readonly config: ResolvedConfig;
|
|
32
34
|
protected readonly diagnostics: Diagnostics;
|
|
33
35
|
private readonly onSampling;
|
|
36
|
+
private readonly onLoss;
|
|
34
37
|
/** Epoch time in milliseconds when the server throttle ends. */
|
|
35
38
|
private throttledUntil;
|
|
36
39
|
/**
|
|
37
40
|
* @param config Active configuration instance.
|
|
38
41
|
* @param diagnostics Diagnostics reporter.
|
|
39
42
|
* @param onSampling Receives the sampling rules of an accepted batch, before validation.
|
|
43
|
+
* @param onLoss Receives the records of a batch that the serializer cannot encode.
|
|
40
44
|
*/
|
|
41
|
-
constructor(config: ResolvedConfig, diagnostics: Diagnostics, onSampling?: (raw: unknown) => void);
|
|
45
|
+
constructor(config: ResolvedConfig, diagnostics: Diagnostics, onSampling?: (raw: unknown) => void, onLoss?: LossReporter);
|
|
42
46
|
/**
|
|
43
47
|
* Sends one batch.
|
|
44
48
|
* @param batch Batch to send.
|
|
49
|
+
* @param onKeepalive Runs when a request of the batch starts with keepalive.
|
|
45
50
|
* @throws TransportError when the batch is not accepted.
|
|
46
51
|
*/
|
|
47
|
-
abstract send(batch: LogBatch): Promise<void>;
|
|
52
|
+
abstract send(batch: LogBatch, onKeepalive?: () => void): Promise<void>;
|
|
48
53
|
/**
|
|
49
54
|
* Returns the remaining throttle delay in milliseconds.
|
|
50
55
|
* @returns Milliseconds remaining in throttle window, or 0 if unthrottled.
|
package/dist/utils/console.d.ts
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import type { Diagnostics } from "../core/diagnostics";
|
|
2
2
|
import type { ResolvedConsole } from "../models/config";
|
|
3
3
|
import type { LogLevel } from "../models/log-record";
|
|
4
|
+
import { type SanitizeLimits } from "./sanitize";
|
|
4
5
|
/** Mirrors log records directly to browser or Node console methods based on severity. */
|
|
5
6
|
export declare class ConsoleSink {
|
|
6
7
|
private settings;
|
|
7
8
|
private diagnostics;
|
|
9
|
+
private readonly limits;
|
|
8
10
|
/**
|
|
9
11
|
* @param settings Console level and styles. A null level prints nothing.
|
|
10
12
|
* @param diagnostics Diagnostics reporter.
|
|
13
|
+
* @param limits Size limits of the printed payload. They are the record limits.
|
|
11
14
|
*/
|
|
12
|
-
constructor(settings: ResolvedConsole, diagnostics: Diagnostics);
|
|
15
|
+
constructor(settings: ResolvedConsole, diagnostics: Diagnostics, limits?: SanitizeLimits);
|
|
13
16
|
/**
|
|
14
17
|
* Replaces the console level and styles.
|
|
15
18
|
* @param settings Console level and styles. A null level prints nothing.
|
|
16
19
|
*/
|
|
17
20
|
update(settings: ResolvedConsole): void;
|
|
18
21
|
/**
|
|
19
|
-
* Tests
|
|
22
|
+
* Tests if a level clears the console threshold.
|
|
20
23
|
* @param level Severity level of the record.
|
|
21
24
|
* @returns True if the sink prints this level.
|
|
22
25
|
*/
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Standard fields of an error. The library writes the other own fields as error data. */
|
|
2
|
+
export declare const ERROR_OWN_KEYS: ReadonlySet<string>;
|
|
3
|
+
/**
|
|
4
|
+
* Tests if a value is a field that error data keeps. An object field, for example the
|
|
5
|
+
* config of an AxiosError, holds credentials and request bodies.
|
|
6
|
+
* @param value Field value.
|
|
7
|
+
* @returns True for a string, a number or a boolean.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isDataField(value: unknown): boolean;
|
|
10
|
+
/** The fields of an error that the library reads. */
|
|
11
|
+
export interface ErrorLike {
|
|
12
|
+
/** Error class name, for example "TypeError". */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Error message. */
|
|
15
|
+
message: string;
|
|
16
|
+
/** Stack trace text. */
|
|
17
|
+
stack?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Tests if a value has the shape of an error.
|
|
21
|
+
* A getter on a hostile value can throw. Call this function inside a diagnostics guard.
|
|
22
|
+
* @param value Value to test.
|
|
23
|
+
* @returns True for an object with a string name, a string message and a string or no stack.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isErrorLike(value: unknown): value is ErrorLike;
|
package/dist/utils/identity.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ 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
|
-
* It uses crypto.getRandomValues when it is available.
|
|
47
|
+
* It uses crypto.getRandomValues when it is available. If not, 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
|
*/
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export declare function runAsLibraryConsole<T>(fn: () => T): T;
|
|
7
7
|
/**
|
|
8
|
-
* Tests
|
|
8
|
+
* Tests if a library console scope is open.
|
|
9
9
|
* @returns True while the library writes to the console.
|
|
10
10
|
*/
|
|
11
11
|
export declare function isLibraryConsole(): boolean;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export declare function runAsLibraryRequest<T>(fn: () => T): T;
|
|
8
8
|
/**
|
|
9
|
-
* Tests
|
|
9
|
+
* Tests if a library request scope is open.
|
|
10
10
|
* @returns True while the library starts a request.
|
|
11
11
|
*/
|
|
12
12
|
export declare function isLibraryRequest(): boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replaces `target[key]` with a wrapper of the current value.
|
|
3
|
+
* @param target Object that holds the function, for example `console` or `globalThis`.
|
|
4
|
+
* @param key Property to replace.
|
|
5
|
+
* @param wrap Makes the wrapper from the original value.
|
|
6
|
+
* @returns Restore function. It writes the original back only if the property still holds
|
|
7
|
+
* the wrapper. It then returns true. If not, it changes nothing. It returns false.
|
|
8
|
+
*/
|
|
9
|
+
export declare function patch<T extends object, K extends keyof T>(target: T, key: K, wrap: (original: T[K]) => T[K]): () => boolean;
|
package/dist/utils/platform.d.ts
CHANGED
|
@@ -11,9 +11,9 @@ export interface PlatformMetadata {
|
|
|
11
11
|
openfinName?: string;
|
|
12
12
|
/** Raw navigator user agent string or empty string if unavailable. */
|
|
13
13
|
userAgent: string;
|
|
14
|
-
/**
|
|
14
|
+
/** True if the code runs in a worker realm. */
|
|
15
15
|
isWorker: boolean;
|
|
16
|
-
/**
|
|
16
|
+
/** True if this context is the top-level document rather than an iframe. */
|
|
17
17
|
isTopLevelDocument: boolean;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -23,7 +23,7 @@ export interface PlatformMetadata {
|
|
|
23
23
|
*/
|
|
24
24
|
export declare function detectPlatform(diagnostics: Diagnostics): PlatformMetadata;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Tests if the current window is the top-level browsing context.
|
|
27
27
|
* @param diagnostics Diagnostics reporter. It counts a blocked read of window.top.
|
|
28
28
|
* @returns True if top-level, false if framed or inaccessible due to cross-origin boundaries.
|
|
29
29
|
*/
|
package/dist/utils/sequence.d.ts
CHANGED
|
@@ -7,9 +7,4 @@ export declare class Sequence {
|
|
|
7
7
|
* @returns Next sequence number.
|
|
8
8
|
*/
|
|
9
9
|
next(): number;
|
|
10
|
-
/**
|
|
11
|
-
* Resets the sequence counter to zero when the runtime gets a new configuration.
|
|
12
|
-
* A continued count shows a false link to the previous run.
|
|
13
|
-
*/
|
|
14
|
-
reset(): void;
|
|
15
10
|
}
|
package/dist/utils/timer.d.ts
CHANGED
|
@@ -14,6 +14,6 @@ export declare function timeSync<T>(logger: CaptureLogger, label: string, fn: ()
|
|
|
14
14
|
* @param label Metric name prefix.
|
|
15
15
|
* @param fn Asynchronous function to execute.
|
|
16
16
|
* @param attributes Optional contextual attributes.
|
|
17
|
-
* @returns Promise
|
|
17
|
+
* @returns Promise that resolves to the result of the wrapped function.
|
|
18
18
|
*/
|
|
19
19
|
export declare function timeAsync<T>(logger: CaptureLogger, label: string, fn: () => Promise<T>, attributes?: Record<string, unknown>): Promise<T>;
|
package/dist/utils/tracing.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface TraceContext {
|
|
|
9
9
|
/** Bitfield byte containing W3C trace flags. */
|
|
10
10
|
traceFlags: number;
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
12
|
+
/** Cause of a rotation of the ambient trace context. */
|
|
13
13
|
export type RotateReason = "start" | "interaction" | "navigation" | "explicit" | "maxAge";
|
|
14
14
|
/**
|
|
15
15
|
* Generates a random 32-character hex string in the W3C trace ID format.
|
|
@@ -45,7 +45,7 @@ export declare class TraceEngine {
|
|
|
45
45
|
/**
|
|
46
46
|
* Loads the OpenTelemetry API. Until the load completes, records use the ambient trace.
|
|
47
47
|
* If there is no loader or the load fails, all records use the ambient trace.
|
|
48
|
-
* @returns Promise
|
|
48
|
+
* @returns Promise that resolves when the attempt settles.
|
|
49
49
|
*/
|
|
50
50
|
loadOtel(): Promise<void>;
|
|
51
51
|
/**
|
|
@@ -54,7 +54,7 @@ export declare class TraceEngine {
|
|
|
54
54
|
*/
|
|
55
55
|
resolve(): TraceContext;
|
|
56
56
|
/**
|
|
57
|
-
* Reads the
|
|
57
|
+
* Reads the active span of the host if the peer module loaded and a span runs.
|
|
58
58
|
* @returns Trace context of the active span, or undefined.
|
|
59
59
|
*/
|
|
60
60
|
private activeSpanContext;
|
package/dist/utils/unref.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Timer handle. It is a number in a browser and a Timeout object in Node. */
|
|
2
2
|
export type TimerHandle = number | {
|
|
3
3
|
unref?: () => void;
|
|
4
4
|
};
|
|
5
5
|
/**
|
|
6
|
-
* Unreferences a timer handle
|
|
6
|
+
* Unreferences a timer handle. A pending timer then does not keep a Node.js process alive.
|
|
7
7
|
* @param timer Timer handle returned by setTimeout.
|
|
8
8
|
*/
|
|
9
9
|
export declare function unrefTimer(timer: TimerHandle): void;
|
|
@@ -9,7 +9,7 @@ var e = class {
|
|
|
9
9
|
install() {
|
|
10
10
|
if (this.installed || (this.installed = !0, this.reportNavigationTiming(), this.ctx.once.webVitals)) return;
|
|
11
11
|
let e = this.ctx.config.capture.webVitalsLoader;
|
|
12
|
-
e ?
|
|
12
|
+
e ? this.loadWebVitals(e) : this.ctx.diagnostics.report("config.invalid", "capture.webVitals needs capture.webVitalsLoader. LCP, CLS and INP are off. Navigation timing continues.");
|
|
13
13
|
}
|
|
14
14
|
uninstall() {
|
|
15
15
|
this.installed = !1;
|
|
@@ -20,6 +20,8 @@ var e = class {
|
|
|
20
20
|
this.ctx.diagnostics.report("capture.install_failed", "The web-vitals module is not available. LCP, CLS and INP are off. Navigation timing continues.");
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
+
if (this.ctx.once.webVitals) return;
|
|
24
|
+
this.ctx.once.webVitals = !0;
|
|
23
25
|
let n = (e, t) => (n) => {
|
|
24
26
|
this.ctx.logger.logMetric(`web_vitals.${e}`, Math.round(n.value * 1e3) / 1e3, t, "gauge", {
|
|
25
27
|
"metric.rating": n.rating,
|
|
@@ -48,4 +50,4 @@ var e = class {
|
|
|
48
50
|
//#endregion
|
|
49
51
|
export { e as WebVitalsCapture };
|
|
50
52
|
|
|
51
|
-
//# sourceMappingURL=web-vitals-
|
|
53
|
+
//# sourceMappingURL=web-vitals-Bflr5jSA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-vitals-Bflr5jSA.js","names":["WebVitalsCapture","ctx","loader","module","send","name","metric","unit","nav","metrics","value"],"sources":["../src/capture/web-vitals.ts"],"sourcesContent":["// src/capture/web-vitals.ts\n//\n// Captures browser navigation timing and Core Web Vitals metrics through an optional peer.\n\nimport type { WebVitalsMetric, WebVitalsModule, WebVitalsReporter } from \"../models/config\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Captures browser navigation timing benchmarks and Core Web Vitals. */\nexport class WebVitalsCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"web-vitals\";\n\n /** Prevents duplicate listener registration. */\n private installed = false;\n\n /**\n * @param ctx Capture context containing configuration, diagnostics, and logger.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Reports navigation timing and starts to load web-vitals. */\n install(): void {\n if (this.installed) {\n return;\n }\n this.installed = true;\n\n this.reportNavigationTiming();\n\n if (this.ctx.once.webVitals) {\n return;\n }\n\n // Do not import the peer by name. The Vite dev server fails if the peer is not installed.\n // Do not set `once` here. A later configure() call with a loader must subscribe.\n const loader = this.ctx.config.capture.webVitalsLoader;\n if (!loader) {\n this.ctx.diagnostics.report(\n \"config.invalid\",\n \"capture.webVitals needs capture.webVitalsLoader. LCP, CLS and INP are off. Navigation timing continues.\",\n );\n return;\n }\n\n // Set the flag after a successful load, not before. A failed load then gets a new\n // attempt on a later install.\n void this.loadWebVitals(loader);\n }\n\n /**\n * Marks the module as uninstalled. The web-vitals reporters stay subscribed\n * because the package has no unsubscribe. `ctx.once` prevents a second set.\n */\n uninstall(): void {\n this.installed = false;\n }\n\n /**\n * Loads the web-vitals module and registers metric reporters.\n * @param loader Loader that the consumer supplies.\n */\n private async loadWebVitals(loader: () => Promise<WebVitalsModule>): Promise<void> {\n const module = await this.ctx.diagnostics.guardAsync(\n \"capture.install_failed\",\n \"The library could not load web-vitals.\",\n loader,\n );\n\n if (!module) {\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The web-vitals module is not available. LCP, CLS and INP are off. Navigation timing continues.\",\n );\n return;\n }\n\n // Two installs in one turn both load the module. Only the first subscribes.\n // web-vitals has no unsubscribe, and a second set reports each metric two times.\n if (this.ctx.once.webVitals) {\n return;\n }\n this.ctx.once.webVitals = true;\n\n const send =\n (name: string, unit: string): WebVitalsReporter =>\n (metric: WebVitalsMetric): void => {\n this.ctx.logger.logMetric(\n `web_vitals.${name}`,\n // Keep three decimals. CLS is a small fraction. An integer value\n // reports each layout shift as zero.\n Math.round(metric.value * 1000) / 1000,\n unit,\n \"gauge\",\n { \"metric.rating\": metric.rating, \"metric.id\": metric.id },\n );\n };\n\n module.onLCP(send(\"lcp\", \"ms\"));\n module.onCLS(send(\"cls\", \"1\"));\n module.onINP(send(\"inp\", \"ms\"));\n module.onFCP(send(\"fcp\", \"ms\"));\n module.onTTFB(send(\"ttfb\", \"ms\"));\n }\n\n /** Extracts and logs PerformanceNavigationTiming benchmarks one time for each document. */\n private reportNavigationTiming(): void {\n // The entry describes the one navigation of this document. A second report after a\n // reconfigure duplicates the seven metrics.\n if (this.ctx.once.navigationTiming) {\n return;\n }\n this.ctx.once.navigationTiming = true;\n\n this.ctx.diagnostics.guard(\n \"capture.install_failed\",\n \"The library could not read the navigation timing.\",\n () => {\n const nav = performance.getEntriesByType(\"navigation\")[0] as\n PerformanceNavigationTiming | undefined;\n if (!nav) {\n return;\n }\n\n const metrics: Record<string, number> = {\n \"navigation.dns_ms\": nav.domainLookupEnd - nav.domainLookupStart,\n \"navigation.tcp_ms\": nav.connectEnd - nav.connectStart,\n \"navigation.ttfb_ms\": nav.responseStart - nav.requestStart,\n \"navigation.response_ms\": nav.responseEnd - nav.responseStart,\n \"navigation.dom_interactive_ms\": nav.domInteractive,\n \"navigation.dom_complete_ms\": nav.domComplete,\n \"navigation.load_ms\": nav.loadEventEnd,\n };\n\n for (const [name, value] of Object.entries(metrics)) {\n // Filters unrecorded or negative timings to avoid false zero readings.\n if (Number.isFinite(value) && value >= 0) {\n this.ctx.logger.logMetric(name, Math.round(value), \"ms\", \"gauge\", {\n \"navigation.type\": nav.type,\n });\n }\n }\n },\n );\n }\n}\n"],"mappings":";AAQA,IAAaA,IAAb,MAAiD;CAUlB;CAR7B,OAAgB;CAGhB,YAAoB;CAKpB,YAAY,GAAsC;EAArB,KAAA,MAAAC;CAAsB;CAGnD,UAAgB;EAQd,IAPI,KAAK,cAGT,KAAK,YAAY,IAEjB,KAAK,uBAAuB,GAExB,KAAK,IAAI,KAAK,YAChB;EAKF,IAAMC,IAAS,KAAK,IAAI,OAAO,QAAQ;EACvC,AAAKA,IAUL,KAAU,cAAcA,CAAM,IAT5B,KAAK,IAAI,YAAY,OACnB,kBACA,yGACF;CAOJ;CAMA,YAAkB;EAChB,KAAK,YAAY;CACnB;CAMA,MAAc,cAAc,GAAuD;EACjF,IAAMC,IAAS,MAAM,KAAK,IAAI,YAAY,WACxC,0BACA,0CACAD,CACF;EAEA,IAAI,CAACC,GAAQ;GACX,KAAK,IAAI,YAAY,OACnB,0BACA,gGACF;GACA;EACF;EAIA,IAAI,KAAK,IAAI,KAAK,WAChB;EAEF,KAAK,IAAI,KAAK,YAAY;EAE1B,IAAMC,KACH,GAAc,OACd,MAAkC;GACjC,KAAK,IAAI,OAAO,UACd,cAAcC,KAGd,KAAK,MAAMC,EAAO,QAAQ,GAAI,IAAI,KAClCC,GACA,SACA;IAAE,iBAAiBD,EAAO;IAAQ,aAAaA,EAAO;GAAG,CAC3D;EACF;EAMF,AAJAH,EAAO,MAAMC,EAAK,OAAO,IAAI,CAAC,GAC9BD,EAAO,MAAMC,EAAK,OAAO,GAAG,CAAC,GAC7BD,EAAO,MAAMC,EAAK,OAAO,IAAI,CAAC,GAC9BD,EAAO,MAAMC,EAAK,OAAO,IAAI,CAAC,GAC9BD,EAAO,OAAOC,EAAK,QAAQ,IAAI,CAAC;CAClC;CAGA,yBAAuC;EAGrC,AAAI,KAAK,IAAI,KAAK,qBAGlB,KAAK,IAAI,KAAK,mBAAmB,IAEjC,KAAK,IAAI,YAAY,MACnB,0BACA,2DACM;GACJ,IAAMI,IAAM,YAAY,iBAAiB,YAAY,CAAC,CAAC;GAEvD,IAAI,CAACA,GACH;GAGF,IAAMC,IAAkC;IACtC,qBAAqBD,EAAI,kBAAkBA,EAAI;IAC/C,qBAAqBA,EAAI,aAAaA,EAAI;IAC1C,sBAAsBA,EAAI,gBAAgBA,EAAI;IAC9C,0BAA0BA,EAAI,cAAcA,EAAI;IAChD,iCAAiCA,EAAI;IACrC,8BAA8BA,EAAI;IAClC,sBAAsBA,EAAI;GAC5B;GAEA,KAAK,IAAM,CAACH,GAAMK,MAAU,OAAO,QAAQD,CAAO,GAEhD,AAAI,OAAO,SAASC,CAAK,KAAKA,KAAS,KACrC,KAAK,IAAI,OAAO,UAAUL,GAAM,KAAK,MAAMK,CAAK,GAAG,MAAM,SAAS,EAChE,mBAAmBF,EAAI,KACzB,CAAC;EAGP,CACF;CACF;AACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=class{ctx;name=`web-vitals`;installed=!1;constructor(e){this.ctx=e}install(){if(this.installed||(this.installed=!0,this.reportNavigationTiming(),this.ctx.once.webVitals))return;let e=this.ctx.config.capture.webVitalsLoader;e?this.loadWebVitals(e):this.ctx.diagnostics.report(`config.invalid`,`capture.webVitals needs capture.webVitalsLoader. LCP, CLS and INP are off. Navigation timing continues.`)}uninstall(){this.installed=!1}async loadWebVitals(e){let t=await this.ctx.diagnostics.guardAsync(`capture.install_failed`,`The library could not load web-vitals.`,e);if(!t){this.ctx.diagnostics.report(`capture.install_failed`,`The web-vitals module is not available. LCP, CLS and INP are off. Navigation timing continues.`);return}if(this.ctx.once.webVitals)return;this.ctx.once.webVitals=!0;let n=(e,t)=>n=>{this.ctx.logger.logMetric(`web_vitals.${e}`,Math.round(n.value*1e3)/1e3,t,`gauge`,{"metric.rating":n.rating,"metric.id":n.id})};t.onLCP(n(`lcp`,`ms`)),t.onCLS(n(`cls`,`1`)),t.onINP(n(`inp`,`ms`)),t.onFCP(n(`fcp`,`ms`)),t.onTTFB(n(`ttfb`,`ms`))}reportNavigationTiming(){this.ctx.once.navigationTiming||(this.ctx.once.navigationTiming=!0,this.ctx.diagnostics.guard(`capture.install_failed`,`The library could not read the navigation timing.`,()=>{let e=performance.getEntriesByType(`navigation`)[0];if(!e)return;let t={"navigation.dns_ms":e.domainLookupEnd-e.domainLookupStart,"navigation.tcp_ms":e.connectEnd-e.connectStart,"navigation.ttfb_ms":e.responseStart-e.requestStart,"navigation.response_ms":e.responseEnd-e.responseStart,"navigation.dom_interactive_ms":e.domInteractive,"navigation.dom_complete_ms":e.domComplete,"navigation.load_ms":e.loadEventEnd};for(let[n,r]of Object.entries(t))Number.isFinite(r)&&r>=0&&this.ctx.logger.logMetric(n,Math.round(r),`ms`,`gauge`,{"navigation.type":e.type})}))}};exports.WebVitalsCapture=e;
|
|
2
|
+
//# sourceMappingURL=web-vitals-DFuoTQbZ.cjs.map
|