@utk09/ui-observability 0.9.4 → 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 +45 -0
- package/README.md +122 -94
- package/dist/batch-BQFtb3i5.cjs +2 -0
- package/dist/batch-BQFtb3i5.cjs.map +1 -0
- package/dist/{batch-D-4xl7op.js → batch-BUJh-1jZ.js} +7 -5
- 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/storm.d.ts +2 -1
- package/dist/capture/types.d.ts +2 -0
- package/dist/{console-Boqa7new.cjs → console-Ce6heqZZ.cjs} +2 -2
- package/dist/console-Ce6heqZZ.cjs.map +1 -0
- package/dist/{console-BT7mcgU6.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 +29 -9
- 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 +7 -2
- package/dist/core/context.d.ts +2 -0
- package/dist/core/diagnostics.d.ts +11 -3
- package/dist/core/meter.d.ts +6 -1
- package/dist/core/pipeline.d.ts +29 -2
- package/dist/core/record.d.ts +2 -1
- package/dist/core/runtime.d.ts +91 -3
- package/dist/core/sampling.d.ts +3 -1
- package/dist/core/sender.d.ts +35 -1
- package/dist/deadline-5_PecIl5.js +26 -0
- package/dist/deadline-5_PecIl5.js.map +1 -0
- package/dist/deadline-XSnm95pg.cjs +2 -0
- package/dist/deadline-XSnm95pg.cjs.map +1 -0
- package/dist/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-BDI96zKc.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 +45 -7
- package/dist/index.js +908 -529
- 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-HgkQUTyS.js → indexeddb-storage-CCA1LvtO.js} +33 -18
- package/dist/indexeddb-storage-CCA1LvtO.js.map +1 -0
- package/dist/{interactions-Ck01cEij.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-DRK0A8u_.js → journey-BUJ4WJxP.js} +12 -12
- package/dist/{journey-DRK0A8u_.js.map → journey-BUJ4WJxP.js.map} +1 -1
- package/dist/{journey-Co9OlzrW.cjs → journey-B_tTnvac.cjs} +2 -2
- package/dist/{journey-Co9OlzrW.cjs.map → journey-B_tTnvac.cjs.map} +1 -1
- 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-ChCar5F8.js → library-request-BKOcaKtQ.js} +2 -2
- package/dist/{library-request-ChCar5F8.js.map → library-request-BKOcaKtQ.js.map} +1 -1
- package/dist/{library-request-gMFOCNcn.cjs → library-request-BaZOi4eg.cjs} +2 -2
- package/dist/{library-request-gMFOCNcn.cjs.map → library-request-BaZOi4eg.cjs.map} +1 -1
- package/dist/{long-frames-Bky6nZDF.cjs → long-frames-CF3qiSAX.cjs} +2 -2
- package/dist/long-frames-CF3qiSAX.cjs.map +1 -0
- package/dist/{long-frames-DDumopji.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 +347 -9
- package/dist/models/drop.d.ts +1 -1
- package/dist/models/health.d.ts +27 -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-BsBZ6_-Q.js → network-DdzXDI3J.js} +18 -16
- 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-4yYjMD-B.js → platform-Bw1btWCT.js} +16 -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-1KqfVBIu.js → remote-rules-DIcC5vVC.js} +3 -3
- package/dist/{remote-rules-1KqfVBIu.js.map → remote-rules-DIcC5vVC.js.map} +1 -1
- package/dist/{remote-rules-BHgEGlYi.cjs → remote-rules-DpFmOef2.cjs} +2 -2
- package/dist/{remote-rules-BHgEGlYi.cjs.map → remote-rules-DpFmOef2.cjs.map} +1 -1
- package/dist/sampling-BVjspJWu.cjs +2 -0
- package/dist/sampling-BVjspJWu.cjs.map +1 -0
- package/dist/{sampling-nYIWP_vP.js → sampling-Cm3WhI0a.js} +26 -36
- package/dist/sampling-Cm3WhI0a.js.map +1 -0
- package/dist/{sanitize-BiUKCUG6.js → sanitize-C-ahCFsG.js} +2 -2
- package/dist/{sanitize-BiUKCUG6.js.map → sanitize-C-ahCFsG.js.map} +1 -1
- package/dist/{sanitize-BxuPSXOk.cjs → sanitize-DHucKGdi.cjs} +2 -2
- package/dist/{sanitize-BxuPSXOk.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/retry-engine.d.ts +7 -2
- package/dist/transport/status-transport.d.ts +17 -0
- package/dist/types-BR9t_w28.js.map +1 -1
- package/dist/types-C7WNpnG1.cjs.map +1 -1
- package/dist/utils/fixed-window.d.ts +9 -0
- package/dist/utils/identity.d.ts +9 -2
- package/dist/utils/lock.d.ts +8 -0
- package/dist/utils/openfin.d.ts +1 -1
- package/dist/utils/platform.d.ts +3 -1
- 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-C4oF6XZT.cjs +0 -2
- package/dist/batch-C4oF6XZT.cjs.map +0 -1
- package/dist/batch-D-4xl7op.js.map +0 -1
- package/dist/bus-Cyvq-Ngx.js +0 -478
- package/dist/bus-Cyvq-Ngx.js.map +0 -1
- package/dist/bus-rOhVuRee.cjs +0 -2
- package/dist/bus-rOhVuRee.cjs.map +0 -1
- package/dist/console-BT7mcgU6.js.map +0 -1
- package/dist/console-Boqa7new.cjs.map +0 -1
- package/dist/constants-BgRS6MB0.cjs +0 -2
- package/dist/constants-BgRS6MB0.cjs.map +0 -1
- package/dist/constants-L_d5YvvQ.js +0 -160
- package/dist/constants-L_d5YvvQ.js.map +0 -1
- package/dist/errors-BDI96zKc.js.map +0 -1
- package/dist/errors-_xEsCVXn.cjs +0 -3
- package/dist/errors-_xEsCVXn.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-Bwku7zzN.cjs +0 -2
- package/dist/identity-Bwku7zzN.cjs.map +0 -1
- package/dist/identity-Dtv917nz.js +0 -98
- package/dist/identity-Dtv917nz.js.map +0 -1
- package/dist/indexeddb-storage-Cvavrf-y.cjs +0 -2
- package/dist/indexeddb-storage-Cvavrf-y.cjs.map +0 -1
- package/dist/indexeddb-storage-HgkQUTyS.js.map +0 -1
- package/dist/interactions-Bhe1ft8P.cjs +0 -2
- package/dist/interactions-Bhe1ft8P.cjs.map +0 -1
- package/dist/interactions-Ck01cEij.js.map +0 -1
- package/dist/log-record-cwFiLyPY.js +0 -17
- package/dist/log-record-cwFiLyPY.js.map +0 -1
- package/dist/log-record-jX9eWUP8.cjs +0 -2
- package/dist/log-record-jX9eWUP8.cjs.map +0 -1
- package/dist/long-frames-Bky6nZDF.cjs.map +0 -1
- package/dist/long-frames-DDumopji.js.map +0 -1
- package/dist/network-BsBZ6_-Q.js.map +0 -1
- package/dist/network-_4csBGBM.cjs +0 -2
- package/dist/network-_4csBGBM.cjs.map +0 -1
- package/dist/platform-4yYjMD-B.js.map +0 -1
- package/dist/platform-o7r1ocOu.cjs +0 -2
- package/dist/platform-o7r1ocOu.cjs.map +0 -1
- package/dist/sampling-C4my-ma0.cjs +0 -2
- package/dist/sampling-C4my-ma0.cjs.map +0 -1
- package/dist/sampling-nYIWP_vP.js.map +0 -1
- package/dist/sender-6vrT9fFL.cjs +0 -3
- package/dist/sender-6vrT9fFL.cjs.map +0 -1
- package/dist/sender-DFQMF39P.js +0 -1351
- package/dist/sender-DFQMF39P.js.map +0 -1
- package/dist/storm-6YYbXzT_.cjs +0 -2
- package/dist/storm-6YYbXzT_.cjs.map +0 -1
- package/dist/storm-CfO0Sam2.js +0 -10
- package/dist/storm-CfO0Sam2.js.map +0 -1
- package/dist/web-socket-Ar4cZxmd.js +0 -102
- package/dist/web-socket-Ar4cZxmd.js.map +0 -1
- package/dist/web-socket-BwJdwSHl.cjs +0 -2
- package/dist/web-socket-BwJdwSHl.cjs.map +0 -1
|
@@ -24,6 +24,19 @@ export declare class MemoryStorage implements StorageAdapter {
|
|
|
24
24
|
* @returns Promise that resolves to an array of batches.
|
|
25
25
|
*/
|
|
26
26
|
take(limit: number): Promise<LogBatch[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Returns up to `limit` batches of one context in FIFO order. It does not delete them.
|
|
29
|
+
* @param id Delivery context id.
|
|
30
|
+
* @param limit Maximum number of batches to retrieve.
|
|
31
|
+
* @returns Promise that resolves to the batches of this context.
|
|
32
|
+
*/
|
|
33
|
+
takeContext(id: string, limit: number): Promise<LogBatch[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Counts the stored batches of one context.
|
|
36
|
+
* @param id Delivery context id.
|
|
37
|
+
* @returns Promise that resolves to the batch count of this context.
|
|
38
|
+
*/
|
|
39
|
+
countContext(id: string): Promise<number>;
|
|
27
40
|
/**
|
|
28
41
|
* Deletes the batch with the given ID.
|
|
29
42
|
* @param id Batch identifier.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-BA9RqRO-.cjs","names":["storageLimits","retention"],"sources":["../src/models/storage.ts"],"sourcesContent":["// src/models/storage.ts\n//\n// Storage interface for undelivered batches, with adapters for IndexedDB,\n// localStorage, memory, and a fallback that does nothing.\n\nimport type { LogBatch } from \"./batch\";\nimport type { RetentionOptions } from \"./config\";\n\n/** Persistent batch storage interface. All methods must resolve and never throw. */\nexport interface StorageAdapter {\n /** Adapter identifier name. */\n readonly name: string;\n\n /**\n * Persists a batch to storage.\n * @param batch The batch to store.\n */\n save(batch: LogBatch): Promise<void>;\n\n /**\n * Reads up to `limit` batches in FIFO order without removing them.\n * @param limit Maximum number of batches to retrieve.\n * @returns Oldest persisted batches.\n */\n take(limit: number): Promise<LogBatch[]>;\n /**\n * Reads batches of one context without loading batches of other contexts.\n * @param id Delivery context id.\n * @param limit Maximum batches to return.\n * @returns Batches of this context, oldest first.\n */\n takeContext?(id: string, limit: number): Promise<LogBatch[]>;\n /**\n * Counts batches of one context without loading them.\n * @param id Delivery context id.\n * @returns Number of batches in this context.\n */\n countContext?(id: string): Promise<number>;\n\n /**\n * Removes a batch by ID. A call with an unknown ID resolves without error.\n * @param id Batch identifier.\n */\n remove(id: string): Promise<void>;\n\n /**\n * Updates the total delivery attempts for a batch.\n * @param id Batch identifier.\n * @param attempts Absolute attempt count.\n */\n bumpAttempts(id: string, attempts: number): Promise<void>;\n\n /**\n * Deletes expired and over-capacity batches.\n * @returns Prune summary metrics.\n */\n prune(): Promise<PruneResult>;\n\n /** Returns the total number of stored batches. */\n count(): Promise<number>;\n\n /** Deletes all batches in storage. */\n clear(): Promise<void>;\n\n /** Closes storage connections and releases resources. */\n close(): Promise<void>;\n}\n\n/** Capacity and retention thresholds enforced by a storage adapter. */\nexport interface StorageLimits {\n /** Maximum batch capacity before FIFO eviction. */\n maxBatches: number;\n /** Maximum time-to-live for a stored batch in milliseconds. */\n maxAgeMs: number;\n /** Maximum delivery attempts before dead-letter drop. */\n maxAttempts: number;\n}\n\n/**\n * Gives the storage limits of a retention setting. \"until-delivered\" has no age limit and no\n * attempt limit. The batch cap still applies.\n * @param retention Retention setting from the config.\n * @returns The limits for the storage adapters and the retry engine.\n */\nexport function storageLimits(retention: RetentionOptions): StorageLimits {\n const { maxBatches } = retention;\n\n if (retention.mode === \"until-delivered\") {\n return { maxBatches, maxAgeMs: Infinity, maxAttempts: Infinity };\n }\n\n return { maxBatches, maxAgeMs: retention.maxAgeMs, maxAttempts: retention.maxAttempts };\n}\n\n/** Metrics for batches and records dropped during storage pruning. */\nexport interface PruneResult {\n /** Total batches dropped. */\n batches: number;\n /** Total records dropped within evicted batches. */\n records: number;\n /**\n * Cause of the drop. If more than one rule applies, this is the last rule. \"not_stored\" means\n * that storage did not keep a batch after a failed send.\n */\n reason: \"expired\" | \"over_capacity\" | \"quota\" | \"not_stored\";\n}\n\n/**\n * Callback invoked when dropped records create a telemetry gap.\n * @param result Summary of evicted data.\n * @param dropped The dropped batches. A corrupt entry has no batch. The list then has none for it.\n */\nexport type GapReporter = (result: PruneResult, dropped: readonly LogBatch[]) => void;\n"],"mappings":"AAoFA,SAAgBA,EAAc,EAA4C,CACxE,GAAM,CAAE,cAAeC,EAMvB,OAJIA,EAAU,OAAS,kBACd,CAAE,aAAY,SAAU,IAAU,YAAa,GAAS,EAG1D,CAAE,aAAY,SAAUA,EAAU,SAAU,YAAaA,EAAU,WAAY,CACxF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/models/storage.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
let { maxBatches: t } = e;
|
|
4
|
+
return e.mode === "until-delivered" ? {
|
|
5
|
+
maxBatches: t,
|
|
6
|
+
maxAgeMs: Infinity,
|
|
7
|
+
maxAttempts: Infinity
|
|
8
|
+
} : {
|
|
9
|
+
maxBatches: t,
|
|
10
|
+
maxAgeMs: e.maxAgeMs,
|
|
11
|
+
maxAttempts: e.maxAttempts
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { e as storageLimits };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=storage-w7Tslvlq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-w7Tslvlq.js","names":["storageLimits","retention"],"sources":["../src/models/storage.ts"],"sourcesContent":["// src/models/storage.ts\n//\n// Storage interface for undelivered batches, with adapters for IndexedDB,\n// localStorage, memory, and a fallback that does nothing.\n\nimport type { LogBatch } from \"./batch\";\nimport type { RetentionOptions } from \"./config\";\n\n/** Persistent batch storage interface. All methods must resolve and never throw. */\nexport interface StorageAdapter {\n /** Adapter identifier name. */\n readonly name: string;\n\n /**\n * Persists a batch to storage.\n * @param batch The batch to store.\n */\n save(batch: LogBatch): Promise<void>;\n\n /**\n * Reads up to `limit` batches in FIFO order without removing them.\n * @param limit Maximum number of batches to retrieve.\n * @returns Oldest persisted batches.\n */\n take(limit: number): Promise<LogBatch[]>;\n /**\n * Reads batches of one context without loading batches of other contexts.\n * @param id Delivery context id.\n * @param limit Maximum batches to return.\n * @returns Batches of this context, oldest first.\n */\n takeContext?(id: string, limit: number): Promise<LogBatch[]>;\n /**\n * Counts batches of one context without loading them.\n * @param id Delivery context id.\n * @returns Number of batches in this context.\n */\n countContext?(id: string): Promise<number>;\n\n /**\n * Removes a batch by ID. A call with an unknown ID resolves without error.\n * @param id Batch identifier.\n */\n remove(id: string): Promise<void>;\n\n /**\n * Updates the total delivery attempts for a batch.\n * @param id Batch identifier.\n * @param attempts Absolute attempt count.\n */\n bumpAttempts(id: string, attempts: number): Promise<void>;\n\n /**\n * Deletes expired and over-capacity batches.\n * @returns Prune summary metrics.\n */\n prune(): Promise<PruneResult>;\n\n /** Returns the total number of stored batches. */\n count(): Promise<number>;\n\n /** Deletes all batches in storage. */\n clear(): Promise<void>;\n\n /** Closes storage connections and releases resources. */\n close(): Promise<void>;\n}\n\n/** Capacity and retention thresholds enforced by a storage adapter. */\nexport interface StorageLimits {\n /** Maximum batch capacity before FIFO eviction. */\n maxBatches: number;\n /** Maximum time-to-live for a stored batch in milliseconds. */\n maxAgeMs: number;\n /** Maximum delivery attempts before dead-letter drop. */\n maxAttempts: number;\n}\n\n/**\n * Gives the storage limits of a retention setting. \"until-delivered\" has no age limit and no\n * attempt limit. The batch cap still applies.\n * @param retention Retention setting from the config.\n * @returns The limits for the storage adapters and the retry engine.\n */\nexport function storageLimits(retention: RetentionOptions): StorageLimits {\n const { maxBatches } = retention;\n\n if (retention.mode === \"until-delivered\") {\n return { maxBatches, maxAgeMs: Infinity, maxAttempts: Infinity };\n }\n\n return { maxBatches, maxAgeMs: retention.maxAgeMs, maxAttempts: retention.maxAttempts };\n}\n\n/** Metrics for batches and records dropped during storage pruning. */\nexport interface PruneResult {\n /** Total batches dropped. */\n batches: number;\n /** Total records dropped within evicted batches. */\n records: number;\n /**\n * Cause of the drop. If more than one rule applies, this is the last rule. \"not_stored\" means\n * that storage did not keep a batch after a failed send.\n */\n reason: \"expired\" | \"over_capacity\" | \"quota\" | \"not_stored\";\n}\n\n/**\n * Callback invoked when dropped records create a telemetry gap.\n * @param result Summary of evicted data.\n * @param dropped The dropped batches. A corrupt entry has no batch. The list then has none for it.\n */\nexport type GapReporter = (result: PruneResult, dropped: readonly LogBatch[]) => void;\n"],"mappings":";AAoFA,SAAgBA,EAAc,GAA4C;CACxE,IAAM,EAAE,kBAAeC;CAMvB,OAJIA,EAAU,SAAS,oBACd;EAAE;EAAY,UAAU;EAAU,aAAa;CAAS,IAG1D;EAAE;EAAY,UAAUA,EAAU;EAAU,aAAaA,EAAU;CAAY;AACxF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./constants-CW-MlHdY.cjs"),t=require("./fixed-window-CvESpFYV.cjs");function n(n,r,i,a,o=e.q){return r===0||t.t(n,r,o)?!0:(i.report(`capture.rate_limited`,`More than ${String(r)} ${a} occurred in ${String(o)} ms. The library ignores the other ${a} in this window.`),!1)}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return n}});
|
|
2
|
+
//# sourceMappingURL=storm-CNZjsw4T.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storm-CNZjsw4T.cjs","names":["ERROR_STORM_WINDOW_MS","countInWindow","require_constants","require_fixed_window","allowInWindow","limit","window","windowMs","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\";\nimport { countInWindow, type StormWindow } from \"../utils/fixed-window\";\n\nexport type { StormWindow } from \"../utils/fixed-window\";\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 * @param windowMs Rate limit window, in milliseconds.\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 windowMs = ERROR_STORM_WINDOW_MS,\n): boolean {\n if (limit === 0 || countInWindow(window, limit, windowMs)) {\n return true;\n }\n\n diagnostics.report(\n \"capture.rate_limited\",\n `More than ${String(limit)} ${what} occurred in ${String(windowMs)} ms. The library ignores the other ${what} in this window.`,\n );\n return false;\n}\n"],"mappings":"qFAoBA,SAAgBI,EACd,EACA,EACA,EACA,EACA,EAAWJ,EAAAA,EACF,CAST,OARIK,IAAU,GAAKJ,EAAAA,EAAcK,EAAQD,EAAOE,CAAQ,EAC/C,IAGTC,EAAY,OACV,uBACA,aAAa,OAAOH,CAAK,EAAE,GAAGI,EAAK,eAAe,OAAOF,CAAQ,EAAE,qCAAqCE,EAAK,iBAC/G,EACO,GACT"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { q as e } from "./constants-CN7GE1Lt.js";
|
|
2
|
+
import { t } from "./fixed-window-CtaFHanJ.js";
|
|
3
|
+
//#region src/capture/storm.ts
|
|
4
|
+
function n(n, r, i, a, o = e) {
|
|
5
|
+
return r === 0 || t(n, r, o) ? !0 : (i.report("capture.rate_limited", `More than ${String(r)} ${a} occurred in ${String(o)} ms. The library ignores the other ${a} in this window.`), !1);
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { n as t };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=storm-Daq2jGHU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storm-Daq2jGHU.js","names":["ERROR_STORM_WINDOW_MS","allowInWindow","limit","countInWindow","window","windowMs","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\";\nimport { countInWindow, type StormWindow } from \"../utils/fixed-window\";\n\nexport type { StormWindow } from \"../utils/fixed-window\";\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 * @param windowMs Rate limit window, in milliseconds.\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 windowMs = ERROR_STORM_WINDOW_MS,\n): boolean {\n if (limit === 0 || countInWindow(window, limit, windowMs)) {\n return true;\n }\n\n diagnostics.report(\n \"capture.rate_limited\",\n `More than ${String(limit)} ${what} occurred in ${String(windowMs)} ms. The library ignores the other ${what} in this window.`,\n );\n return false;\n}\n"],"mappings":";;;AAoBA,SAAgBC,EACd,GACA,GACA,GACA,GACA,IAAWD,GACF;CAST,OARIE,MAAU,KAAKC,EAAcC,GAAQF,GAAOG,CAAQ,IAC/C,MAGTC,EAAY,OACV,wBACA,aAAa,OAAOJ,CAAK,EAAE,GAAGK,EAAK,eAAe,OAAOF,CAAQ,EAAE,qCAAqCE,EAAK,iBAC/G,GACO;AACT"}
|
|
@@ -13,7 +13,7 @@ export declare class RetryEngine {
|
|
|
13
13
|
private readonly transport;
|
|
14
14
|
private readonly diagnostics;
|
|
15
15
|
private readonly config;
|
|
16
|
-
private readonly batchesPerDrain
|
|
16
|
+
private readonly batchesPerDrain?;
|
|
17
17
|
private readonly onLoss;
|
|
18
18
|
/** This field holds the active retry timer handle. It is null when no timer runs. */
|
|
19
19
|
private timer;
|
|
@@ -35,7 +35,7 @@ export declare class RetryEngine {
|
|
|
35
35
|
* @param batchesPerDrain Maximum batches processed per drain tick.
|
|
36
36
|
* @param onLoss Receives the records of each batch that the engine drops.
|
|
37
37
|
*/
|
|
38
|
-
constructor(storage: StorageAdapter, transport: BatchTransport, diagnostics: Diagnostics, config: ResolvedConfig, batchesPerDrain?: number, onLoss?: LossReporter);
|
|
38
|
+
constructor(storage: StorageAdapter, transport: BatchTransport, diagnostics: Diagnostics, config: ResolvedConfig, batchesPerDrain?: number | undefined, onLoss?: LossReporter);
|
|
39
39
|
/** This method starts the engine. It listens for online events and arms the first timer. */
|
|
40
40
|
start(): void;
|
|
41
41
|
/** This method schedules an earlier retry when storage receives a new offline batch. */
|
|
@@ -50,6 +50,11 @@ export declare class RetryEngine {
|
|
|
50
50
|
storeFailed(batch: LogBatch, error: unknown): Promise<void>;
|
|
51
51
|
/** This method stops the engine. It removes the listener and clears the pending timer. */
|
|
52
52
|
stop(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Tries one delivery pass of stored batches before a context change. The caller sets the deadline.
|
|
55
|
+
* @returns Promise that resolves when this pass stops.
|
|
56
|
+
*/
|
|
57
|
+
flush(): Promise<void>;
|
|
53
58
|
/**
|
|
54
59
|
* Clears the pending timer. It then schedules a drain after the delay.
|
|
55
60
|
* @param delayMs Delay duration in milliseconds.
|
|
@@ -35,6 +35,23 @@ export declare abstract class StatusTransport implements BatchTransport {
|
|
|
35
35
|
protected readonly diagnostics: Diagnostics;
|
|
36
36
|
private readonly onSampling;
|
|
37
37
|
private readonly onLoss;
|
|
38
|
+
/** Abort controller shared by the requests of this delivery context. */
|
|
39
|
+
protected readonly cancellation: AbortController;
|
|
40
|
+
/** Cancels work of this context. A custom transport receives the same abort signal. */
|
|
41
|
+
stop(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Checks the batch context after each asynchronous step and before a send.
|
|
44
|
+
* @param batch Batch to check.
|
|
45
|
+
* @throws TransportError if the context stopped or the context id does not match.
|
|
46
|
+
*/
|
|
47
|
+
protected assertContext(batch: LogBatch): void;
|
|
48
|
+
/**
|
|
49
|
+
* Ends the wait if this context stops before the work completes.
|
|
50
|
+
* @param work Work to wait for.
|
|
51
|
+
* @returns The result of the work.
|
|
52
|
+
* @throws TransportError if this context stops first.
|
|
53
|
+
*/
|
|
54
|
+
protected untilCancelled<T>(work: Promise<T>): Promise<T>;
|
|
38
55
|
/**
|
|
39
56
|
* Epoch time in milliseconds when the server throttle ends, for each endpoint. A 429 from
|
|
40
57
|
* metricsEndpoint must not stop the log batches.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-BR9t_w28.js","names":["matchesAny","url","patterns","pattern"],"sources":["../src/capture/types.ts"],"sourcesContent":["// src/capture/types.ts\n//\n// Shared interfaces, logger abstractions, and utility helpers for auto-capture modules.\n\nimport type { BreadcrumbBuffer } from \"../core/breadcrumbs\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { SpanData } from \"../core/spans\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { MetricType } from \"../models/log-record\";\nimport type { InstrumentDef, MetricAttributes } from \"../models/metric\";\nimport type { TraceEngine } from \"../utils/tracing\";\n\n/**\n * Logging interface that auto-capture modules use. A reference to the runtime class\n * here causes an import cycle. The runtime installs the capture modules.\n */\nexport interface CaptureLogger {\n /**\n * Logs an error event with an associated error instance or reason.\n * @param message Error description.\n * @param error Caught error instance or reason.\n * @param payload Optional attributes.\n */\n error(message: string, error?: unknown, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a warning event.\n * @param message Warning description.\n * @param payload Optional attributes.\n */\n warn(message: string, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a discrete lifecycle or user event.\n * @param name Event identifier.\n * @param payload Optional attributes.\n */\n logEvent(name: string, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a numerical metric measurement.\n * @param name Metric name.\n * @param value Numerical measurement.\n * @param unit Unit of measurement.\n * @param type Metric type classification.\n * @param attrs Optional metric attributes.\n */\n logMetric(\n name: string,\n value: number,\n unit?: string,\n type?: MetricType,\n attrs?: Record<string, unknown>,\n ): void;\n\n /**\n * Logs a diagnostic debug message.\n * @param message Debug message.\n * @param payload Optional attributes.\n */\n debug(message: string, payload?: Record<string, unknown>): void;\n}\n\n/**\n * Capture work that runs one time for each document, not one time for each\n * install. A reconfigure builds new capture instances. Thus instance state\n * cannot hold these flags. web-vitals has no unsubscribe. A second subscription\n * reports each metric two times.\n */\nexport interface CaptureOnce {\n /** True after the library subscribes the web-vitals reporters. */\n webVitals: boolean;\n /** True after the library reports navigation timing. */\n navigationTiming: boolean;\n /** True after the first long frame install. Only that install reads buffered frames. */\n longFrames: boolean;\n}\n\n/** Shared runtime dependencies provided to auto-capture instances. */\nexport interface CaptureContext {\n /** Active runtime configuration. */\n config: ResolvedConfig;\n /** Diagnostics reporter for capture faults. */\n diagnostics: Diagnostics;\n /** Logger instance for recorded telemetry. */\n logger: CaptureLogger;\n /** Buffer for recording contextual breadcrumbs. */\n breadcrumbs: BreadcrumbBuffer;\n /** Active trace context provider. */\n tracing: TraceEngine;\n /** Guards for the capture work that a reinstall must not repeat. */\n once: CaptureOnce;\n /** Adds a value to a counter or a histogram of the runtime. */\n recordMetric: (def: InstrumentDef, value: number, attributes?: MetricAttributes) => void;\n /** Records a span. The runtime drops it when spans are off. */\n recordSpan: (span: SpanData) => void;\n}\n\n/** Lifecycle interface for browser instrumentation modules. */\nexport interface Capture {\n /** Module identifier used in diagnostics. */\n readonly name: string;\n /**\n * Attaches instrumentation listeners and patches target APIs. A second patch on a\n * patched function adds a second wrapper and doubles each record. A second call\n * must do nothing.\n */\n install(): void;\n /** Restores native APIs and removes registered listeners. */\n uninstall(): void;\n}\n\n/**\n * Tests if a URL matches any string substring or regular expression pattern.\n * @param url Target URL to test. A value that is not a string matches nothing.\n * @param patterns Substrings and regular expressions to test against.\n * @returns True if any pattern matches the URL.\n */\nexport function matchesAny(url: unknown, patterns: (string | RegExp)[]): boolean {\n // Guard against a URL that is not a string. includes() on it throws in the call of the host.\n if (typeof url !== \"string\") {\n return false;\n }\n\n return patterns.some((pattern) =>\n typeof pattern === \"string\" ? url.includes(pattern) : pattern.test(url),\n );\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"types-BR9t_w28.js","names":["matchesAny","url","patterns","pattern"],"sources":["../src/capture/types.ts"],"sourcesContent":["// src/capture/types.ts\n//\n// Shared interfaces, logger abstractions, and utility helpers for auto-capture modules.\n\nimport type { BreadcrumbBuffer } from \"../core/breadcrumbs\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { SpanData } from \"../core/spans\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { MetricType } from \"../models/log-record\";\nimport type { InstrumentDef, MetricAttributes } from \"../models/metric\";\nimport type { TraceEngine } from \"../utils/tracing\";\n\n/**\n * Logging interface that auto-capture modules use. A reference to the runtime class\n * here causes an import cycle. The runtime installs the capture modules.\n */\nexport interface CaptureLogger {\n /**\n * Logs an error event with an associated error instance or reason.\n * @param message Error description.\n * @param error Caught error instance or reason.\n * @param payload Optional attributes.\n */\n error(message: string, error?: unknown, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a warning event.\n * @param message Warning description.\n * @param payload Optional attributes.\n */\n warn(message: string, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a discrete lifecycle or user event.\n * @param name Event identifier.\n * @param payload Optional attributes.\n */\n logEvent(name: string, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a numerical metric measurement.\n * @param name Metric name.\n * @param value Numerical measurement.\n * @param unit Unit of measurement.\n * @param type Metric type classification.\n * @param attrs Optional metric attributes.\n */\n logMetric(\n name: string,\n value: number,\n unit?: string,\n type?: MetricType,\n attrs?: Record<string, unknown>,\n ): void;\n\n /**\n * Logs a diagnostic debug message.\n * @param message Debug message.\n * @param payload Optional attributes.\n */\n debug(message: string, payload?: Record<string, unknown>): void;\n}\n\n/**\n * Capture work that runs one time for each document, not one time for each\n * install. A reconfigure builds new capture instances. Thus instance state\n * cannot hold these flags. web-vitals has no unsubscribe. A second subscription\n * reports each metric two times.\n */\nexport interface CaptureOnce {\n /** True after the library subscribes the web-vitals reporters. */\n webVitals: boolean;\n /** True after the library reports navigation timing. */\n navigationTiming: boolean;\n /** True after the first long frame install. Only that install reads buffered frames. */\n longFrames: boolean;\n}\n\n/** Shared runtime dependencies provided to auto-capture instances. */\nexport interface CaptureContext {\n /** False while the runtime stops or changes its security context. */\n isActive?: () => boolean;\n /** Active runtime configuration. */\n config: ResolvedConfig;\n /** Diagnostics reporter for capture faults. */\n diagnostics: Diagnostics;\n /** Logger instance for recorded telemetry. */\n logger: CaptureLogger;\n /** Buffer for recording contextual breadcrumbs. */\n breadcrumbs: BreadcrumbBuffer;\n /** Active trace context provider. */\n tracing: TraceEngine;\n /** Guards for the capture work that a reinstall must not repeat. */\n once: CaptureOnce;\n /** Adds a value to a counter or a histogram of the runtime. */\n recordMetric: (def: InstrumentDef, value: number, attributes?: MetricAttributes) => void;\n /** Records a span. The runtime drops it when spans are off. */\n recordSpan: (span: SpanData) => void;\n}\n\n/** Lifecycle interface for browser instrumentation modules. */\nexport interface Capture {\n /** Module identifier used in diagnostics. */\n readonly name: string;\n /**\n * Attaches instrumentation listeners and patches target APIs. A second patch on a\n * patched function adds a second wrapper and doubles each record. A second call\n * must do nothing.\n */\n install(): void;\n /** Restores native APIs and removes registered listeners. */\n uninstall(): void;\n}\n\n/**\n * Tests if a URL matches any string substring or regular expression pattern.\n * @param url Target URL to test. A value that is not a string matches nothing.\n * @param patterns Substrings and regular expressions to test against.\n * @returns True if any pattern matches the URL.\n */\nexport function matchesAny(url: unknown, patterns: (string | RegExp)[]): boolean {\n // Guard against a URL that is not a string. includes() on it throws in the call of the host.\n if (typeof url !== \"string\") {\n return false;\n }\n\n return patterns.some((pattern) =>\n typeof pattern === \"string\" ? url.includes(pattern) : pattern.test(url),\n );\n}\n"],"mappings":";AAwHA,SAAgBA,EAAW,GAAc,GAAwC;CAM/E,OAJI,OAAOC,KAAQ,YAIZC,EAAS,MAAM,MACpB,OAAOC,KAAY,WAAWF,EAAI,SAASE,CAAO,IAAIA,EAAQ,KAAKF,CAAG,CACxE;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-C7WNpnG1.cjs","names":["matchesAny","url","patterns","pattern"],"sources":["../src/capture/types.ts"],"sourcesContent":["// src/capture/types.ts\n//\n// Shared interfaces, logger abstractions, and utility helpers for auto-capture modules.\n\nimport type { BreadcrumbBuffer } from \"../core/breadcrumbs\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { SpanData } from \"../core/spans\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { MetricType } from \"../models/log-record\";\nimport type { InstrumentDef, MetricAttributes } from \"../models/metric\";\nimport type { TraceEngine } from \"../utils/tracing\";\n\n/**\n * Logging interface that auto-capture modules use. A reference to the runtime class\n * here causes an import cycle. The runtime installs the capture modules.\n */\nexport interface CaptureLogger {\n /**\n * Logs an error event with an associated error instance or reason.\n * @param message Error description.\n * @param error Caught error instance or reason.\n * @param payload Optional attributes.\n */\n error(message: string, error?: unknown, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a warning event.\n * @param message Warning description.\n * @param payload Optional attributes.\n */\n warn(message: string, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a discrete lifecycle or user event.\n * @param name Event identifier.\n * @param payload Optional attributes.\n */\n logEvent(name: string, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a numerical metric measurement.\n * @param name Metric name.\n * @param value Numerical measurement.\n * @param unit Unit of measurement.\n * @param type Metric type classification.\n * @param attrs Optional metric attributes.\n */\n logMetric(\n name: string,\n value: number,\n unit?: string,\n type?: MetricType,\n attrs?: Record<string, unknown>,\n ): void;\n\n /**\n * Logs a diagnostic debug message.\n * @param message Debug message.\n * @param payload Optional attributes.\n */\n debug(message: string, payload?: Record<string, unknown>): void;\n}\n\n/**\n * Capture work that runs one time for each document, not one time for each\n * install. A reconfigure builds new capture instances. Thus instance state\n * cannot hold these flags. web-vitals has no unsubscribe. A second subscription\n * reports each metric two times.\n */\nexport interface CaptureOnce {\n /** True after the library subscribes the web-vitals reporters. */\n webVitals: boolean;\n /** True after the library reports navigation timing. */\n navigationTiming: boolean;\n /** True after the first long frame install. Only that install reads buffered frames. */\n longFrames: boolean;\n}\n\n/** Shared runtime dependencies provided to auto-capture instances. */\nexport interface CaptureContext {\n /** Active runtime configuration. */\n config: ResolvedConfig;\n /** Diagnostics reporter for capture faults. */\n diagnostics: Diagnostics;\n /** Logger instance for recorded telemetry. */\n logger: CaptureLogger;\n /** Buffer for recording contextual breadcrumbs. */\n breadcrumbs: BreadcrumbBuffer;\n /** Active trace context provider. */\n tracing: TraceEngine;\n /** Guards for the capture work that a reinstall must not repeat. */\n once: CaptureOnce;\n /** Adds a value to a counter or a histogram of the runtime. */\n recordMetric: (def: InstrumentDef, value: number, attributes?: MetricAttributes) => void;\n /** Records a span. The runtime drops it when spans are off. */\n recordSpan: (span: SpanData) => void;\n}\n\n/** Lifecycle interface for browser instrumentation modules. */\nexport interface Capture {\n /** Module identifier used in diagnostics. */\n readonly name: string;\n /**\n * Attaches instrumentation listeners and patches target APIs. A second patch on a\n * patched function adds a second wrapper and doubles each record. A second call\n * must do nothing.\n */\n install(): void;\n /** Restores native APIs and removes registered listeners. */\n uninstall(): void;\n}\n\n/**\n * Tests if a URL matches any string substring or regular expression pattern.\n * @param url Target URL to test. A value that is not a string matches nothing.\n * @param patterns Substrings and regular expressions to test against.\n * @returns True if any pattern matches the URL.\n */\nexport function matchesAny(url: unknown, patterns: (string | RegExp)[]): boolean {\n // Guard against a URL that is not a string. includes() on it throws in the call of the host.\n if (typeof url !== \"string\") {\n return false;\n }\n\n return patterns.some((pattern) =>\n typeof pattern === \"string\" ? url.includes(pattern) : pattern.test(url),\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types-C7WNpnG1.cjs","names":["matchesAny","url","patterns","pattern"],"sources":["../src/capture/types.ts"],"sourcesContent":["// src/capture/types.ts\n//\n// Shared interfaces, logger abstractions, and utility helpers for auto-capture modules.\n\nimport type { BreadcrumbBuffer } from \"../core/breadcrumbs\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { SpanData } from \"../core/spans\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { MetricType } from \"../models/log-record\";\nimport type { InstrumentDef, MetricAttributes } from \"../models/metric\";\nimport type { TraceEngine } from \"../utils/tracing\";\n\n/**\n * Logging interface that auto-capture modules use. A reference to the runtime class\n * here causes an import cycle. The runtime installs the capture modules.\n */\nexport interface CaptureLogger {\n /**\n * Logs an error event with an associated error instance or reason.\n * @param message Error description.\n * @param error Caught error instance or reason.\n * @param payload Optional attributes.\n */\n error(message: string, error?: unknown, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a warning event.\n * @param message Warning description.\n * @param payload Optional attributes.\n */\n warn(message: string, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a discrete lifecycle or user event.\n * @param name Event identifier.\n * @param payload Optional attributes.\n */\n logEvent(name: string, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a numerical metric measurement.\n * @param name Metric name.\n * @param value Numerical measurement.\n * @param unit Unit of measurement.\n * @param type Metric type classification.\n * @param attrs Optional metric attributes.\n */\n logMetric(\n name: string,\n value: number,\n unit?: string,\n type?: MetricType,\n attrs?: Record<string, unknown>,\n ): void;\n\n /**\n * Logs a diagnostic debug message.\n * @param message Debug message.\n * @param payload Optional attributes.\n */\n debug(message: string, payload?: Record<string, unknown>): void;\n}\n\n/**\n * Capture work that runs one time for each document, not one time for each\n * install. A reconfigure builds new capture instances. Thus instance state\n * cannot hold these flags. web-vitals has no unsubscribe. A second subscription\n * reports each metric two times.\n */\nexport interface CaptureOnce {\n /** True after the library subscribes the web-vitals reporters. */\n webVitals: boolean;\n /** True after the library reports navigation timing. */\n navigationTiming: boolean;\n /** True after the first long frame install. Only that install reads buffered frames. */\n longFrames: boolean;\n}\n\n/** Shared runtime dependencies provided to auto-capture instances. */\nexport interface CaptureContext {\n /** False while the runtime stops or changes its security context. */\n isActive?: () => boolean;\n /** Active runtime configuration. */\n config: ResolvedConfig;\n /** Diagnostics reporter for capture faults. */\n diagnostics: Diagnostics;\n /** Logger instance for recorded telemetry. */\n logger: CaptureLogger;\n /** Buffer for recording contextual breadcrumbs. */\n breadcrumbs: BreadcrumbBuffer;\n /** Active trace context provider. */\n tracing: TraceEngine;\n /** Guards for the capture work that a reinstall must not repeat. */\n once: CaptureOnce;\n /** Adds a value to a counter or a histogram of the runtime. */\n recordMetric: (def: InstrumentDef, value: number, attributes?: MetricAttributes) => void;\n /** Records a span. The runtime drops it when spans are off. */\n recordSpan: (span: SpanData) => void;\n}\n\n/** Lifecycle interface for browser instrumentation modules. */\nexport interface Capture {\n /** Module identifier used in diagnostics. */\n readonly name: string;\n /**\n * Attaches instrumentation listeners and patches target APIs. A second patch on a\n * patched function adds a second wrapper and doubles each record. A second call\n * must do nothing.\n */\n install(): void;\n /** Restores native APIs and removes registered listeners. */\n uninstall(): void;\n}\n\n/**\n * Tests if a URL matches any string substring or regular expression pattern.\n * @param url Target URL to test. A value that is not a string matches nothing.\n * @param patterns Substrings and regular expressions to test against.\n * @returns True if any pattern matches the URL.\n */\nexport function matchesAny(url: unknown, patterns: (string | RegExp)[]): boolean {\n // Guard against a URL that is not a string. includes() on it throws in the call of the host.\n if (typeof url !== \"string\") {\n return false;\n }\n\n return patterns.some((pattern) =>\n typeof pattern === \"string\" ? url.includes(pattern) : pattern.test(url),\n );\n}\n"],"mappings":"AAwHA,SAAgBA,EAAW,EAAc,EAAwC,CAM/E,OAJI,OAAOC,GAAQ,UAIZC,EAAS,KAAM,GACpB,OAAOC,GAAY,SAAWF,EAAI,SAASE,CAAO,EAAIA,EAAQ,KAAKF,CAAG,CACxE,CACF"}
|
|
@@ -13,3 +13,12 @@ export interface StormWindow {
|
|
|
13
13
|
* @returns False when the window has no allowance left. The caller must drop the event.
|
|
14
14
|
*/
|
|
15
15
|
export declare function countInWindow(window: StormWindow, limit: number, windowMs: number): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Tells if a fixed window has ended. The bus uses the same rule to expire its source entries.
|
|
18
|
+
* @param window Window state.
|
|
19
|
+
* @param windowMs Length of the window, in milliseconds.
|
|
20
|
+
* @param now Current epoch time, in milliseconds.
|
|
21
|
+
* @returns True after the window length, or when the clock moved back. Without the second
|
|
22
|
+
* check, a clock that moves back keeps the window open.
|
|
23
|
+
*/
|
|
24
|
+
export declare function windowEnded(window: StormWindow, windowMs: number, now: number): boolean;
|
package/dist/utils/identity.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ export declare function newId(diagnostics: Diagnostics): string;
|
|
|
61
61
|
* @param stores Identity stores.
|
|
62
62
|
* @returns Populated Identity object.
|
|
63
63
|
*/
|
|
64
|
-
export declare function resolveIdentity(diagnostics: Diagnostics, stores?: IdentityStores): Identity;
|
|
64
|
+
export declare function resolveIdentity(diagnostics: Diagnostics, stores?: IdentityStores, idleMs?: number): Identity;
|
|
65
65
|
/**
|
|
66
66
|
* Writes a new tab id to the session store.
|
|
67
67
|
* @param tabId New tab identifier.
|
|
@@ -77,18 +77,25 @@ export declare function persistTabId(tabId: string, diagnostics: Diagnostics, st
|
|
|
77
77
|
export declare class SessionTouch {
|
|
78
78
|
private diagnostics;
|
|
79
79
|
private readonly stores;
|
|
80
|
+
private readonly touchMs;
|
|
81
|
+
private readonly idleMs;
|
|
80
82
|
/** Epoch milliseconds of the last write this instance made. */
|
|
81
83
|
private lastTouchAt;
|
|
82
84
|
/**
|
|
83
85
|
* @param diagnostics Diagnostics reporter.
|
|
84
86
|
* @param stores Identity stores.
|
|
85
87
|
*/
|
|
86
|
-
constructor(diagnostics: Diagnostics, stores?: IdentityStores);
|
|
88
|
+
constructor(diagnostics: Diagnostics, stores?: IdentityStores, touchMs?: number, idleMs?: number);
|
|
87
89
|
/**
|
|
88
90
|
* Writes the session activity time to the local store. It writes one time in each throttle window.
|
|
89
91
|
* @param sessionId Active session identifier.
|
|
90
92
|
*/
|
|
91
93
|
touch(sessionId: string): void;
|
|
94
|
+
/**
|
|
95
|
+
* Reads the live session id in the local store.
|
|
96
|
+
* @returns The stored session id, or undefined if no session is live.
|
|
97
|
+
*/
|
|
98
|
+
stored(): string | undefined;
|
|
92
99
|
/**
|
|
93
100
|
* Writes a new session id to the local store now. The throttle does not apply.
|
|
94
101
|
* @param sessionId New session identifier.
|
package/dist/utils/lock.d.ts
CHANGED
|
@@ -13,3 +13,11 @@ import type { Diagnostics } from "../core/diagnostics";
|
|
|
13
13
|
export declare function withDrainLock<T>(name: string, diagnostics: Diagnostics, fn: () => Promise<T>, { skipIfBusy }?: {
|
|
14
14
|
skipIfBusy?: boolean;
|
|
15
15
|
}): Promise<T | undefined>;
|
|
16
|
+
/**
|
|
17
|
+
* Gives the lock name of one application namespace. Two namespaces on one origin then do not wait for each other.
|
|
18
|
+
* Without it, the retry pass of one application skips while the other holds the lock.
|
|
19
|
+
* @param name Base lock name.
|
|
20
|
+
* @param namespace Application storage namespace. An empty value keeps the base name.
|
|
21
|
+
* @returns Lock name for this namespace.
|
|
22
|
+
*/
|
|
23
|
+
export declare function lockName(name: string, namespace: string): string;
|
package/dist/utils/openfin.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface FinIab {
|
|
|
14
14
|
*/
|
|
15
15
|
subscribe(identity: {
|
|
16
16
|
uuid: string;
|
|
17
|
-
}, topic: string, listener: (message: unknown) => void): Promise<void>;
|
|
17
|
+
}, topic: string, listener: (message: unknown, uuid?: string, name?: string) => void): Promise<void>;
|
|
18
18
|
}
|
|
19
19
|
/** The members of fin.me that the library reads. */
|
|
20
20
|
export interface FinMe {
|
package/dist/utils/platform.d.ts
CHANGED
|
@@ -39,9 +39,11 @@ export declare function currentUrl(diagnostics: Diagnostics): string;
|
|
|
39
39
|
* credential. Without fullUrls, it also removes the query and the fragment.
|
|
40
40
|
* @param url Absolute or relative URL.
|
|
41
41
|
* @param fullUrls Value of `capture.fullUrls`.
|
|
42
|
+
* @param transform Value of `capture.urlTransform`. It replaces the default rule.
|
|
43
|
+
* @param diagnostics Diagnostics reporter for a transform that throws.
|
|
42
44
|
* @returns The URL to record.
|
|
43
45
|
*/
|
|
44
|
-
export declare function recordedUrl(url: string, fullUrls: boolean): string;
|
|
46
|
+
export declare function recordedUrl(url: string, fullUrls: boolean, transform?: (url: string) => string | null, diagnostics?: Diagnostics): string;
|
|
45
47
|
/**
|
|
46
48
|
* Drops the query string and fragment from a URL.
|
|
47
49
|
* It cuts the string and does not parse a URL. A relative request target has no base URL.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./library-request-BaZOi4eg.cjs"),t=require("./platform-DBSKTvFn.cjs"),n=require("./patch-BX8KrPCT.cjs"),r=require("./storm-CNZjsw4T.cjs"),i=require("./types-C7WNpnG1.cjs");var a=`ui.websocket.messages`;function o(e,n,r){let i=new URL(e);return{target:t.i(e,!1,n.capture.urlTransform,r),server:i.hostname}}function s(t,n,r){let i=t.servers.get(n),a=r===`transmit`&&e.t();if(!t.active||i===void 0||a||t.config.securityContext.isolation&&t.contexts.get(n)!==t.config.securityContext.id)return;let o={"network.io.direction":r,"server.address":i};t.messages.add(1,o)}var c=class{diagnostics;config;name=`websocket`;restore;state;window={start:0,count:0};constructor(e,t){this.diagnostics=e,this.config=t}install(e){if(this.restore||typeof WebSocket>`u`)return;let t={active:!0,ctx:e,messages:e.counter(a),servers:new WeakMap,contexts:new WeakMap,config:this.config};this.state=t;let r=e=>{this.track(e,t)};this.restore=n.t(globalThis,`WebSocket`,e=>class extends e{static[Symbol.hasInstance](t){return t instanceof e}constructor(e,t){super(e,t),r(this)}send(e){super.send(e),s(t,this,`transmit`)}})}uninstall(){this.state&&(this.state.active=!1),this.restore&&!this.restore()&&this.diagnostics.report(`capture.install_failed`,`Another script wrapped WebSocket after the library. The library keeps that wrapper.`),this.restore=void 0,this.state=void 0}track(e,t){t.active&&this.diagnostics.guard(`capture.record_failed`,`The library could not track a WebSocket. The socket works without capture.`,()=>{if(i.t(e.url,this.config.capture.ignoreUrls))return;let{target:n,server:r}=o(e.url,this.config,this.diagnostics),a={"url.full":n,"server.address":r},{logger:c}=t.ctx;t.servers.set(e,r),t.contexts.set(e,this.config.securityContext.id);let l=n=>{(!this.config.securityContext.isolation||t.contexts.get(e)===this.config.securityContext.id)&&this.allow(t)&&n()};e.addEventListener(`open`,()=>{l(()=>{c.logEvent(`websocket.open`,a)})}),e.addEventListener(`error`,()=>{l(()=>{c.warn(`websocket.error`,a)})}),e.addEventListener(`close`,e=>{l(()=>{c.logEvent(`websocket.close`,{...a,"websocket.close.code":e.code,"websocket.close.clean":e.wasClean})})}),e.addEventListener(`message`,()=>{s(t,e,`receive`)})})}allow(e){return e.active&&r.t(this.window,this.config.capturePolicy.webSocketPerWindow,this.diagnostics,`WebSocket events`,this.config.capturePolicy.windowMs)}};exports.WebSocketCapture=c;
|
|
2
|
+
//# sourceMappingURL=web-socket-BacvKOvD.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-socket-BacvKOvD.cjs","names":["recordedUrl","isLibraryRequest","patch","matchesAny","allowInWindow","require_library_request","require_platform","require_patch","require_storm","require_types","MESSAGES_METRIC","socketTarget","parsed","url","config","diagnostics","count","server","state","socket","own","direction","attributes","WebSocketCapture","ctx","track","Original","value","protocols","data","target","lifecycle","write","logger","event"],"sources":["../src/capture/web-socket.ts"],"sourcesContent":["// src/capture/web-socket.ts\n//\n// Records the open, close and error events of each WebSocket. It counts the messages by direction\n// and server. It never reads the content of a message. It is a capture plugin, and the runtime\n// loads it as a separate chunk.\n\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { Counter, MetricAttributes } from \"../models/metric\";\nimport type { CapturePlugin, PluginContext } from \"../models/plugin\";\nimport { isLibraryRequest } from \"../utils/library-request\";\nimport { recordedUrl } from \"../utils/platform\";\nimport { patch } from \"../utils/patch\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport { matchesAny } from \"./types\";\n\n/** Name of the message counter. */\nconst MESSAGES_METRIC = \"ui.websocket.messages\";\n\n/** Data of one WebSocket.send call. */\ntype SendData = Parameters<WebSocket[\"send\"]>[0];\n\n/** State of one install. A wrapper that stays after uninstall reads it and records nothing. */\ninterface InstallState {\n /** False after uninstall. */\n active: boolean;\n /** Tools of the plugin. */\n ctx: PluginContext;\n /** Counter of the messages. */\n messages: Counter;\n /** Server host name of each tracked socket. */\n servers: WeakMap<WebSocket, string>;\n /** Delivery context in force when each socket opened. */\n contexts: WeakMap<WebSocket, string>;\n /** Active capture settings and isolation rule. */\n config: ResolvedConfig;\n}\n\n/**\n * Removes the user info, the query and the fragment from a socket URL. They can hold a token.\n * @param url Absolute URL of the socket.\n * @param config Active capture settings.\n * @param diagnostics Diagnostics reporter for a URL transform that throws.\n * @returns The URL to record and the host name of the server.\n */\nfunction socketTarget(\n url: string,\n config: ResolvedConfig,\n diagnostics: Diagnostics,\n): { target: string; server: string } {\n const parsed = new URL(url);\n\n return {\n // Ignore fullUrls. A browser cannot set a header on a socket. Thus apps often put a token in\n // the query. Only urlTransform can record more of the URL.\n target: recordedUrl(url, false, config.capture.urlTransform, diagnostics),\n server: parsed.hostname,\n };\n}\n\n/**\n * Counts one message of a tracked socket.\n * @param state State of the install that made the socket.\n * @param socket Socket of the message.\n * @param direction Direction of the message.\n */\nfunction count(state: InstallState, socket: WebSocket, direction: \"transmit\" | \"receive\"): void {\n const server = state.servers.get(socket);\n\n // A send of the library, for example a custom transport, must not make the next send.\n const own = direction === \"transmit\" && isLibraryRequest();\n if (\n !state.active ||\n server === undefined ||\n own ||\n (state.config.securityContext.isolation &&\n state.contexts.get(socket) !== state.config.securityContext.id)\n ) {\n return;\n }\n\n const attributes: MetricAttributes = {\n \"network.io.direction\": direction,\n \"server.address\": server,\n };\n state.messages.add(1, attributes);\n}\n\n/** Records the lifecycle and the message counts of each WebSocket that the app opens. */\nexport class WebSocketCapture implements CapturePlugin {\n /** Capture module identifier. */\n readonly name = \"websocket\";\n\n /** Restores the WebSocket constructor. Undefined when the capture is not installed. */\n private restore: (() => boolean) | undefined;\n\n /** State of the active install. */\n private state: InstallState | undefined;\n\n /** Rate limit of the lifecycle records. A reconnect loop must not flood the pipeline. */\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n /**\n * @param diagnostics Diagnostics reporter.\n * @param config Active configuration. The capture reads `capture.ignoreUrls`.\n */\n constructor(\n private readonly diagnostics: Diagnostics,\n private readonly config: ResolvedConfig,\n ) {}\n\n /**\n * Replaces the WebSocket constructor with a subclass that tracks each socket.\n * @param ctx Tools of the plugin.\n */\n install(ctx: PluginContext): void {\n if (this.restore || typeof WebSocket === \"undefined\") {\n return;\n }\n\n const state: InstallState = {\n active: true,\n ctx,\n messages: ctx.counter(MESSAGES_METRIC),\n servers: new WeakMap(),\n contexts: new WeakMap(),\n config: this.config,\n };\n this.state = state;\n\n const track = (socket: WebSocket): void => {\n this.track(socket, state);\n };\n\n this.restore = patch(\n globalThis,\n \"WebSocket\",\n (Original) =>\n class TrackedWebSocket extends Original {\n /**\n * Keeps instanceof true for a socket that the app opened before the install.\n * @param value Value to test.\n * @returns True for each native socket.\n */\n static override [Symbol.hasInstance](value: unknown): boolean {\n return value instanceof Original;\n }\n\n /**\n * @param url URL of the server.\n * @param protocols Sub-protocols of the app.\n */\n constructor(url: string | URL, protocols?: string | string[]) {\n super(url, protocols);\n track(this);\n }\n\n /**\n * Sends the data, then counts one message. A send that throws counts nothing.\n * @param data Data of the app. The library does not read it.\n */\n override send(data: SendData): void {\n super.send(data);\n count(state, this, \"transmit\");\n }\n },\n );\n }\n\n /** Restores the WebSocket constructor and stops each tracked socket from recording. */\n uninstall(): void {\n if (this.state) {\n this.state.active = false;\n }\n\n // Another script can wrap the constructor after the library. Keep its wrapper.\n if (this.restore && !this.restore()) {\n this.diagnostics.report(\n \"capture.install_failed\",\n \"Another script wrapped WebSocket after the library. The library keeps that wrapper.\",\n );\n }\n\n this.restore = undefined;\n this.state = undefined;\n }\n\n /**\n * Adds the listeners that record the lifecycle and the received messages of one socket.\n * @param socket New socket of the app.\n * @param state State of the install that made the socket.\n */\n private track(socket: WebSocket, state: InstallState): void {\n if (!state.active) {\n return;\n }\n\n // A read here runs inside the constructor call of the app. A throw must not fail it.\n this.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not track a WebSocket. The socket works without capture.\",\n () => {\n // ignoreUrls matches the full URL. A custom transport can send over its own socket.\n if (matchesAny(socket.url, this.config.capture.ignoreUrls)) {\n return;\n }\n\n const { target, server } = socketTarget(socket.url, this.config, this.diagnostics);\n const attributes = { \"url.full\": target, \"server.address\": server };\n const { logger } = state.ctx;\n state.servers.set(socket, server);\n state.contexts.set(socket, this.config.securityContext.id);\n\n const lifecycle = (write: () => void): void => {\n if (\n (!this.config.securityContext.isolation ||\n state.contexts.get(socket) === this.config.securityContext.id) &&\n this.allow(state)\n ) {\n write();\n }\n };\n\n socket.addEventListener(\"open\", () => {\n lifecycle(() => {\n logger.logEvent(\"websocket.open\", attributes);\n });\n });\n socket.addEventListener(\"error\", () => {\n lifecycle(() => {\n logger.warn(\"websocket.error\", attributes);\n });\n });\n socket.addEventListener(\"close\", (event) => {\n lifecycle(() => {\n logger.logEvent(\"websocket.close\", {\n ...attributes,\n \"websocket.close.code\": event.code,\n \"websocket.close.clean\": event.wasClean,\n });\n });\n });\n socket.addEventListener(\"message\", () => {\n count(state, socket, \"receive\");\n });\n },\n );\n }\n\n /**\n * Tests if a lifecycle record can go out.\n * @param state State of the install that made the socket.\n * @returns False after uninstall, or when the window has no allowance left.\n */\n private allow(state: InstallState): boolean {\n return (\n state.active &&\n allowInWindow(\n this.window,\n this.config.capturePolicy.webSocketPerWindow,\n this.diagnostics,\n \"WebSocket events\",\n this.config.capturePolicy.windowMs,\n )\n );\n }\n}\n"],"mappings":"6LAiBA,IAAMU,EAAkB,wBA4BxB,SAASC,EACP,EACA,EACA,EACoC,CACpC,IAAMC,EAAS,IAAI,IAAIC,CAAG,EAE1B,MAAO,CAGL,OAAQb,EAAAA,EAAYa,EAAK,GAAOC,EAAO,QAAQ,aAAcC,CAAW,EACxE,OAAQH,EAAO,QACjB,CACF,CAQA,SAASI,EAAM,EAAqB,EAAmB,EAAyC,CAC9F,IAAMC,EAASC,EAAM,QAAQ,IAAIC,CAAM,EAGjCC,EAAMC,IAAc,YAAcpB,EAAAA,EAAiB,EACzD,GACE,CAACiB,EAAM,QACPD,IAAW,IAAA,IACXG,GACCF,EAAM,OAAO,gBAAgB,WAC5BA,EAAM,SAAS,IAAIC,CAAM,IAAMD,EAAM,OAAO,gBAAgB,GAE9D,OAGF,IAAMI,EAA+B,CACnC,uBAAwBD,EACxB,iBAAkBJ,CACpB,EACAC,EAAM,SAAS,IAAI,EAAGI,CAAU,CAClC,CAGA,IAAaC,EAAb,KAAuD,CAkBlC,YACA,OAjBnB,KAAgB,YAGhB,QAGA,MAGA,OAAuC,CAAE,MAAO,EAAG,MAAO,CAAE,EAM5D,YACE,EACA,EACA,CAFiB,KAAA,YAAAR,EACA,KAAA,OAAAD,CAChB,CAMH,QAAQ,EAA0B,CAChC,GAAI,KAAK,SAAW,OAAO,UAAc,IACvC,OAGF,IAAMI,EAAsB,CAC1B,OAAQ,GACR,MACA,SAAUM,EAAI,QAAQd,CAAe,EACrC,QAAS,IAAI,QACb,SAAU,IAAI,QACd,OAAQ,KAAK,MACf,EACA,KAAK,MAAQQ,EAEb,IAAMO,EAAS,GAA4B,CACzC,KAAK,MAAMN,EAAQD,CAAK,CAC1B,EAEA,KAAK,QAAUhB,EAAAA,EACb,WACA,YACC,GACC,cAA+BwB,CAAS,CAMtC,OAAiB,OAAO,aAAa,EAAyB,CAC5D,OAAOC,aAAiBD,CAC1B,CAMA,YAAY,EAAmB,EAA+B,CAC5D,MAAMb,EAAKe,CAAS,EACpBH,EAAM,IAAI,CACZ,CAMA,KAAc,EAAsB,CAClC,MAAM,KAAKI,CAAI,EACfb,EAAME,EAAO,KAAM,UAAU,CAC/B,CACF,CACJ,CACF,CAGA,WAAkB,CACZ,KAAK,QACP,KAAK,MAAM,OAAS,IAIlB,KAAK,SAAW,CAAC,KAAK,QAAQ,GAChC,KAAK,YAAY,OACf,yBACA,qFACF,EAGF,KAAK,QAAU,IAAA,GACf,KAAK,MAAQ,IAAA,EACf,CAOA,MAAc,EAAmB,EAA2B,CACrDA,EAAM,QAKX,KAAK,YAAY,MACf,wBACA,iFACM,CAEJ,GAAIf,EAAAA,EAAWgB,EAAO,IAAK,KAAK,OAAO,QAAQ,UAAU,EACvD,OAGF,GAAM,CAAE,SAAQ,UAAWR,EAAaQ,EAAO,IAAK,KAAK,OAAQ,KAAK,WAAW,EAC3EG,EAAa,CAAE,WAAYQ,EAAQ,iBAAkBb,CAAO,EAC5D,CAAE,UAAWC,EAAM,IACzBA,EAAM,QAAQ,IAAIC,EAAQF,CAAM,EAChCC,EAAM,SAAS,IAAIC,EAAQ,KAAK,OAAO,gBAAgB,EAAE,EAEzD,IAAMY,EAAa,GAA4B,EAE1C,CAAC,KAAK,OAAO,gBAAgB,WAC5Bb,EAAM,SAAS,IAAIC,CAAM,IAAM,KAAK,OAAO,gBAAgB,KAC7D,KAAK,MAAMD,CAAK,GAEhBc,EAAM,CAEV,EAEAb,EAAO,iBAAiB,WAAc,CACpCY,MAAgB,CACdE,EAAO,SAAS,iBAAkBX,CAAU,CAC9C,CAAC,CACH,CAAC,EACDH,EAAO,iBAAiB,YAAe,CACrCY,MAAgB,CACdE,EAAO,KAAK,kBAAmBX,CAAU,CAC3C,CAAC,CACH,CAAC,EACDH,EAAO,iBAAiB,QAAU,GAAU,CAC1CY,MAAgB,CACdE,EAAO,SAAS,kBAAmB,CACjC,GAAGX,EACH,uBAAwBY,EAAM,KAC9B,wBAAyBA,EAAM,QACjC,CAAC,CACH,CAAC,CACH,CAAC,EACDf,EAAO,iBAAiB,cAAiB,CACvCH,EAAME,EAAOC,EAAQ,SAAS,CAChC,CAAC,CACH,CACF,CACF,CAOA,MAAc,EAA8B,CAC1C,OACED,EAAM,QACNd,EAAAA,EACE,KAAK,OACL,KAAK,OAAO,cAAc,mBAC1B,KAAK,YACL,mBACA,KAAK,OAAO,cAAc,QAC5B,CAEJ,CACF"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { t as e } from "./library-request-BKOcaKtQ.js";
|
|
2
|
+
import { i as t } from "./platform-Bw1btWCT.js";
|
|
3
|
+
import { t as n } from "./patch-CCWfuEY7.js";
|
|
4
|
+
import { t as r } from "./storm-Daq2jGHU.js";
|
|
5
|
+
import { t as i } from "./types-BR9t_w28.js";
|
|
6
|
+
//#region src/capture/web-socket.ts
|
|
7
|
+
var a = "ui.websocket.messages";
|
|
8
|
+
function o(e, n, r) {
|
|
9
|
+
let i = new URL(e);
|
|
10
|
+
return {
|
|
11
|
+
target: t(e, !1, n.capture.urlTransform, r),
|
|
12
|
+
server: i.hostname
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function s(t, n, r) {
|
|
16
|
+
let i = t.servers.get(n), a = r === "transmit" && e();
|
|
17
|
+
if (!t.active || i === void 0 || a || t.config.securityContext.isolation && t.contexts.get(n) !== t.config.securityContext.id) return;
|
|
18
|
+
let o = {
|
|
19
|
+
"network.io.direction": r,
|
|
20
|
+
"server.address": i
|
|
21
|
+
};
|
|
22
|
+
t.messages.add(1, o);
|
|
23
|
+
}
|
|
24
|
+
var c = class {
|
|
25
|
+
diagnostics;
|
|
26
|
+
config;
|
|
27
|
+
name = "websocket";
|
|
28
|
+
restore;
|
|
29
|
+
state;
|
|
30
|
+
window = {
|
|
31
|
+
start: 0,
|
|
32
|
+
count: 0
|
|
33
|
+
};
|
|
34
|
+
constructor(e, t) {
|
|
35
|
+
this.diagnostics = e, this.config = t;
|
|
36
|
+
}
|
|
37
|
+
install(e) {
|
|
38
|
+
if (this.restore || typeof WebSocket > "u") return;
|
|
39
|
+
let t = {
|
|
40
|
+
active: !0,
|
|
41
|
+
ctx: e,
|
|
42
|
+
messages: e.counter(a),
|
|
43
|
+
servers: /* @__PURE__ */ new WeakMap(),
|
|
44
|
+
contexts: /* @__PURE__ */ new WeakMap(),
|
|
45
|
+
config: this.config
|
|
46
|
+
};
|
|
47
|
+
this.state = t;
|
|
48
|
+
let r = (e) => {
|
|
49
|
+
this.track(e, t);
|
|
50
|
+
};
|
|
51
|
+
this.restore = n(globalThis, "WebSocket", (e) => class extends e {
|
|
52
|
+
static [Symbol.hasInstance](t) {
|
|
53
|
+
return t instanceof e;
|
|
54
|
+
}
|
|
55
|
+
constructor(e, t) {
|
|
56
|
+
super(e, t), r(this);
|
|
57
|
+
}
|
|
58
|
+
send(e) {
|
|
59
|
+
super.send(e), s(t, this, "transmit");
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
uninstall() {
|
|
64
|
+
this.state && (this.state.active = !1), this.restore && !this.restore() && this.diagnostics.report("capture.install_failed", "Another script wrapped WebSocket after the library. The library keeps that wrapper."), this.restore = void 0, this.state = void 0;
|
|
65
|
+
}
|
|
66
|
+
track(e, t) {
|
|
67
|
+
t.active && this.diagnostics.guard("capture.record_failed", "The library could not track a WebSocket. The socket works without capture.", () => {
|
|
68
|
+
if (i(e.url, this.config.capture.ignoreUrls)) return;
|
|
69
|
+
let { target: n, server: r } = o(e.url, this.config, this.diagnostics), a = {
|
|
70
|
+
"url.full": n,
|
|
71
|
+
"server.address": r
|
|
72
|
+
}, { logger: c } = t.ctx;
|
|
73
|
+
t.servers.set(e, r), t.contexts.set(e, this.config.securityContext.id);
|
|
74
|
+
let l = (n) => {
|
|
75
|
+
(!this.config.securityContext.isolation || t.contexts.get(e) === this.config.securityContext.id) && this.allow(t) && n();
|
|
76
|
+
};
|
|
77
|
+
e.addEventListener("open", () => {
|
|
78
|
+
l(() => {
|
|
79
|
+
c.logEvent("websocket.open", a);
|
|
80
|
+
});
|
|
81
|
+
}), e.addEventListener("error", () => {
|
|
82
|
+
l(() => {
|
|
83
|
+
c.warn("websocket.error", a);
|
|
84
|
+
});
|
|
85
|
+
}), e.addEventListener("close", (e) => {
|
|
86
|
+
l(() => {
|
|
87
|
+
c.logEvent("websocket.close", {
|
|
88
|
+
...a,
|
|
89
|
+
"websocket.close.code": e.code,
|
|
90
|
+
"websocket.close.clean": e.wasClean
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}), e.addEventListener("message", () => {
|
|
94
|
+
s(t, e, "receive");
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
allow(e) {
|
|
99
|
+
return e.active && r(this.window, this.config.capturePolicy.webSocketPerWindow, this.diagnostics, "WebSocket events", this.config.capturePolicy.windowMs);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
//#endregion
|
|
103
|
+
export { c as WebSocketCapture };
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=web-socket-CpsD8WAa.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-socket-CpsD8WAa.js","names":["isLibraryRequest","recordedUrl","patch","allowInWindow","matchesAny","MESSAGES_METRIC","socketTarget","parsed","url","config","diagnostics","count","server","state","socket","own","direction","attributes","WebSocketCapture","ctx","track","Original","value","protocols","data","target","lifecycle","write","event"],"sources":["../src/capture/web-socket.ts"],"sourcesContent":["// src/capture/web-socket.ts\n//\n// Records the open, close and error events of each WebSocket. It counts the messages by direction\n// and server. It never reads the content of a message. It is a capture plugin, and the runtime\n// loads it as a separate chunk.\n\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { Counter, MetricAttributes } from \"../models/metric\";\nimport type { CapturePlugin, PluginContext } from \"../models/plugin\";\nimport { isLibraryRequest } from \"../utils/library-request\";\nimport { recordedUrl } from \"../utils/platform\";\nimport { patch } from \"../utils/patch\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport { matchesAny } from \"./types\";\n\n/** Name of the message counter. */\nconst MESSAGES_METRIC = \"ui.websocket.messages\";\n\n/** Data of one WebSocket.send call. */\ntype SendData = Parameters<WebSocket[\"send\"]>[0];\n\n/** State of one install. A wrapper that stays after uninstall reads it and records nothing. */\ninterface InstallState {\n /** False after uninstall. */\n active: boolean;\n /** Tools of the plugin. */\n ctx: PluginContext;\n /** Counter of the messages. */\n messages: Counter;\n /** Server host name of each tracked socket. */\n servers: WeakMap<WebSocket, string>;\n /** Delivery context in force when each socket opened. */\n contexts: WeakMap<WebSocket, string>;\n /** Active capture settings and isolation rule. */\n config: ResolvedConfig;\n}\n\n/**\n * Removes the user info, the query and the fragment from a socket URL. They can hold a token.\n * @param url Absolute URL of the socket.\n * @param config Active capture settings.\n * @param diagnostics Diagnostics reporter for a URL transform that throws.\n * @returns The URL to record and the host name of the server.\n */\nfunction socketTarget(\n url: string,\n config: ResolvedConfig,\n diagnostics: Diagnostics,\n): { target: string; server: string } {\n const parsed = new URL(url);\n\n return {\n // Ignore fullUrls. A browser cannot set a header on a socket. Thus apps often put a token in\n // the query. Only urlTransform can record more of the URL.\n target: recordedUrl(url, false, config.capture.urlTransform, diagnostics),\n server: parsed.hostname,\n };\n}\n\n/**\n * Counts one message of a tracked socket.\n * @param state State of the install that made the socket.\n * @param socket Socket of the message.\n * @param direction Direction of the message.\n */\nfunction count(state: InstallState, socket: WebSocket, direction: \"transmit\" | \"receive\"): void {\n const server = state.servers.get(socket);\n\n // A send of the library, for example a custom transport, must not make the next send.\n const own = direction === \"transmit\" && isLibraryRequest();\n if (\n !state.active ||\n server === undefined ||\n own ||\n (state.config.securityContext.isolation &&\n state.contexts.get(socket) !== state.config.securityContext.id)\n ) {\n return;\n }\n\n const attributes: MetricAttributes = {\n \"network.io.direction\": direction,\n \"server.address\": server,\n };\n state.messages.add(1, attributes);\n}\n\n/** Records the lifecycle and the message counts of each WebSocket that the app opens. */\nexport class WebSocketCapture implements CapturePlugin {\n /** Capture module identifier. */\n readonly name = \"websocket\";\n\n /** Restores the WebSocket constructor. Undefined when the capture is not installed. */\n private restore: (() => boolean) | undefined;\n\n /** State of the active install. */\n private state: InstallState | undefined;\n\n /** Rate limit of the lifecycle records. A reconnect loop must not flood the pipeline. */\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n /**\n * @param diagnostics Diagnostics reporter.\n * @param config Active configuration. The capture reads `capture.ignoreUrls`.\n */\n constructor(\n private readonly diagnostics: Diagnostics,\n private readonly config: ResolvedConfig,\n ) {}\n\n /**\n * Replaces the WebSocket constructor with a subclass that tracks each socket.\n * @param ctx Tools of the plugin.\n */\n install(ctx: PluginContext): void {\n if (this.restore || typeof WebSocket === \"undefined\") {\n return;\n }\n\n const state: InstallState = {\n active: true,\n ctx,\n messages: ctx.counter(MESSAGES_METRIC),\n servers: new WeakMap(),\n contexts: new WeakMap(),\n config: this.config,\n };\n this.state = state;\n\n const track = (socket: WebSocket): void => {\n this.track(socket, state);\n };\n\n this.restore = patch(\n globalThis,\n \"WebSocket\",\n (Original) =>\n class TrackedWebSocket extends Original {\n /**\n * Keeps instanceof true for a socket that the app opened before the install.\n * @param value Value to test.\n * @returns True for each native socket.\n */\n static override [Symbol.hasInstance](value: unknown): boolean {\n return value instanceof Original;\n }\n\n /**\n * @param url URL of the server.\n * @param protocols Sub-protocols of the app.\n */\n constructor(url: string | URL, protocols?: string | string[]) {\n super(url, protocols);\n track(this);\n }\n\n /**\n * Sends the data, then counts one message. A send that throws counts nothing.\n * @param data Data of the app. The library does not read it.\n */\n override send(data: SendData): void {\n super.send(data);\n count(state, this, \"transmit\");\n }\n },\n );\n }\n\n /** Restores the WebSocket constructor and stops each tracked socket from recording. */\n uninstall(): void {\n if (this.state) {\n this.state.active = false;\n }\n\n // Another script can wrap the constructor after the library. Keep its wrapper.\n if (this.restore && !this.restore()) {\n this.diagnostics.report(\n \"capture.install_failed\",\n \"Another script wrapped WebSocket after the library. The library keeps that wrapper.\",\n );\n }\n\n this.restore = undefined;\n this.state = undefined;\n }\n\n /**\n * Adds the listeners that record the lifecycle and the received messages of one socket.\n * @param socket New socket of the app.\n * @param state State of the install that made the socket.\n */\n private track(socket: WebSocket, state: InstallState): void {\n if (!state.active) {\n return;\n }\n\n // A read here runs inside the constructor call of the app. A throw must not fail it.\n this.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not track a WebSocket. The socket works without capture.\",\n () => {\n // ignoreUrls matches the full URL. A custom transport can send over its own socket.\n if (matchesAny(socket.url, this.config.capture.ignoreUrls)) {\n return;\n }\n\n const { target, server } = socketTarget(socket.url, this.config, this.diagnostics);\n const attributes = { \"url.full\": target, \"server.address\": server };\n const { logger } = state.ctx;\n state.servers.set(socket, server);\n state.contexts.set(socket, this.config.securityContext.id);\n\n const lifecycle = (write: () => void): void => {\n if (\n (!this.config.securityContext.isolation ||\n state.contexts.get(socket) === this.config.securityContext.id) &&\n this.allow(state)\n ) {\n write();\n }\n };\n\n socket.addEventListener(\"open\", () => {\n lifecycle(() => {\n logger.logEvent(\"websocket.open\", attributes);\n });\n });\n socket.addEventListener(\"error\", () => {\n lifecycle(() => {\n logger.warn(\"websocket.error\", attributes);\n });\n });\n socket.addEventListener(\"close\", (event) => {\n lifecycle(() => {\n logger.logEvent(\"websocket.close\", {\n ...attributes,\n \"websocket.close.code\": event.code,\n \"websocket.close.clean\": event.wasClean,\n });\n });\n });\n socket.addEventListener(\"message\", () => {\n count(state, socket, \"receive\");\n });\n },\n );\n }\n\n /**\n * Tests if a lifecycle record can go out.\n * @param state State of the install that made the socket.\n * @returns False after uninstall, or when the window has no allowance left.\n */\n private allow(state: InstallState): boolean {\n return (\n state.active &&\n allowInWindow(\n this.window,\n this.config.capturePolicy.webSocketPerWindow,\n this.diagnostics,\n \"WebSocket events\",\n this.config.capturePolicy.windowMs,\n )\n );\n }\n}\n"],"mappings":"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"}
|
package/package.json
CHANGED
package/dist/batch-C4oF6XZT.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("./constants-BgRS6MB0.cjs"),t=require("./identity-Bwku7zzN.cjs");function n(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`id`),n=Reflect.get(e,`createdAt`),r=Reflect.get(e,`attempts`),i=Reflect.get(e,`records`);return typeof t==`string`&&typeof n==`number`&&typeof r==`number`&&Array.isArray(i)}function r(e,n){if(e.records.length<2)return null;let r=Math.floor(e.records.length/2),i=r=>({id:t.i(n),records:r,createdAt:e.createdAt,attempts:e.attempts});return[i(e.records.slice(0,r)),i(e.records.slice(r))]}function i(e,t){let n=e;if(typeof n!=`object`||!n)return;let r=Reflect.get(n,`attributes`);if(typeof r==`object`&&r)return Reflect.get(r,t)}function a(t){return i(t,e.d)===e._t}function o(e){return e.reduce((e,t)=>e+t.records.length,0)}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return i}});
|
|
2
|
-
//# sourceMappingURL=batch-C4oF6XZT.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"batch-C4oF6XZT.cjs","names":["newId","ATTR_LOG_TYPE","LOG_TYPE_ACTION","require_constants","require_identity","isLogBatch","value","id","createdAt","attempts","records","splitBatch","batch","middle","halve","diagnostics","attributeOf","record","attributes","key","isActionRecord","countRecords","batches","total"],"sources":["../src/models/batch.ts"],"sourcesContent":["// src/models/batch.ts\n//\n// A batch of log records for delivery to the ingest endpoint.\n\nimport { ATTR_LOG_TYPE, LOG_TYPE_ACTION } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { newId } from \"../utils/identity\";\nimport type { LogRecord } from \"./log-record\";\n\n/**\n * A batch of records with a stable id used for server-side deduplication across retries.\n * @see {@link splitBatch}\n */\nexport interface LogBatch {\n /** Deduplication key. It stays the same across retries and reloads. */\n id: string;\n /** Records to deliver, in log order. */\n records: LogRecord[];\n /** Batch creation time, in epoch milliseconds. */\n createdAt: number;\n /** Delivery attempts so far. */\n attempts: number;\n}\n\n/**\n * Tells if a value from storage has all fields of a batch. `keyOf` cannot match\n * an entry without `id` after delivery. The library then retries that entry with no\n * end, and the entry blocks each batch behind it. An entry without `attempts` counts\n * as NaN. That count never reaches `maxAttempts`. Thus the library never drops the\n * entry as a dead letter.\n * @param value Parsed storage entry.\n * @returns True when each required field is present and has the correct type.\n */\nexport function isLogBatch(value: unknown): value is LogBatch {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const id: unknown = Reflect.get(value, \"id\");\n const createdAt: unknown = Reflect.get(value, \"createdAt\");\n const attempts: unknown = Reflect.get(value, \"attempts\");\n const records: unknown = Reflect.get(value, \"records\");\n\n return (\n typeof id === \"string\" &&\n typeof createdAt === \"number\" &&\n typeof attempts === \"number\" &&\n Array.isArray(records)\n );\n}\n\n/**\n * Splits a batch that the server rejected as too large into two halves.\n * Each half gets a new id. Each half keeps the age and attempts of the original batch.\n * @param batch The rejected batch.\n * @param diagnostics Diagnostics reporter for the new batch ids.\n * @returns Two batches, or `null` if a single record is already over the limit.\n */\nexport function splitBatch(batch: LogBatch, diagnostics: Diagnostics): [LogBatch, LogBatch] | null {\n if (batch.records.length < 2) {\n return null;\n }\n\n const middle = Math.floor(batch.records.length / 2);\n const halve = (records: LogRecord[]): LogBatch => ({\n id: newId(diagnostics),\n records,\n createdAt: batch.createdAt,\n attempts: batch.attempts,\n });\n\n return [halve(batch.records.slice(0, middle)), halve(batch.records.slice(middle))];\n}\n\n/**\n * Reads one attribute of a record. A record from storage can be corrupt. It can be null or have\n * no attributes.\n * @param record Record to read.\n * @param key Attribute key.\n * @returns The attribute value, or undefined for a corrupt record.\n */\nexport function attributeOf(record: LogRecord, key: string): unknown {\n const value: unknown = record;\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n const attributes: unknown = Reflect.get(value, \"attributes\");\n if (typeof attributes !== \"object\" || attributes === null) {\n return undefined;\n }\n\n return Reflect.get(attributes, key);\n}\n\n/**\n * Tests if a record is an action. A corrupt record from storage is not an action.\n * @param record Record to test.\n * @returns True for an action record.\n */\nexport function isActionRecord(record: LogRecord): boolean {\n return attributeOf(record, ATTR_LOG_TYPE) === LOG_TYPE_ACTION;\n}\n\n/**\n * Returns the total record count of the batches.\n * @param batches Batches to measure.\n * @returns Total record count.\n */\nexport function countRecords(batches: readonly LogBatch[]): number {\n return batches.reduce((total, batch) => total + batch.records.length, 0);\n}\n"],"mappings":"iFAiCA,SAAgBK,EAAW,EAAmC,CAC5D,GAAI,OAAOC,GAAU,WAAYA,EAC/B,MAAO,GAGT,IAAMC,EAAc,QAAQ,IAAID,EAAO,IAAI,EACrCE,EAAqB,QAAQ,IAAIF,EAAO,WAAW,EACnDG,EAAoB,QAAQ,IAAIH,EAAO,UAAU,EACjDI,EAAmB,QAAQ,IAAIJ,EAAO,SAAS,EAErD,OACE,OAAOC,GAAO,UACd,OAAOC,GAAc,UACrB,OAAOC,GAAa,UACpB,MAAM,QAAQC,CAAO,CAEzB,CASA,SAAgBC,EAAW,EAAiB,EAAuD,CACjG,GAAIC,EAAM,QAAQ,OAAS,EACzB,OAAO,KAGT,IAAMC,EAAS,KAAK,MAAMD,EAAM,QAAQ,OAAS,CAAC,EAC5CE,EAAS,IAAoC,CACjD,GAAId,EAAAA,EAAMe,CAAW,EACrB,UACA,UAAWH,EAAM,UACjB,SAAUA,EAAM,QAClB,GAEA,MAAO,CAACE,EAAMF,EAAM,QAAQ,MAAM,EAAGC,CAAM,CAAC,EAAGC,EAAMF,EAAM,QAAQ,MAAMC,CAAM,CAAC,CAAC,CACnF,CASA,SAAgBG,EAAY,EAAmB,EAAsB,CACnE,IAAMV,EAAiBW,EACvB,GAAI,OAAOX,GAAU,WAAYA,EAC/B,OAGF,IAAMY,EAAsB,QAAQ,IAAIZ,EAAO,YAAY,EAC3D,GAAI,OAAOY,GAAe,UAAYA,EAItC,OAAO,QAAQ,IAAIA,EAAYC,CAAG,CACpC,CAOA,SAAgBC,EAAe,EAA4B,CACzD,OAAOJ,EAAYC,EAAQhB,EAAAA,CAAa,IAAMC,EAAAA,EAChD,CAOA,SAAgBmB,EAAa,EAAsC,CACjE,OAAOC,EAAQ,QAAQ,EAAO,IAAUC,EAAQX,EAAM,QAAQ,OAAQ,CAAC,CACzE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"batch-D-4xl7op.js","names":["LOG_TYPE_ACTION","ATTR_LOG_TYPE","newId","isLogBatch","value","id","createdAt","attempts","records","splitBatch","batch","middle","halve","diagnostics","attributeOf","record","attributes","key","isActionRecord","countRecords","batches","total"],"sources":["../src/models/batch.ts"],"sourcesContent":["// src/models/batch.ts\n//\n// A batch of log records for delivery to the ingest endpoint.\n\nimport { ATTR_LOG_TYPE, LOG_TYPE_ACTION } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { newId } from \"../utils/identity\";\nimport type { LogRecord } from \"./log-record\";\n\n/**\n * A batch of records with a stable id used for server-side deduplication across retries.\n * @see {@link splitBatch}\n */\nexport interface LogBatch {\n /** Deduplication key. It stays the same across retries and reloads. */\n id: string;\n /** Records to deliver, in log order. */\n records: LogRecord[];\n /** Batch creation time, in epoch milliseconds. */\n createdAt: number;\n /** Delivery attempts so far. */\n attempts: number;\n}\n\n/**\n * Tells if a value from storage has all fields of a batch. `keyOf` cannot match\n * an entry without `id` after delivery. The library then retries that entry with no\n * end, and the entry blocks each batch behind it. An entry without `attempts` counts\n * as NaN. That count never reaches `maxAttempts`. Thus the library never drops the\n * entry as a dead letter.\n * @param value Parsed storage entry.\n * @returns True when each required field is present and has the correct type.\n */\nexport function isLogBatch(value: unknown): value is LogBatch {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const id: unknown = Reflect.get(value, \"id\");\n const createdAt: unknown = Reflect.get(value, \"createdAt\");\n const attempts: unknown = Reflect.get(value, \"attempts\");\n const records: unknown = Reflect.get(value, \"records\");\n\n return (\n typeof id === \"string\" &&\n typeof createdAt === \"number\" &&\n typeof attempts === \"number\" &&\n Array.isArray(records)\n );\n}\n\n/**\n * Splits a batch that the server rejected as too large into two halves.\n * Each half gets a new id. Each half keeps the age and attempts of the original batch.\n * @param batch The rejected batch.\n * @param diagnostics Diagnostics reporter for the new batch ids.\n * @returns Two batches, or `null` if a single record is already over the limit.\n */\nexport function splitBatch(batch: LogBatch, diagnostics: Diagnostics): [LogBatch, LogBatch] | null {\n if (batch.records.length < 2) {\n return null;\n }\n\n const middle = Math.floor(batch.records.length / 2);\n const halve = (records: LogRecord[]): LogBatch => ({\n id: newId(diagnostics),\n records,\n createdAt: batch.createdAt,\n attempts: batch.attempts,\n });\n\n return [halve(batch.records.slice(0, middle)), halve(batch.records.slice(middle))];\n}\n\n/**\n * Reads one attribute of a record. A record from storage can be corrupt. It can be null or have\n * no attributes.\n * @param record Record to read.\n * @param key Attribute key.\n * @returns The attribute value, or undefined for a corrupt record.\n */\nexport function attributeOf(record: LogRecord, key: string): unknown {\n const value: unknown = record;\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n const attributes: unknown = Reflect.get(value, \"attributes\");\n if (typeof attributes !== \"object\" || attributes === null) {\n return undefined;\n }\n\n return Reflect.get(attributes, key);\n}\n\n/**\n * Tests if a record is an action. A corrupt record from storage is not an action.\n * @param record Record to test.\n * @returns True for an action record.\n */\nexport function isActionRecord(record: LogRecord): boolean {\n return attributeOf(record, ATTR_LOG_TYPE) === LOG_TYPE_ACTION;\n}\n\n/**\n * Returns the total record count of the batches.\n * @param batches Batches to measure.\n * @returns Total record count.\n */\nexport function countRecords(batches: readonly LogBatch[]): number {\n return batches.reduce((total, batch) => total + batch.records.length, 0);\n}\n"],"mappings":";;;AAiCA,SAAgBG,EAAW,GAAmC;CAC5D,IAAI,OAAOC,KAAU,aAAYA,GAC/B,OAAO;CAGT,IAAMC,IAAc,QAAQ,IAAID,GAAO,IAAI,GACrCE,IAAqB,QAAQ,IAAIF,GAAO,WAAW,GACnDG,IAAoB,QAAQ,IAAIH,GAAO,UAAU,GACjDI,IAAmB,QAAQ,IAAIJ,GAAO,SAAS;CAErD,OACE,OAAOC,KAAO,YACd,OAAOC,KAAc,YACrB,OAAOC,KAAa,YACpB,MAAM,QAAQC,CAAO;AAEzB;AASA,SAAgBC,EAAW,GAAiB,GAAuD;CACjG,IAAIC,EAAM,QAAQ,SAAS,GACzB,OAAO;CAGT,IAAMC,IAAS,KAAK,MAAMD,EAAM,QAAQ,SAAS,CAAC,GAC5CE,KAAS,OAAoC;EACjD,IAAIV,EAAMW,CAAW;EACrB;EACA,WAAWH,EAAM;EACjB,UAAUA,EAAM;CAClB;CAEA,OAAO,CAACE,EAAMF,EAAM,QAAQ,MAAM,GAAGC,CAAM,CAAC,GAAGC,EAAMF,EAAM,QAAQ,MAAMC,CAAM,CAAC,CAAC;AACnF;AASA,SAAgBG,EAAY,GAAmB,GAAsB;CACnE,IAAMV,IAAiBW;CACvB,IAAI,OAAOX,KAAU,aAAYA,GAC/B;CAGF,IAAMY,IAAsB,QAAQ,IAAIZ,GAAO,YAAY;CAC3D,IAAI,OAAOY,KAAe,YAAYA,GAItC,OAAO,QAAQ,IAAIA,GAAYC,CAAG;AACpC;AAOA,SAAgBC,EAAe,GAA4B;CACzD,OAAOJ,EAAYC,GAAQd,CAAa,MAAMD;AAChD;AAOA,SAAgBmB,EAAa,GAAsC;CACjE,OAAOC,EAAQ,QAAQ,GAAO,MAAUC,IAAQX,EAAM,QAAQ,QAAQ,CAAC;AACzE"}
|