@utk09/ui-observability 0.9.5 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/README.md +315 -99
- package/bin/uiobs.mjs +8 -0
- package/dist/{batch-BQFtb3i5.cjs → batch-C8OcWR2L.cjs} +2 -2
- package/dist/{batch-BQFtb3i5.cjs.map → batch-C8OcWR2L.cjs.map} +1 -1
- package/dist/{batch-BUJh-1jZ.js → batch-CL9uWYY3.js} +5 -6
- package/dist/{batch-BUJh-1jZ.js.map → batch-CL9uWYY3.js.map} +1 -1
- package/dist/bus/bus.d.ts +15 -0
- package/dist/{bus-DeOPHWaD.js → bus-BZ0GldpT.js} +125 -112
- package/dist/bus-BZ0GldpT.js.map +1 -0
- package/dist/bus-VWlmM5xs.cjs +2 -0
- package/dist/bus-VWlmM5xs.cjs.map +1 -0
- package/dist/capture/interactions.d.ts +18 -0
- package/dist/capture/lifecycle.d.ts +20 -0
- package/dist/capture/reports.d.ts +17 -0
- package/dist/capture/resource-timing.d.ts +14 -0
- package/dist/capture/server-timing.d.ts +19 -0
- package/dist/capture/types.d.ts +13 -0
- package/dist/capture/unclean-exit.d.ts +31 -0
- package/dist/capture/user-timing.d.ts +22 -0
- package/dist/console-BPZCuSLc.cjs +2 -0
- package/dist/console-BPZCuSLc.cjs.map +1 -0
- package/dist/{console-DbAZYJuy.js → console-BeCF7n59.js} +20 -20
- package/dist/{console-DbAZYJuy.js.map → console-BeCF7n59.js.map} +1 -1
- package/dist/constants-DqKJH_MP.cjs +2 -0
- package/dist/constants-DqKJH_MP.cjs.map +1 -0
- package/dist/constants-zyrqveN4.js +304 -0
- package/dist/constants-zyrqveN4.js.map +1 -0
- package/dist/constants.d.ts +58 -2
- package/dist/context-storage-BjzeBSxH.cjs.map +1 -1
- package/dist/{context-storage-DxZf4Gfh.js → context-storage-BzkoHzkQ.js} +2 -3
- package/dist/{context-storage-DxZf4Gfh.js.map → context-storage-BzkoHzkQ.js.map} +1 -1
- package/dist/core/debug-buffer.d.ts +34 -0
- package/dist/core/debug-bundle.d.ts +12 -0
- package/dist/core/deferred.d.ts +7 -0
- package/dist/core/logger.d.ts +7 -2
- package/dist/core/measure.d.ts +19 -0
- package/dist/core/pipeline.d.ts +6 -1
- package/dist/core/record.d.ts +20 -1
- package/dist/core/remote-sampling.d.ts +5 -1
- package/dist/core/runtime.d.ts +45 -2
- package/dist/core/sampling.d.ts +5 -4
- package/dist/core/sender.d.ts +3 -1
- package/dist/core/spans.d.ts +5 -0
- package/dist/{deadline-5_PecIl5.js → deadline-BOjOxNHj.js} +3 -5
- package/dist/{deadline-5_PecIl5.js.map → deadline-BOjOxNHj.js.map} +1 -1
- package/dist/deadline-XSnm95pg.cjs.map +1 -1
- package/dist/debug-bundle-BzJNpbF0.cjs +2 -0
- package/dist/debug-bundle-BzJNpbF0.cjs.map +1 -0
- package/dist/debug-bundle-C7UkHZ-q.js +25 -0
- package/dist/debug-bundle-C7UkHZ-q.js.map +1 -0
- package/dist/doctor.cjs +2 -0
- package/dist/doctor.cjs.map +1 -0
- package/dist/doctor.d.ts +23 -0
- package/dist/doctor.js +98 -0
- package/dist/doctor.js.map +1 -0
- package/dist/{emergency-queue-Cs1hrjsC.cjs → emergency-queue-CNTRui5t.cjs} +2 -2
- package/dist/{emergency-queue-Cs1hrjsC.cjs.map → emergency-queue-CNTRui5t.cjs.map} +1 -1
- package/dist/{emergency-queue-BYUyDHGD.js → emergency-queue-Zy6lNafo.js} +17 -19
- package/dist/{emergency-queue-BYUyDHGD.js.map → emergency-queue-Zy6lNafo.js.map} +1 -1
- package/dist/{error-like-Ywo5uRHo.js → error-like-B11pB4aL.js} +2 -3
- package/dist/{error-like-Ywo5uRHo.js.map → error-like-B11pB4aL.js.map} +1 -1
- package/dist/error-like-gGRx2s36.cjs.map +1 -1
- package/dist/{errors-BhC7HTSt.js → errors-Dh7kef0i.js} +5 -6
- package/dist/{errors-BhC7HTSt.js.map → errors-Dh7kef0i.js.map} +1 -1
- package/dist/{errors-CgY633cG.cjs → errors-tfEr48bS.cjs} +2 -2
- package/dist/{errors-CgY633cG.cjs.map → errors-tfEr48bS.cjs.map} +1 -1
- package/dist/{factory-C5TujXlU.js → factory-BonqI3NL.js} +16 -20
- package/dist/{factory-C5TujXlU.js.map → factory-BonqI3NL.js.map} +1 -1
- package/dist/{factory-CNj4DH3n.cjs → factory-CJXVYp0R.cjs} +2 -2
- package/dist/{factory-CNj4DH3n.cjs.map → factory-CJXVYp0R.cjs.map} +1 -1
- package/dist/fixed-window-CvESpFYV.cjs.map +1 -1
- package/dist/{fixed-window-CtaFHanJ.js → fixed-window-Dq3MLUUv.js} +2 -3
- package/dist/{fixed-window-CtaFHanJ.js.map → fixed-window-Dq3MLUUv.js.map} +1 -1
- package/dist/global-scope-BN-Io_yv.cjs.map +1 -1
- package/dist/{global-scope-dp2jADRl.js → global-scope-D9I8s-oN.js} +2 -3
- package/dist/{global-scope-dp2jADRl.js.map → global-scope-D9I8s-oN.js.map} +1 -1
- package/dist/guards-Cidk71ME.js +7 -0
- package/dist/guards-Cidk71ME.js.map +1 -0
- package/dist/guards-nJ70syPt.cjs +2 -0
- package/dist/guards-nJ70syPt.cjs.map +1 -0
- package/dist/{identity-Da9TkuKd.cjs → identity-Cxgj6pZX.cjs} +2 -2
- package/dist/{identity-Da9TkuKd.cjs.map → identity-Cxgj6pZX.cjs.map} +1 -1
- package/dist/{identity-8vKkyAWm.js → identity-DT5VmvXy.js} +15 -16
- package/dist/{identity-8vKkyAWm.js.map → identity-DT5VmvXy.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +27 -7
- package/dist/index.js +980 -604
- package/dist/index.js.map +1 -1
- package/dist/{indexeddb-storage-CCA1LvtO.js → indexeddb-storage-BJVtiQKm.js} +29 -30
- package/dist/{indexeddb-storage-CCA1LvtO.js.map → indexeddb-storage-BJVtiQKm.js.map} +1 -1
- package/dist/{indexeddb-storage-BTfIFRHF.cjs → indexeddb-storage-CIoW21Xd.cjs} +2 -2
- package/dist/{indexeddb-storage-BTfIFRHF.cjs.map → indexeddb-storage-CIoW21Xd.cjs.map} +1 -1
- package/dist/interactions-DTgKy_6K.js +119 -0
- package/dist/interactions-DTgKy_6K.js.map +1 -0
- package/dist/interactions-fEN6FbVo.cjs +2 -0
- package/dist/interactions-fEN6FbVo.cjs.map +1 -0
- package/dist/{journey-BUJ4WJxP.js → journey-CuJrHzEg.js} +18 -19
- package/dist/{journey-BUJ4WJxP.js.map → journey-CuJrHzEg.js.map} +1 -1
- package/dist/{journey-B_tTnvac.cjs → journey-pffMVMfa.cjs} +2 -2
- package/dist/{journey-B_tTnvac.cjs.map → journey-pffMVMfa.cjs.map} +1 -1
- package/dist/keys-BHhw_0Wh.cjs.map +1 -1
- package/dist/{keys-D5r_GH9q.js → keys-BU9j5YqW.js} +2 -3
- package/dist/{keys-D5r_GH9q.js.map → keys-BU9j5YqW.js.map} +1 -1
- package/dist/library-console-C1m6g1BR.js +13 -0
- package/dist/library-console-C1m6g1BR.js.map +1 -0
- package/dist/library-console-D2GY9Or6.cjs +2 -0
- package/dist/library-console-D2GY9Or6.cjs.map +1 -0
- package/dist/{library-request-BaZOi4eg.cjs → library-request-1BX_UlaX.cjs} +2 -2
- package/dist/{library-request-BaZOi4eg.cjs.map → library-request-1BX_UlaX.cjs.map} +1 -1
- package/dist/library-request-BQBT9N9Q.js +24 -0
- package/dist/{library-request-BKOcaKtQ.js.map → library-request-BQBT9N9Q.js.map} +1 -1
- package/dist/lifecycle-2EtUaRpo.cjs +2 -0
- package/dist/lifecycle-2EtUaRpo.cjs.map +1 -0
- package/dist/lifecycle-BaKx_-32.js +55 -0
- package/dist/lifecycle-BaKx_-32.js.map +1 -0
- package/dist/log-record-CAoGBBf3.js +16 -0
- package/dist/log-record-CAoGBBf3.js.map +1 -0
- package/dist/log-record-i9zOTkpQ.cjs +2 -0
- package/dist/log-record-i9zOTkpQ.cjs.map +1 -0
- package/dist/{long-frames-CF3qiSAX.cjs → long-frames-BVg4i5SC.cjs} +2 -2
- package/dist/{long-frames-CF3qiSAX.cjs.map → long-frames-BVg4i5SC.cjs.map} +1 -1
- package/dist/{long-frames-DI5ypfAF.js → long-frames-Czk7IupC.js} +4 -5
- package/dist/{long-frames-DI5ypfAF.js.map → long-frames-Czk7IupC.js.map} +1 -1
- package/dist/models/config.d.ts +168 -4
- package/dist/models/health.d.ts +25 -0
- package/dist/models/metric.d.ts +13 -0
- package/dist/models/storage.d.ts +5 -0
- package/dist/{network-DdzXDI3J.js → network-DBNwApoF.js} +117 -70
- package/dist/network-DBNwApoF.js.map +1 -0
- package/dist/network-xbbuvG_6.cjs +2 -0
- package/dist/network-xbbuvG_6.cjs.map +1 -0
- package/dist/openfin-Bxelt0yg.js +7 -0
- package/dist/{openfin-BwEN0uj4.js.map → openfin-Bxelt0yg.js.map} +1 -1
- package/dist/openfin-DtH2f7zX.cjs.map +1 -1
- package/dist/otlp-BDvFrLnc.cjs +2 -0
- package/dist/otlp-BDvFrLnc.cjs.map +1 -0
- package/dist/otlp-BTJdIa6F.js +81 -0
- package/dist/otlp-BTJdIa6F.js.map +1 -0
- package/dist/patch-BX8KrPCT.cjs.map +1 -1
- package/dist/{patch-CCWfuEY7.js → patch-UdPz1ea8.js} +2 -3
- package/dist/{patch-CCWfuEY7.js.map → patch-UdPz1ea8.js.map} +1 -1
- package/dist/{platform-DBSKTvFn.cjs → platform-C2Ez5kDc.cjs} +2 -2
- package/dist/{platform-DBSKTvFn.cjs.map → platform-C2Ez5kDc.cjs.map} +1 -1
- package/dist/{platform-Bw1btWCT.js → platform-DkcuXwe-.js} +5 -6
- package/dist/{platform-Bw1btWCT.js.map → platform-DkcuXwe-.js.map} +1 -1
- package/dist/remote-rules-Cfb4K-Nl.js +98 -0
- package/dist/remote-rules-Cfb4K-Nl.js.map +1 -0
- package/dist/remote-rules-vzvk7aKf.cjs +2 -0
- package/dist/remote-rules-vzvk7aKf.cjs.map +1 -0
- package/dist/reports-Dk2YhKIh.cjs +2 -0
- package/dist/reports-Dk2YhKIh.cjs.map +1 -0
- package/dist/reports-TA-zInnq.js +70 -0
- package/dist/reports-TA-zInnq.js.map +1 -0
- package/dist/resource-timing-BLv3EA2A.js +76 -0
- package/dist/resource-timing-BLv3EA2A.js.map +1 -0
- package/dist/resource-timing-Cysw1S1f.cjs +2 -0
- package/dist/resource-timing-Cysw1S1f.cjs.map +1 -0
- package/dist/sampling-C4VV-1MS.js +60 -0
- package/dist/sampling-C4VV-1MS.js.map +1 -0
- package/dist/sampling-Ckh2yW9k.cjs +2 -0
- package/dist/sampling-Ckh2yW9k.cjs.map +1 -0
- package/dist/sanitize-6ymPlVvP.js +112 -0
- package/dist/sanitize-6ymPlVvP.js.map +1 -0
- package/dist/sanitize-BAWzkZt0.cjs +2 -0
- package/dist/sanitize-BAWzkZt0.cjs.map +1 -0
- package/dist/select-ZF4by-lF.cjs +3 -0
- package/dist/select-ZF4by-lF.cjs.map +1 -0
- package/dist/select-xtQaenIi.js +270 -0
- package/dist/select-xtQaenIi.js.map +1 -0
- package/dist/{sender-DUUmSglb.js → sender-CiMHC9YG.js} +202 -509
- package/dist/sender-CiMHC9YG.js.map +1 -0
- package/dist/sender-D5wBoXA8.cjs +2 -0
- package/dist/sender-D5wBoXA8.cjs.map +1 -0
- package/dist/storage/persistence.d.ts +8 -0
- package/dist/storage-BA9RqRO-.cjs.map +1 -1
- package/dist/{storage-w7Tslvlq.js → storage-DZwed89z.js} +2 -3
- package/dist/storage-DZwed89z.js.map +1 -0
- package/dist/storm-CYi9Swpx.cjs +2 -0
- package/dist/{storm-CNZjsw4T.cjs.map → storm-CYi9Swpx.cjs.map} +1 -1
- package/dist/{storm-Daq2jGHU.js → storm-VR024_QN.js} +4 -5
- package/dist/{storm-Daq2jGHU.js.map → storm-VR024_QN.js.map} +1 -1
- package/dist/transport/headers.d.ts +8 -0
- package/dist/transport/http-transport.d.ts +2 -6
- package/dist/transport/serializers/otlp.d.ts +14 -0
- package/dist/transport/status-transport.d.ts +5 -2
- package/dist/transport/worker-client.d.ts +14 -0
- package/dist/transport/worker-entry.d.ts +5 -0
- package/dist/transport/worker-protocol.d.ts +36 -0
- package/dist/transport/worker-server.d.ts +3 -0
- package/dist/transport/worker-transport.d.ts +9 -0
- package/dist/{types-BR9t_w28.js → types-BAerHgCq.js} +2 -3
- package/dist/types-BAerHgCq.js.map +1 -0
- package/dist/types-C7WNpnG1.cjs.map +1 -1
- package/dist/unclean-exit-CwcUhFOn.js +62 -0
- package/dist/unclean-exit-CwcUhFOn.js.map +1 -0
- package/dist/unclean-exit-DFUN57wY.cjs +2 -0
- package/dist/unclean-exit-DFUN57wY.cjs.map +1 -0
- package/dist/user-timing-C9kfRq3J.cjs +2 -0
- package/dist/user-timing-C9kfRq3J.cjs.map +1 -0
- package/dist/user-timing-_jZIhDKI.js +63 -0
- package/dist/user-timing-_jZIhDKI.js.map +1 -0
- package/dist/{web-socket-BacvKOvD.cjs → web-socket-BWUoqBh8.cjs} +2 -2
- package/dist/{web-socket-BacvKOvD.cjs.map → web-socket-BWUoqBh8.cjs.map} +1 -1
- package/dist/{web-socket-CpsD8WAa.js → web-socket-CV7yIMnm.js} +7 -8
- package/dist/{web-socket-CpsD8WAa.js.map → web-socket-CV7yIMnm.js.map} +1 -1
- package/dist/{web-vitals-Bflr5jSA.js → web-vitals-Bq4WFHQo.js} +2 -3
- package/dist/{web-vitals-Bflr5jSA.js.map → web-vitals-Bq4WFHQo.js.map} +1 -1
- package/dist/web-vitals-DFuoTQbZ.cjs.map +1 -1
- package/dist/worker-protocol-Bai7GAIA.cjs +2 -0
- package/dist/worker-protocol-Bai7GAIA.cjs.map +1 -0
- package/dist/worker-protocol-CrsdSDLn.js +49 -0
- package/dist/worker-protocol-CrsdSDLn.js.map +1 -0
- package/dist/worker-server-BrIYkfoa.cjs +2 -0
- package/dist/worker-server-BrIYkfoa.cjs.map +1 -0
- package/dist/worker-server-Dp5HYm4b.js +83 -0
- package/dist/worker-server-Dp5HYm4b.js.map +1 -0
- package/dist/worker-transport-Bwej4N2e.cjs +2 -0
- package/dist/worker-transport-Bwej4N2e.cjs.map +1 -0
- package/dist/worker-transport-D6jtgpqN.js +199 -0
- package/dist/worker-transport-D6jtgpqN.js.map +1 -0
- package/package.json +31 -41
- package/dist/bus-BW6N-pY8.cjs +0 -2
- package/dist/bus-BW6N-pY8.cjs.map +0 -1
- package/dist/bus-DeOPHWaD.js.map +0 -1
- package/dist/console-Ce6heqZZ.cjs +0 -2
- package/dist/console-Ce6heqZZ.cjs.map +0 -1
- package/dist/constants-CN7GE1Lt.js +0 -246
- package/dist/constants-CN7GE1Lt.js.map +0 -1
- package/dist/constants-CW-MlHdY.cjs +0 -2
- package/dist/constants-CW-MlHdY.cjs.map +0 -1
- package/dist/interactions-BUDLxbv1.js +0 -74
- package/dist/interactions-BUDLxbv1.js.map +0 -1
- package/dist/interactions-NHbLKrqe.cjs +0 -2
- package/dist/interactions-NHbLKrqe.cjs.map +0 -1
- package/dist/library-request-BKOcaKtQ.js +0 -25
- package/dist/network-CF8UO5PK.cjs +0 -2
- package/dist/network-CF8UO5PK.cjs.map +0 -1
- package/dist/network-DdzXDI3J.js.map +0 -1
- package/dist/openfin-BwEN0uj4.js +0 -8
- package/dist/remote-rules-DIcC5vVC.js +0 -91
- package/dist/remote-rules-DIcC5vVC.js.map +0 -1
- package/dist/remote-rules-DpFmOef2.cjs +0 -2
- package/dist/remote-rules-DpFmOef2.cjs.map +0 -1
- package/dist/sampling-BVjspJWu.cjs +0 -2
- package/dist/sampling-BVjspJWu.cjs.map +0 -1
- package/dist/sampling-Cm3WhI0a.js +0 -76
- package/dist/sampling-Cm3WhI0a.js.map +0 -1
- package/dist/sanitize-C-ahCFsG.js +0 -123
- package/dist/sanitize-C-ahCFsG.js.map +0 -1
- package/dist/sanitize-DHucKGdi.cjs +0 -2
- package/dist/sanitize-DHucKGdi.cjs.map +0 -1
- package/dist/sender-D3fRCR8d.cjs +0 -3
- package/dist/sender-D3fRCR8d.cjs.map +0 -1
- package/dist/sender-DUUmSglb.js.map +0 -1
- package/dist/storage-w7Tslvlq.js.map +0 -1
- package/dist/storm-CNZjsw4T.cjs +0 -2
- package/dist/types-BR9t_w28.js.map +0 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { DebugBufferPolicy } from "../models/config";
|
|
2
|
+
import type { LogRecord } from "../models/log-record";
|
|
3
|
+
/** Bounded list of the records that the library dropped by level or by sampling. */
|
|
4
|
+
export declare class DebugBuffer {
|
|
5
|
+
private readonly policy;
|
|
6
|
+
/** Kept records, oldest first. It can hold up to two times maxRecords between trims. */
|
|
7
|
+
private kept;
|
|
8
|
+
/**
|
|
9
|
+
* @param policy Gives the settings in force. A later configure() can change them.
|
|
10
|
+
*/
|
|
11
|
+
constructor(policy: () => DebugBufferPolicy);
|
|
12
|
+
/**
|
|
13
|
+
* Keeps a record. When the buffer is full, the oldest record leaves first.
|
|
14
|
+
* @param record Built record. The privacy hooks already ran on it.
|
|
15
|
+
*/
|
|
16
|
+
push(record: LogRecord): void;
|
|
17
|
+
/**
|
|
18
|
+
* Takes the kept records that are not too old, and empties the buffer.
|
|
19
|
+
* @returns The records, oldest first. Each has `uiobs.debug_buffer: true`.
|
|
20
|
+
*/
|
|
21
|
+
drain(): LogRecord[];
|
|
22
|
+
/**
|
|
23
|
+
* Gives the kept records without taking them.
|
|
24
|
+
* @returns The records, oldest first.
|
|
25
|
+
*/
|
|
26
|
+
snapshot(): LogRecord[];
|
|
27
|
+
/**
|
|
28
|
+
* Gives the kept records that the settings in force permit. A buffer that is off empties itself.
|
|
29
|
+
* @returns The records, oldest first.
|
|
30
|
+
*/
|
|
31
|
+
private live;
|
|
32
|
+
/** Removes each kept record. The records of an old session or identity must not go out. */
|
|
33
|
+
clear(): void;
|
|
34
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ResolvedConfig } from "../models/config";
|
|
2
|
+
import { type SanitizeLimits } from "../utils/sanitize";
|
|
3
|
+
import type { Diagnostics } from "./diagnostics";
|
|
4
|
+
/**
|
|
5
|
+
* Copies the config for a support ticket. It leaves out the headers and cuts each URL. A function
|
|
6
|
+
* becomes its name, and a RegExp its text.
|
|
7
|
+
* @param config Active configuration.
|
|
8
|
+
* @param limits Limits of the copy, as for record attributes.
|
|
9
|
+
* @param diagnostics Diagnostics reporter.
|
|
10
|
+
* @returns JSON-safe copy of the config.
|
|
11
|
+
*/
|
|
12
|
+
export declare function configSummary(config: ResolvedConfig, limits: SanitizeLimits, diagnostics: Diagnostics): Record<string, unknown>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Diagnostics } from "./diagnostics";
|
|
2
|
+
/** Queues a call without reading its payload. A full queue first builds its pending calls. */
|
|
3
|
+
export declare function deferWrite(owner: object, work: () => void, diagnostics: Diagnostics, limit: number): void;
|
|
4
|
+
/** Builds pending calls before a flush, a session change or a delivery identity change. */
|
|
5
|
+
export declare function drainDeferred(owner: object): void;
|
|
6
|
+
/** Releases calls that a hook queues during shutdown. Those calls have no built records. */
|
|
7
|
+
export declare function cancelDeferred(owner: object): void;
|
package/dist/core/logger.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type MetricType } from "../models/log-record";
|
|
2
2
|
import type { ObservabilityRuntime } from "./runtime";
|
|
3
3
|
/** Configuration options for a scoped OneLogger instance. */
|
|
4
4
|
export interface OneLoggerOptions {
|
|
@@ -109,9 +109,12 @@ export declare class OneLogger {
|
|
|
109
109
|
* @param type Record classification.
|
|
110
110
|
* @param body Primary message.
|
|
111
111
|
* @param payload Optional contextual attributes.
|
|
112
|
-
* @param copied True when the payload is a copy that the library made. write() does not copy it.
|
|
113
112
|
*/
|
|
114
113
|
private write;
|
|
114
|
+
/** Runs a call at once or queues it without reading its payload. */
|
|
115
|
+
private submit;
|
|
116
|
+
/** Builds a standard record from a call whose payload is now ready to read. */
|
|
117
|
+
private writeNow;
|
|
115
118
|
/**
|
|
116
119
|
* Builds and emits an error record with breadcrumbs. It also prints the record to the console.
|
|
117
120
|
* @param level Severity level ("ERROR" or "FATAL").
|
|
@@ -120,6 +123,8 @@ export declare class OneLogger {
|
|
|
120
123
|
* @param payload Optional contextual attributes.
|
|
121
124
|
*/
|
|
122
125
|
private writeError;
|
|
126
|
+
/** Builds an error record after the deferred queue releases its payload. */
|
|
127
|
+
private writeErrorNow;
|
|
123
128
|
/**
|
|
124
129
|
* Prints one log line. With a redact hook, the line shows only what redact returned.
|
|
125
130
|
* A host can record console arguments. The console must not show what redact removes.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { InstrumentDef, Measure, MetricAttributes } from "../models/metric";
|
|
2
|
+
import { type ClientSpan } from "../utils/tracing";
|
|
3
|
+
import type { SpanData } from "./spans";
|
|
4
|
+
/** Receivers of the values of one measure. */
|
|
5
|
+
export interface MeasureSinks {
|
|
6
|
+
/** Adds a value to a histogram. */
|
|
7
|
+
metric(def: InstrumentDef, value: number, attributes: MetricAttributes): void;
|
|
8
|
+
/** Records one span. */
|
|
9
|
+
span(span: SpanData): void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Starts the clock of one operation.
|
|
13
|
+
* @param name Operation name. A JavaScript caller can pass another type.
|
|
14
|
+
* @param attributes Copy of the attribute set of the app.
|
|
15
|
+
* @param span Span of the operation, or undefined with spans off or for a dropped trace.
|
|
16
|
+
* @param sinks Receivers of the values.
|
|
17
|
+
* @returns The handle of the operation.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createMeasure(name: unknown, attributes: MetricAttributes, span: ClientSpan | undefined, sinks: MeasureSinks): Measure;
|
package/dist/core/pipeline.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare class LogPipeline {
|
|
|
24
24
|
private readonly routingContextId?;
|
|
25
25
|
private readonly policy?;
|
|
26
26
|
private readonly onLoss;
|
|
27
|
+
private readonly clockOffset;
|
|
27
28
|
/** Buffer instances for logs and metrics streams. */
|
|
28
29
|
private readonly streams;
|
|
29
30
|
/** In-flight batches without delivery confirmation. The exit flush sends them again. */
|
|
@@ -68,8 +69,12 @@ export declare class LogPipeline {
|
|
|
68
69
|
* @param retry Retry engine for redelivering persisted batches.
|
|
69
70
|
* @param diagnostics Diagnostics reporter.
|
|
70
71
|
* @param streamOptions Batching policy per stream, from the batching config.
|
|
72
|
+
* @param routingContextId Gives the delivery context id of a new batch.
|
|
73
|
+
* @param policy Active configuration instance.
|
|
74
|
+
* @param onLoss Receives the records that the pipeline loses.
|
|
75
|
+
* @param clockOffset Gives the clock offset for a new log or span record, if known.
|
|
71
76
|
*/
|
|
72
|
-
constructor(transport: BatchTransport, storage: StorageAdapter, retry: RetryEngine, diagnostics: Diagnostics, streamOptions: Record<StreamName, StreamOptions>, routingContextId?: (() => string | undefined) | undefined, policy?: ResolvedConfig | undefined, onLoss?: LossReporter);
|
|
77
|
+
constructor(transport: BatchTransport, storage: StorageAdapter, retry: RetryEngine, diagnostics: Diagnostics, streamOptions: Record<StreamName, StreamOptions>, routingContextId?: (() => string | undefined) | undefined, policy?: ResolvedConfig | undefined, onLoss?: LossReporter, clockOffset?: () => number | undefined);
|
|
73
78
|
/**
|
|
74
79
|
* Sets the observed timestamp and adds a record to the pipeline.
|
|
75
80
|
* @param record Record to push.
|
package/dist/core/record.d.ts
CHANGED
|
@@ -6,8 +6,9 @@ import { type SanitizeLimits } from "../utils/sanitize";
|
|
|
6
6
|
import type { Sequence } from "../utils/sequence";
|
|
7
7
|
import type { TraceContext, TraceEngine } from "../utils/tracing";
|
|
8
8
|
import type { ContextStore } from "./context";
|
|
9
|
+
import type { DebugBuffer } from "./debug-buffer";
|
|
9
10
|
import type { Diagnostics } from "./diagnostics";
|
|
10
|
-
import type { JourneyEngine } from "./journey";
|
|
11
|
+
import type { Journey, JourneyEngine } from "./journey";
|
|
11
12
|
import type { RemoteSlot } from "./remote-sampling";
|
|
12
13
|
/** Injected dependencies required by RecordBuilder. */
|
|
13
14
|
export interface RecordBuilderDeps {
|
|
@@ -31,6 +32,8 @@ export interface RecordBuilderDeps {
|
|
|
31
32
|
platform: PlatformMetadata;
|
|
32
33
|
/** Slot of the sampling rules from the ingest server. */
|
|
33
34
|
remote: RemoteSlot;
|
|
35
|
+
/** Keeps the records that minLevel or sampling drops, for the next error. */
|
|
36
|
+
debug?: DebugBuffer;
|
|
34
37
|
}
|
|
35
38
|
/** Size limits for each record. The builder applies them after sanitize and after redact. */
|
|
36
39
|
export interface RecordLimits extends SanitizeLimits {
|
|
@@ -51,6 +54,14 @@ export interface BuildResult {
|
|
|
51
54
|
/** Reason for the drop. It is absent when the builder built a record. */
|
|
52
55
|
dropped?: DropReason;
|
|
53
56
|
}
|
|
57
|
+
/** Metadata captured before a deferred logger call reads its payload. */
|
|
58
|
+
export interface RecordSnapshot {
|
|
59
|
+
timeUnixNano: string;
|
|
60
|
+
trace: TraceContext;
|
|
61
|
+
journey: Journey | null;
|
|
62
|
+
context: Record<string, unknown>;
|
|
63
|
+
url: string;
|
|
64
|
+
}
|
|
54
65
|
/** Input parameters for constructing a single log record. */
|
|
55
66
|
export interface BuildInput {
|
|
56
67
|
/** Severity level of the log entry. */
|
|
@@ -74,6 +85,8 @@ export interface BuildInput {
|
|
|
74
85
|
aggregated?: boolean;
|
|
75
86
|
/** Trace IDs of a span. Without them, the builder reads the active trace. */
|
|
76
87
|
trace?: TraceContext;
|
|
88
|
+
/** Metadata of the call before the deferred build. */
|
|
89
|
+
snapshot?: RecordSnapshot;
|
|
77
90
|
}
|
|
78
91
|
/** Builds validated and sanitized LogRecord instances from logger inputs. */
|
|
79
92
|
export declare class RecordBuilder {
|
|
@@ -95,6 +108,12 @@ export declare class RecordBuilder {
|
|
|
95
108
|
* @returns True if the library builds a record of this level and type.
|
|
96
109
|
*/
|
|
97
110
|
isEnabled(level: LogLevel, namespace: string, type?: LogType): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Keeps a record that minLevel or sampling dropped, when the debug buffer is on. The privacy
|
|
113
|
+
* hooks run now. An error record of this context sends the kept record later.
|
|
114
|
+
* @param input Input of the dropped record.
|
|
115
|
+
*/
|
|
116
|
+
private keepForDebug;
|
|
98
117
|
/**
|
|
99
118
|
* Builds a structured LogRecord from the input. It sanitizes attributes and applies size limits.
|
|
100
119
|
* @param input Logger call input parameters.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { REMOTE_SAMPLING_VERSION } from "../constants";
|
|
2
|
-
import type { ResolvedConfig } from "../models/config";
|
|
2
|
+
import type { RemoteCaptureFlag, ResolvedConfig } from "../models/config";
|
|
3
3
|
import type { LogLevel } from "../models/log-record";
|
|
4
4
|
/** Sampling rules from the ingest server, after validation. */
|
|
5
5
|
export interface RemoteRules {
|
|
@@ -7,6 +7,8 @@ export interface RemoteRules {
|
|
|
7
7
|
defaultRate?: number;
|
|
8
8
|
/** Rate for each namespace prefix. They apply over the config rates. */
|
|
9
9
|
rates: Record<string, number>;
|
|
10
|
+
/** Temporary capture switches. Each context applies its own allowlist. */
|
|
11
|
+
capture?: Partial<Record<RemoteCaptureFlag, boolean>>;
|
|
10
12
|
/** Lowest level that the library sends. It can only lower `minLevel`. */
|
|
11
13
|
minLevel?: LogLevel;
|
|
12
14
|
/** Lowest level for each namespace prefix. It can only lower the level of the config. */
|
|
@@ -30,6 +32,8 @@ export interface RemoteWire extends RemoteRules {
|
|
|
30
32
|
export interface RemoteSlot {
|
|
31
33
|
/** Overlay, or null before the first rules. */
|
|
32
34
|
sampling: RemoteSampling | null;
|
|
35
|
+
/** Refreshes captures after a trusted rule update. */
|
|
36
|
+
changed?: () => void;
|
|
33
37
|
}
|
|
34
38
|
/** Remote sampling rules in force for this context. */
|
|
35
39
|
export declare class RemoteSampling {
|
package/dist/core/runtime.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import type { Receive, WorkerLike } from "../bus/links";
|
|
|
2
2
|
import type { BusMessage } from "../models/bus";
|
|
3
3
|
import type { FrameOptions, SourceOptions } from "../models/bus";
|
|
4
4
|
import type { ObservabilityConfig, ResolvedConfig, SecurityContextUpdate, SecurityContextRotationOptions } from "../models/config";
|
|
5
|
-
import type { InstrumentDef, MetricAttributes } from "../models/metric";
|
|
5
|
+
import type { InstrumentDef, Measure, MetricAttributes } from "../models/metric";
|
|
6
6
|
import { type LogRecord } from "../models/log-record";
|
|
7
7
|
import type { DeliveryStats } from "../models/stats";
|
|
8
|
-
import type { ObservabilityHealth } from "../models/health";
|
|
8
|
+
import type { DebugBundle, ObservabilityHealth } from "../models/health";
|
|
9
9
|
import { ConsoleSink } from "../utils/console";
|
|
10
10
|
import { type Identity } from "../utils/identity";
|
|
11
11
|
import { type PlatformMetadata } from "../utils/platform";
|
|
@@ -30,6 +30,14 @@ export declare class ObservabilityRuntime {
|
|
|
30
30
|
private rotation?;
|
|
31
31
|
/** Memory store kept for later context changes. */
|
|
32
32
|
private memoryStorage?;
|
|
33
|
+
/** State of the request for persistent storage. getHealth() reports it. */
|
|
34
|
+
private storagePersistence;
|
|
35
|
+
/** True while a diagnostic record goes out. A diagnostic during that time gives no record. */
|
|
36
|
+
private recordingDiagnostic;
|
|
37
|
+
/** Logger of the records that diagnostics.records gives. */
|
|
38
|
+
private readonly diagnosticLogger;
|
|
39
|
+
/** Records that minLevel or sampling dropped. An error of this context sends them first. */
|
|
40
|
+
private readonly debugBuffer;
|
|
33
41
|
/** True if the app supplied a context id at startup. */
|
|
34
42
|
private explicitSecurityContext;
|
|
35
43
|
/** True after this forwarder takes a context id from its owner. */
|
|
@@ -83,6 +91,12 @@ export declare class ObservabilityRuntime {
|
|
|
83
91
|
readonly builder: RecordBuilder;
|
|
84
92
|
/** Slot of the remote sampling rules. The sender or the bus fills it. */
|
|
85
93
|
private readonly remote;
|
|
94
|
+
/** Count of delivery identity changes. The first id of a context is not a change. */
|
|
95
|
+
private identityEpoch;
|
|
96
|
+
/** Timer that restores the local capture switches after the remote TTL. */
|
|
97
|
+
private remoteCaptureTimer;
|
|
98
|
+
/** Settings of the current capture load or install. */
|
|
99
|
+
private installedCaptureKey;
|
|
86
100
|
/** Console sink for local developer output. */
|
|
87
101
|
readonly console: ConsoleSink;
|
|
88
102
|
/** Collects lost records into onDrop summaries. */
|
|
@@ -151,6 +165,18 @@ export declare class ObservabilityRuntime {
|
|
|
151
165
|
* @param mismatch True for a console-only runtime next to another version.
|
|
152
166
|
*/
|
|
153
167
|
private constructor();
|
|
168
|
+
/**
|
|
169
|
+
* Gives the handler of the diagnostics. With diagnostics.records, it also sends each event
|
|
170
|
+
* as a record.
|
|
171
|
+
* @returns The handler, or undefined without onDiagnostic and without diagnostic records.
|
|
172
|
+
*/
|
|
173
|
+
private diagnosticHandler;
|
|
174
|
+
/**
|
|
175
|
+
* Sends a diagnostic event as a record when diagnostics.records selects its code.
|
|
176
|
+
* A diagnostic during that send gives no record. That stops a loop.
|
|
177
|
+
* @param event Diagnostic event.
|
|
178
|
+
*/
|
|
179
|
+
private recordDiagnostic;
|
|
154
180
|
/**
|
|
155
181
|
* Adds a breadcrumb from app code. It copies the data now. A later change of the object of the
|
|
156
182
|
* app then does not change the trail.
|
|
@@ -166,6 +192,13 @@ export declare class ObservabilityRuntime {
|
|
|
166
192
|
* @param attributes Attribute set of the value.
|
|
167
193
|
*/
|
|
168
194
|
recordMetric(def: InstrumentDef, value: number, attributes?: MetricAttributes): void;
|
|
195
|
+
/**
|
|
196
|
+
* Starts a timed operation. A shutdown or a new delivery identity before its end drops its values.
|
|
197
|
+
* @param name Operation name.
|
|
198
|
+
* @param attributes Attribute set of each histogram point.
|
|
199
|
+
* @returns The handle of the operation.
|
|
200
|
+
*/
|
|
201
|
+
startMeasure(name: string, attributes?: MetricAttributes): Measure;
|
|
169
202
|
/**
|
|
170
203
|
* Builds and emits the record of one span. The console does not print it. minLevel does not
|
|
171
204
|
* drop it. The trace engine sampled the trace before the span existed.
|
|
@@ -326,6 +359,10 @@ export declare class ObservabilityRuntime {
|
|
|
326
359
|
private loadSender;
|
|
327
360
|
/** Imports and builds the delivery stack. It then moves the held records into it. It never rejects. */
|
|
328
361
|
private buildSender;
|
|
362
|
+
/** Refreshes temporary switches and restores local settings when their TTL ends. */
|
|
363
|
+
private refreshCaptures;
|
|
364
|
+
/** Returns local capture settings with the permitted remote switches. */
|
|
365
|
+
private effectiveCapture;
|
|
329
366
|
/** Loads, builds and installs the enabled capture modules. It never rejects. */
|
|
330
367
|
private installCaptures;
|
|
331
368
|
/** Uninstalls the active capture modules. */
|
|
@@ -448,6 +485,12 @@ export declare class ObservabilityRuntime {
|
|
|
448
485
|
* @returns Promise that resolves when the stored batches are stored again.
|
|
449
486
|
*/
|
|
450
487
|
private carry;
|
|
488
|
+
/**
|
|
489
|
+
* Collects the state of this runtime for a support ticket. The app decides where to send it.
|
|
490
|
+
* @param health Health snapshot from the facade, with the logger cache counts.
|
|
491
|
+
* @returns Promise that resolves to the JSON-safe bundle.
|
|
492
|
+
*/
|
|
493
|
+
debugBundle(health: ObservabilityHealth): Promise<DebugBundle>;
|
|
451
494
|
/**
|
|
452
495
|
* Reads the state of this runtime. It does not wait for startup or the sender to load.
|
|
453
496
|
* @returns State, delivery counts and policies. The facade adds the logger cache counts.
|
package/dist/core/sampling.d.ts
CHANGED
|
@@ -65,21 +65,22 @@ export declare function shouldSampleInput(input: SampleInput, config: ResolvedCo
|
|
|
65
65
|
*/
|
|
66
66
|
export declare function shouldSample(record: LogRecord, config: ResolvedConfig, remote?: RemoteRules | null): boolean;
|
|
67
67
|
/**
|
|
68
|
-
* Sets a fixed-window limit on the
|
|
68
|
+
* Sets a fixed-window limit on the records that bypass sampling by their level.
|
|
69
69
|
*
|
|
70
70
|
* ErrorCapture already limits auto-captured errors. This class limits the remaining case.
|
|
71
71
|
* An example is application code that calls logger.error in a render loop.
|
|
72
72
|
*/
|
|
73
73
|
export declare class ErrorCeiling {
|
|
74
|
-
/**
|
|
74
|
+
/** Records at or above the threshold level admitted in the current window. */
|
|
75
75
|
private readonly window;
|
|
76
76
|
/**
|
|
77
|
-
* Checks a record against the limit. It counts only
|
|
77
|
+
* Checks a record against the limit. It counts only records at or above `from`.
|
|
78
78
|
* @param record Record about to enter a stream.
|
|
79
79
|
* @param limit Maximum records in one window. Set 0 for no limit.
|
|
80
80
|
* @param windowMs Rate limit window, in milliseconds.
|
|
81
|
+
* @param from Lowest level that bypasses sampling.
|
|
81
82
|
* @returns False when the window has no allowance left. The caller must drop the record.
|
|
82
83
|
*/
|
|
83
|
-
allow(record: LogRecord, limit?: number, windowMs?: number): boolean;
|
|
84
|
+
allow(record: LogRecord, limit?: number, windowMs?: number, from?: LogLevel): boolean;
|
|
84
85
|
}
|
|
85
86
|
export {};
|
package/dist/core/sender.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { ResolvedConfig } from "../models/config";
|
|
|
3
3
|
import type { LossReporter } from "../models/drop";
|
|
4
4
|
import type { LogRecord } from "../models/log-record";
|
|
5
5
|
import type { DeliveryStats } from "../models/stats";
|
|
6
|
-
import { type GapReporter, type StorageAdapter } from "../models/storage";
|
|
6
|
+
import { type GapReporter, type StorageAdapter, type StoragePersistence } from "../models/storage";
|
|
7
7
|
import type { Diagnostics } from "./diagnostics";
|
|
8
8
|
import type { RemoteSlot } from "./remote-sampling";
|
|
9
9
|
/** Inputs to build the delivery stack. */
|
|
@@ -11,6 +11,8 @@ export interface SenderDeps {
|
|
|
11
11
|
/** Memory store that this runtime keeps when the security context changes. */
|
|
12
12
|
storage?: StorageAdapter;
|
|
13
13
|
onStorage?: (storage: StorageAdapter) => void;
|
|
14
|
+
/** Receives the state of the request for persistent storage. */
|
|
15
|
+
onPersistence?: (state: StoragePersistence) => void;
|
|
14
16
|
/** Active configuration instance. */
|
|
15
17
|
config: ResolvedConfig;
|
|
16
18
|
/** Diagnostics reporter. */
|
package/dist/core/spans.d.ts
CHANGED
|
@@ -19,6 +19,11 @@ export interface SpanData {
|
|
|
19
19
|
error: boolean;
|
|
20
20
|
/** Attributes of the span. */
|
|
21
21
|
attributes: Record<string, unknown>;
|
|
22
|
+
/** Server span linked through a response traceparent entry. */
|
|
23
|
+
link?: {
|
|
24
|
+
traceId: string;
|
|
25
|
+
spanId: string;
|
|
26
|
+
};
|
|
22
27
|
}
|
|
23
28
|
/**
|
|
24
29
|
* Builds the root span of an ambient trace that ended.
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// src/utils/unref.ts
|
|
2
2
|
function e(e) {
|
|
3
3
|
typeof e != "number" && e.unref?.();
|
|
4
4
|
}
|
|
5
|
-
|
|
6
|
-
//#region src/utils/deadline.ts
|
|
5
|
+
// src/utils/deadline.ts
|
|
7
6
|
var t = class extends Error {
|
|
8
7
|
constructor(e) {
|
|
9
8
|
super(`The operation took longer than ${String(e)} ms.`), this.name = "DeadlineError";
|
|
@@ -20,7 +19,6 @@ function n(n, r) {
|
|
|
20
19
|
clearTimeout(i);
|
|
21
20
|
});
|
|
22
21
|
}
|
|
23
|
-
//#endregion
|
|
24
22
|
export { n, e as r, t };
|
|
25
23
|
|
|
26
|
-
//# sourceMappingURL=deadline-
|
|
24
|
+
//# sourceMappingURL=deadline-BOjOxNHj.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deadline-
|
|
1
|
+
{"version":3,"file":"deadline-BOjOxNHj.js","names":["unrefTimer","timer","DeadlineError","ms","withDeadline","expire","deadline","work"],"sources":["../src/utils/unref.ts","../src/utils/deadline.ts"],"sourcesContent":["// src/utils/unref.ts\n//\n// Unreferences timer handles in Node and browser environments. A pending timer\n// keeps a Node process alive under SSR and in tests.\n\n/** Timer handle. It is a number in a browser and a Timeout object in Node. */\nexport type TimerHandle = number | { unref?: () => void };\n\n/**\n * Unreferences a timer handle. A pending timer then does not keep a Node.js process alive.\n * @param timer Timer handle returned by setTimeout.\n */\nexport function unrefTimer(timer: TimerHandle): void {\n if (typeof timer !== \"number\") {\n timer.unref?.();\n }\n}\n","// src/utils/deadline.ts\n//\n// Sets a deadline for a promise that can stay pending. A pending promise raises no\n// diagnostics event. Without a deadline, its caller waits forever and keeps its slot.\n\nimport { unrefTimer } from \"./unref\";\n\n/** Error of a promise that did not settle before its deadline. */\nexport class DeadlineError extends Error {\n /**\n * @param ms Deadline in milliseconds.\n */\n constructor(ms: number) {\n super(`The operation took longer than ${String(ms)} ms.`);\n this.name = \"DeadlineError\";\n }\n}\n\n/**\n * Rejects when a promise does not settle within a deadline.\n * @param work Promise to bound.\n * @param ms Deadline in milliseconds.\n * @returns The value of the promise, or a rejection after the deadline.\n */\nexport function withDeadline<T>(work: Promise<T>, ms: number): Promise<T> {\n let expire: ReturnType<typeof setTimeout> | undefined;\n\n const deadline = new Promise<never>((_resolve, reject) => {\n const timer = setTimeout(() => {\n reject(new DeadlineError(ms));\n }, ms);\n\n expire = timer;\n unrefTimer(timer);\n });\n\n // Clear the timer on success and on failure. If not, each storage call leaves an armed timer.\n return Promise.race([work, deadline]).finally(() => {\n clearTimeout(expire);\n });\n}\n"],"mappings":";AAYA,SAAgBA,EAAW,GAA0B;CACnD,AAAI,OAAOC,KAAU,YACnBA,EAAM,QAAQ;AAElB;;ACRA,IAAaC,IAAb,cAAmC,MAAM;CAIvC,YAAY,GAAY;EAEtB,AADA,MAAM,kCAAkC,OAAOC,CAAE,EAAE,KAAK,GACxD,KAAK,OAAO;CACd;AACF;AAQA,SAAgBC,EAAgB,GAAkB,GAAwB;CACxE,IAAIC,GAEEC,IAAW,IAAI,SAAgB,GAAU,MAAW;EACxD,IAAML,IAAQ,iBAAiB;GAC7B,EAAO,IAAIC,EAAcC,CAAE,CAAC;EAC9B,GAAGA,CAAE;EAGL,AADA,IAASF,GACTD,EAAWC,CAAK;CAClB,CAAC;CAGD,OAAO,QAAQ,KAAK,CAACM,GAAMD,CAAQ,CAAC,CAAC,CAAC,cAAc;EAClD,aAAaD,CAAM;CACrB,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deadline-XSnm95pg.cjs","names":["unrefTimer","timer","DeadlineError","ms","withDeadline","expire","deadline","reject","work"],"sources":["../src/utils/unref.ts","../src/utils/deadline.ts"],"sourcesContent":["// src/utils/unref.ts\n//\n// Unreferences timer handles in Node and browser environments. A pending timer\n// keeps a Node process alive under SSR and in tests.\n\n/** Timer handle. It is a number in a browser and a Timeout object in Node. */\nexport type TimerHandle = number | { unref?: () => void };\n\n/**\n * Unreferences a timer handle. A pending timer then does not keep a Node.js process alive.\n * @param timer Timer handle returned by setTimeout.\n */\nexport function unrefTimer(timer: TimerHandle): void {\n if (typeof timer !== \"number\") {\n timer.unref?.();\n }\n}\n","// src/utils/deadline.ts\n//\n// Sets a deadline for a promise that can stay pending. A pending promise raises no\n// diagnostics event. Without a deadline, its caller waits forever and keeps its slot.\n\nimport { unrefTimer } from \"./unref\";\n\n/** Error of a promise that did not settle before its deadline. */\nexport class DeadlineError extends Error {\n /**\n * @param ms Deadline in milliseconds.\n */\n constructor(ms: number) {\n super(`The operation took longer than ${String(ms)} ms.`);\n this.name = \"DeadlineError\";\n }\n}\n\n/**\n * Rejects when a promise does not settle within a deadline.\n * @param work Promise to bound.\n * @param ms Deadline in milliseconds.\n * @returns The value of the promise, or a rejection after the deadline.\n */\nexport function withDeadline<T>(work: Promise<T>, ms: number): Promise<T> {\n let expire: ReturnType<typeof setTimeout> | undefined;\n\n const deadline = new Promise<never>((_resolve, reject) => {\n const timer = setTimeout(() => {\n reject(new DeadlineError(ms));\n }, ms);\n\n expire = timer;\n unrefTimer(timer);\n });\n\n // Clear the timer on success and on failure. If not, each storage call leaves an armed timer.\n return Promise.race([work, deadline]).finally(() => {\n clearTimeout(expire);\n });\n}\n"],"mappings":"AAYA,SAAgBA,EAAW,EAA0B,CAC/C,OAAOC,GAAU,UACnBA,EAAM,QAAQ,CAElB,CCRA,IAAaC,EAAb,cAAmC,KAAM,CAIvC,YAAY,EAAY,CACtB,MAAM,kCAAkC,OAAOC,CAAE,EAAE,KAAK,EACxD,KAAK,KAAO,eACd,CACF,EAQA,SAAgBC,EAAgB,EAAkB,EAAwB,CACxE,IAAIC,EAEEC,EAAW,IAAI,SAAgB,EAAU,IAAW,CACxD,IAAML,EAAQ,eAAiB,CAC7BM,EAAO,IAAIL,EAAcC,CAAE,CAAC,CAC9B,EAAGA,CAAE,EAEL,EAASF,EACTD,EAAWC,CAAK,CAClB,CAAC,EAGD,OAAO,QAAQ,KAAK,CAACO,EAAMF,CAAQ,CAAC,CAAC,CAAC,YAAc,CAClD,aAAaD,CAAM,CACrB,CAAC,CACH"}
|
|
1
|
+
{"version":3,"file":"deadline-XSnm95pg.cjs","names":["unrefTimer","timer","DeadlineError","ms","withDeadline","expire","deadline","reject","work"],"sources":["../src/utils/unref.ts","../src/utils/deadline.ts"],"sourcesContent":["// src/utils/unref.ts\n//\n// Unreferences timer handles in Node and browser environments. A pending timer\n// keeps a Node process alive under SSR and in tests.\n\n/** Timer handle. It is a number in a browser and a Timeout object in Node. */\nexport type TimerHandle = number | { unref?: () => void };\n\n/**\n * Unreferences a timer handle. A pending timer then does not keep a Node.js process alive.\n * @param timer Timer handle returned by setTimeout.\n */\nexport function unrefTimer(timer: TimerHandle): void {\n if (typeof timer !== \"number\") {\n timer.unref?.();\n }\n}\n","// src/utils/deadline.ts\n//\n// Sets a deadline for a promise that can stay pending. A pending promise raises no\n// diagnostics event. Without a deadline, its caller waits forever and keeps its slot.\n\nimport { unrefTimer } from \"./unref\";\n\n/** Error of a promise that did not settle before its deadline. */\nexport class DeadlineError extends Error {\n /**\n * @param ms Deadline in milliseconds.\n */\n constructor(ms: number) {\n super(`The operation took longer than ${String(ms)} ms.`);\n this.name = \"DeadlineError\";\n }\n}\n\n/**\n * Rejects when a promise does not settle within a deadline.\n * @param work Promise to bound.\n * @param ms Deadline in milliseconds.\n * @returns The value of the promise, or a rejection after the deadline.\n */\nexport function withDeadline<T>(work: Promise<T>, ms: number): Promise<T> {\n let expire: ReturnType<typeof setTimeout> | undefined;\n\n const deadline = new Promise<never>((_resolve, reject) => {\n const timer = setTimeout(() => {\n reject(new DeadlineError(ms));\n }, ms);\n\n expire = timer;\n unrefTimer(timer);\n });\n\n // Clear the timer on success and on failure. If not, each storage call leaves an armed timer.\n return Promise.race([work, deadline]).finally(() => {\n clearTimeout(expire);\n });\n}\n"],"mappings":"AAYA,SAAgBA,EAAW,EAA0B,CAC/C,OAAOC,GAAU,UACnBA,EAAM,QAAQ,CAElB,CCRA,IAAaC,EAAb,cAAmC,KAAM,CAIvC,YAAY,EAAY,CACtB,MAAM,kCAAkC,OAAOC,CAAE,EAAE,KAAK,EACxD,KAAK,KAAO,eACd,CACF,EAQA,SAAgBC,EAAgB,EAAkB,EAAwB,CACxE,IAAIC,EAEEC,EAAW,IAAI,SAAgB,EAAU,IAAW,CACxD,IAAML,EAAQ,eAAiB,CAC7BM,EAAO,IAAIL,EAAcC,CAAE,CAAC,CAC9B,EAAGA,CAAE,EAEL,EAASF,EACTD,EAAWC,CAAK,CAClB,CAAC,EAGD,OAAO,QAAQ,KAAK,CAACO,EAAMF,CAAQ,CAAC,CAAC,CAAC,YAAc,CAClD,aAAaD,CAAM,CACrB,CAAC,CACH,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./guards-nJ70syPt.cjs"),t=require("./platform-C2Ez5kDc.cjs"),n=require("./sanitize-BAWzkZt0.cjs");function r(n){return typeof n==`string`?/^[a-z][a-z\d+.-]*:\/\//i.test(n)?t.i(n,!1):n:Array.isArray(n)?n.map(r):e.t(n)?Object.fromEntries(Object.entries(n).map(([e,t])=>[e,r(t)])):n}function i(e,i,a){let o=e=>typeof e==`string`?t.i(e,!1):e,{capture:s,serializer:c}=e,l={...e,endpoint:o(e.endpoint),metricsEndpoint:o(e.metricsEndpoint),tracesEndpoint:o(e.tracesEndpoint),serializer:typeof c==`string`?c:c.name,capture:{...s,ignoreUrls:s.ignoreUrls.map(o),plugins:s.plugins.map(e=>e.name)}};return Reflect.deleteProperty(l,`headers`),r(n.n(l,i,a))}exports.configSummary=i;
|
|
2
|
+
//# sourceMappingURL=debug-bundle-BzJNpbF0.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-bundle-BzJNpbF0.cjs","names":["recordedUrl","isObject","sanitize","require_guards","require_platform","require_sanitize","stripUrls","value","key","entry","configSummary","cut","config","copy","serializer","capture","plugin","limits","diagnostics"],"sources":["../src/core/debug-bundle.ts"],"sourcesContent":["// src/core/debug-bundle.ts\n//\n// Makes the config summary of a debug bundle. The runtime loads this module only when the app\n// asks for a bundle.\n\nimport type { ResolvedConfig } from \"../models/config\";\nimport { isObject } from \"../utils/guards\";\nimport { recordedUrl } from \"../utils/platform\";\nimport { sanitize, type SanitizeLimits } from \"../utils/sanitize\";\nimport type { Diagnostics } from \"./diagnostics\";\n\n/**\n * Removes the user info, query and fragment of each absolute URL in a JSON-safe value. The\n * library also puts the endpoints into `capture.ignoreUrls`.\n * @param value JSON-safe value.\n * @returns The value with each URL cut.\n */\nfunction stripUrls(value: unknown): unknown {\n if (typeof value === \"string\") {\n return /^[a-z][a-z\\d+.-]*:\\/\\//i.test(value) ? recordedUrl(value, false) : value;\n }\n\n if (Array.isArray(value)) {\n return value.map(stripUrls);\n }\n\n if (isObject(value)) {\n return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, stripUrls(entry)]));\n }\n\n return value;\n}\n\n/**\n * Copies the config for a support ticket. It leaves out the headers and cuts each URL. A function\n * becomes its name, and a RegExp its text.\n * @param config Active configuration.\n * @param limits Limits of the copy, as for record attributes.\n * @param diagnostics Diagnostics reporter.\n * @returns JSON-safe copy of the config.\n */\nexport function configSummary(\n config: ResolvedConfig,\n limits: SanitizeLimits,\n diagnostics: Diagnostics,\n): Record<string, unknown> {\n // A relative endpoint has no scheme. stripUrls() does not see it as a URL.\n const cut = (value: unknown): unknown =>\n typeof value === \"string\" ? recordedUrl(value, false) : value;\n const { capture, serializer } = config;\n const copy: Record<string, unknown> = {\n ...config,\n endpoint: cut(config.endpoint),\n metricsEndpoint: cut(config.metricsEndpoint),\n tracesEndpoint: cut(config.tracesEndpoint),\n // An object of the app can hold a key in any field. Only its name goes out.\n serializer: typeof serializer === \"string\" ? serializer : serializer.name,\n capture: {\n ...capture,\n ignoreUrls: capture.ignoreUrls.map(cut),\n plugins: capture.plugins.map((plugin) => plugin.name),\n },\n };\n // Static headers can hold a token.\n Reflect.deleteProperty(copy, \"headers\");\n\n return stripUrls(sanitize(copy, limits, diagnostics)) as Record<string, unknown>;\n}\n"],"mappings":"A,mHAiBA,SAASM,EAAU,EAAyB,CAa1C,OAZI,OAAOC,GAAU,SACZ,0BAA0B,KAAKA,CAAK,EAAIP,EAAAA,EAAYO,EAAO,EAAK,EAAIA,EAGzE,MAAM,QAAQA,CAAK,EACdA,EAAM,IAAID,CAAS,EAGxBL,EAAAA,EAASM,CAAK,EACT,OAAO,YAAY,OAAO,QAAQA,CAAK,CAAC,CAAC,KAAK,CAACC,EAAKC,KAAW,CAACD,EAAKF,EAAUG,CAAK,CAAC,CAAC,CAAC,EAGzFF,CACT,CAUA,SAAgBG,EACd,EACA,EACA,EACyB,CAEzB,IAAMC,EAAO,GACX,OAAOJ,GAAU,SAAWP,EAAAA,EAAYO,EAAO,EAAK,EAAIA,EACpD,CAAE,UAAS,cAAeK,EAC1BC,EAAgC,CACpC,GAAGD,EACH,SAAUD,EAAIC,EAAO,QAAQ,EAC7B,gBAAiBD,EAAIC,EAAO,eAAe,EAC3C,eAAgBD,EAAIC,EAAO,cAAc,EAEzC,WAAY,OAAOE,GAAe,SAAWA,EAAaA,EAAW,KACrE,QAAS,CACP,GAAGC,EACH,WAAYA,EAAQ,WAAW,IAAIJ,CAAG,EACtC,QAASI,EAAQ,QAAQ,IAAK,GAAWC,EAAO,IAAI,CACtD,CACF,EAIA,OAFA,QAAQ,eAAeH,EAAM,SAAS,EAE/BP,EAAUJ,EAAAA,EAASW,EAAMI,EAAQC,CAAW,CAAC,CACtD,C"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { t as e } from "./guards-Cidk71ME.js";
|
|
2
|
+
import { i as t } from "./platform-DkcuXwe-.js";
|
|
3
|
+
import { n } from "./sanitize-6ymPlVvP.js";
|
|
4
|
+
// src/core/debug-bundle.ts
|
|
5
|
+
function r(n) {
|
|
6
|
+
return typeof n == "string" ? /^[a-z][a-z\d+.-]*:\/\//i.test(n) ? t(n, !1) : n : Array.isArray(n) ? n.map(r) : e(n) ? Object.fromEntries(Object.entries(n).map(([e, t]) => [e, r(t)])) : n;
|
|
7
|
+
}
|
|
8
|
+
function i(e, i, a) {
|
|
9
|
+
let o = (e) => typeof e == "string" ? t(e, !1) : e, { capture: s, serializer: c } = e, l = {
|
|
10
|
+
...e,
|
|
11
|
+
endpoint: o(e.endpoint),
|
|
12
|
+
metricsEndpoint: o(e.metricsEndpoint),
|
|
13
|
+
tracesEndpoint: o(e.tracesEndpoint),
|
|
14
|
+
serializer: typeof c == "string" ? c : c.name,
|
|
15
|
+
capture: {
|
|
16
|
+
...s,
|
|
17
|
+
ignoreUrls: s.ignoreUrls.map(o),
|
|
18
|
+
plugins: s.plugins.map((e) => e.name)
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
return Reflect.deleteProperty(l, "headers"), r(n(l, i, a));
|
|
22
|
+
}
|
|
23
|
+
export { i as configSummary };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=debug-bundle-C7UkHZ-q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-bundle-C7UkHZ-q.js","names":["isObject","recordedUrl","stripUrls","value","key","entry","configSummary","cut","config","copy","serializer","capture","plugin","sanitize","limits","diagnostics"],"sources":["../src/core/debug-bundle.ts"],"sourcesContent":["// src/core/debug-bundle.ts\n//\n// Makes the config summary of a debug bundle. The runtime loads this module only when the app\n// asks for a bundle.\n\nimport type { ResolvedConfig } from \"../models/config\";\nimport { isObject } from \"../utils/guards\";\nimport { recordedUrl } from \"../utils/platform\";\nimport { sanitize, type SanitizeLimits } from \"../utils/sanitize\";\nimport type { Diagnostics } from \"./diagnostics\";\n\n/**\n * Removes the user info, query and fragment of each absolute URL in a JSON-safe value. The\n * library also puts the endpoints into `capture.ignoreUrls`.\n * @param value JSON-safe value.\n * @returns The value with each URL cut.\n */\nfunction stripUrls(value: unknown): unknown {\n if (typeof value === \"string\") {\n return /^[a-z][a-z\\d+.-]*:\\/\\//i.test(value) ? recordedUrl(value, false) : value;\n }\n\n if (Array.isArray(value)) {\n return value.map(stripUrls);\n }\n\n if (isObject(value)) {\n return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, stripUrls(entry)]));\n }\n\n return value;\n}\n\n/**\n * Copies the config for a support ticket. It leaves out the headers and cuts each URL. A function\n * becomes its name, and a RegExp its text.\n * @param config Active configuration.\n * @param limits Limits of the copy, as for record attributes.\n * @param diagnostics Diagnostics reporter.\n * @returns JSON-safe copy of the config.\n */\nexport function configSummary(\n config: ResolvedConfig,\n limits: SanitizeLimits,\n diagnostics: Diagnostics,\n): Record<string, unknown> {\n // A relative endpoint has no scheme. stripUrls() does not see it as a URL.\n const cut = (value: unknown): unknown =>\n typeof value === \"string\" ? recordedUrl(value, false) : value;\n const { capture, serializer } = config;\n const copy: Record<string, unknown> = {\n ...config,\n endpoint: cut(config.endpoint),\n metricsEndpoint: cut(config.metricsEndpoint),\n tracesEndpoint: cut(config.tracesEndpoint),\n // An object of the app can hold a key in any field. Only its name goes out.\n serializer: typeof serializer === \"string\" ? serializer : serializer.name,\n capture: {\n ...capture,\n ignoreUrls: capture.ignoreUrls.map(cut),\n plugins: capture.plugins.map((plugin) => plugin.name),\n },\n };\n // Static headers can hold a token.\n Reflect.deleteProperty(copy, \"headers\");\n\n return stripUrls(sanitize(copy, limits, diagnostics)) as Record<string, unknown>;\n}\n"],"mappings":";;;;AAiBA,SAASE,EAAU,GAAyB;CAa1C,OAZI,OAAOC,KAAU,WACZ,0BAA0B,KAAKA,CAAK,IAAIF,EAAYE,GAAO,EAAK,IAAIA,IAGzE,MAAM,QAAQA,CAAK,IACdA,EAAM,IAAID,CAAS,IAGxBF,EAASG,CAAK,IACT,OAAO,YAAY,OAAO,QAAQA,CAAK,CAAC,CAAC,KAAK,CAACC,GAAKC,OAAW,CAACD,GAAKF,EAAUG,CAAK,CAAC,CAAC,CAAC,IAGzFF;AACT;AAUA,SAAgBG,EACd,GACA,GACA,GACyB;CAEzB,IAAMC,KAAO,MACX,OAAOJ,KAAU,WAAWF,EAAYE,GAAO,EAAK,IAAIA,GACpD,EAAE,YAAS,kBAAeK,GAC1BC,IAAgC;EACpC,GAAGD;EACH,UAAUD,EAAIC,EAAO,QAAQ;EAC7B,iBAAiBD,EAAIC,EAAO,eAAe;EAC3C,gBAAgBD,EAAIC,EAAO,cAAc;EAEzC,YAAY,OAAOE,KAAe,WAAWA,IAAaA,EAAW;EACrE,SAAS;GACP,GAAGC;GACH,YAAYA,EAAQ,WAAW,IAAIJ,CAAG;GACtC,SAASI,EAAQ,QAAQ,KAAK,MAAWC,EAAO,IAAI;EACtD;CACF;CAIA,OAFA,QAAQ,eAAeH,GAAM,SAAS,GAE/BP,EAAUW,EAASJ,GAAMK,GAAQC,CAAW,CAAC;AACtD"}
|
package/dist/doctor.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./constants-DqKJH_MP.cjs"),t=require("./otlp-BDvFrLnc.cjs");var n=1e4,r=0,i=1,a=2,o=`Usage: uiobs doctor <url> --origin <origin>. An origin has no path and no trailing slash.`,s=`Access-Control-Expose-Headers`,c=[e.lt,e.ct,e.st,e.ot].map(e=>e.toLowerCase()),l=[e.ft,e.ut].map(e=>e.toLowerCase());function u(){let t=crypto.randomUUID().replaceAll(`-`,``);return{timeUnixNano:`${String(Date.now())}000000`,traceId:t,spanId:t.slice(0,16),traceFlags:1,severityNumber:e.bn.INFO,severityText:`INFO`,body:`uiobs doctor test record`,attributes:{},resource:{"service.name":`uiobs-doctor`}}}async function d(e,t){try{return await fetch(e,{...t,redirect:`manual`,signal:AbortSignal.timeout(n)})}catch(e){let t=e instanceof Error?e.cause??e:e;return`The request failed. ${t instanceof Error?t.message:String(t)}`}}function f(e,t,n){let r=(e.headers.get(t)??``).toLowerCase().split(`,`).map(e=>e.trim());return r.includes(`*`)?[]:n.filter(e=>!r.includes(e))}var p=e=>e.ok?void 0:`The server returned ${String(e.status)}.`;function m(e,t,n,...r){let i=typeof t==`string`?t:r.map(e=>e(t)).find(e=>e!==void 0);return{rule:e,pass:i===void 0,detail:i??n}}async function h(n,r){let i=e=>{let t=e.headers.get(`Access-Control-Allow-Origin`);return t===r||t===`*`?void 0:`Access-Control-Allow-Origin is ${String(t)}. It must allow ${r}.`},a=await d(n,{method:`OPTIONS`,headers:{Origin:r,"Access-Control-Request-Method":`POST`,"Access-Control-Request-Headers":c.join(`, `)}}),{body:o,contentType:h}=t.r.serialize([u()]),g=(t,i,a,o={})=>d(n,{method:`POST`,headers:{Origin:r,[e.lt]:h,[e.st]:t,[e.ot]:String(i),...o},body:a}),_=crypto.randomUUID(),v=await g(_,0,o),y=await g(_,1,o),b=await t.a(o),x=b?await g(crypto.randomUUID(),0,b,{[e.ct]:e.tt}):`This Node version has no CompressionStream.`,S=typeof v==`string`?[]:f(v,s,l),C=S.length>0?` Optional headers stay hidden: ${S.join(`, `)}.`:``;return[m(`preflight`,a,`The server permits POST from this origin.`,p,i),m(`allowed headers`,a,`The server allows each request header of the library.`,e=>{let t=f(e,`Access-Control-Allow-Headers`,c);return t.length>0?`Access-Control-Allow-Headers must include ${t.join(`, `)}.`:void 0}),m(`test batch`,v,`The server accepted a test batch.`,p,i),m(`exposed headers`,v,`The server exposes Retry-After.${C}`,e=>f(e,s,[`retry-after`]).length>0?`${s} must include retry-after.`:void 0),m(`gzip`,x,`The server accepted a gzip batch.`,p),m(`deduplication`,y,`The server accepted a repeated batch id. A client cannot see if it stored the batch again.`,p)]}function g(e){return/^https?:\/\//i.test(e)&&URL.canParse(e)}function _(e){return URL.canParse(e)&&new URL(e).origin===e}async function v(e,t){let[n,s,c,l]=e;if(n!==`doctor`||c!==`--origin`||!g(s)||!_(l))return t(o),t(`Received: ${JSON.stringify(e)}`),a;let u=await h(s,l);for(let{rule:e,pass:n,detail:r}of u)t(`${n?`PASS`:`FAIL`} ${e}: ${r}`);return u.every(({pass:e})=>e)?r:i}exports.main=v,exports.runDoctor=h;
|
|
2
|
+
//# sourceMappingURL=doctor.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doctor.cjs","names":["HEADER_CONTENT_TYPE","HEADER_CONTENT_ENCODING","HEADER_BATCH_ID","HEADER_ATTEMPT","HEADER_SAMPLING","HEADER_DATE","SEVERITY_NUMBER","otlpSerializer","gzip","ENCODING_GZIP","require_constants","require_otlp","REQUEST_TIMEOUT_MS","EXIT_PASS","EXIT_FAIL","EXIT_USAGE","USAGE","EXPOSE_HEADERS","REQUEST_HEADERS","name","OPTIONAL_EXPOSED","testRecord","traceId","request","url","init","error","reason","absent","values","response","value","wanted","statusProblem","judge","tests","problem","answer","test","found","passed","runDoctor","originProblem","allowed","origin","preflight","post","contentType","id","attempt","extra","payload","batchId","first","body","repeated","compressed","zipped","hidden","note","missing","isHttpUrl","isOrigin","main","command","flag","args","print","results","pass","rule","detail"],"sources":["../src/doctor.ts"],"sourcesContent":["// src/doctor.ts\n//\n// Checks an ingest server against the ingest contract in the README. The `uiobs doctor` command\n// calls main(). The code uses web APIs only. The browser build replaces each \"node:\" import.\n\nimport {\n ENCODING_GZIP,\n HEADER_ATTEMPT,\n HEADER_BATCH_ID,\n HEADER_CONTENT_ENCODING,\n HEADER_CONTENT_TYPE,\n HEADER_DATE,\n HEADER_RETRY_AFTER,\n HEADER_SAMPLING,\n SEVERITY_NUMBER,\n} from \"./constants\";\nimport type { LogRecord } from \"./models/log-record\";\nimport { gzip } from \"./transport/compression\";\nimport { otlpSerializer } from \"./transport/serializers/otlp\";\n\n/** Maximum wait for one answer, in milliseconds. */\nconst REQUEST_TIMEOUT_MS = 10000;\n\n/** Exit code when each rule passes. */\nconst EXIT_PASS = 0;\n\n/** Exit code when a rule fails. */\nconst EXIT_FAIL = 1;\n\n/** Exit code of a wrong command. */\nconst EXIT_USAGE = 2;\n\n/** Text of a wrong command. */\nconst USAGE =\n \"Usage: uiobs doctor <url> --origin <origin>. An origin has no path and no trailing slash.\";\n\n/** Response header that lists the headers a page can read. */\nconst EXPOSE_HEADERS = \"Access-Control-Expose-Headers\";\n\n/** Request headers of the library. The server must allow each one. */\nconst REQUEST_HEADERS = [\n HEADER_CONTENT_TYPE,\n HEADER_CONTENT_ENCODING,\n HEADER_BATCH_ID,\n HEADER_ATTEMPT,\n].map((name) => name.toLowerCase());\n\n/** Response headers that only an optional feature reads. */\nconst OPTIONAL_EXPOSED = [HEADER_SAMPLING, HEADER_DATE].map((name) => name.toLowerCase());\n\n/** Result of one rule of the ingest contract. */\nexport interface DoctorResult {\n /** Rule name. */\n rule: string;\n /** True when the server meets the rule. */\n pass: boolean;\n /** Reason of the result. */\n detail: string;\n}\n\n/** An HTTP answer, or the text of a failed request. */\ntype Answer = Response | string;\n\n/** Gives the text of a problem, or undefined when the answer meets the test. */\ntype AnswerTest = (response: Response) => string | undefined;\n\n/** Builds the test record. The server stores it as an ordinary record. */\nfunction testRecord(): LogRecord {\n const traceId = crypto.randomUUID().replaceAll(\"-\", \"\");\n\n return {\n timeUnixNano: `${String(Date.now())}000000`,\n traceId,\n spanId: traceId.slice(0, 16),\n traceFlags: 1,\n severityNumber: SEVERITY_NUMBER.INFO,\n severityText: \"INFO\",\n body: \"uiobs doctor test record\",\n attributes: {},\n resource: { \"service.name\": \"uiobs-doctor\" },\n };\n}\n\n/** Sends one request. The result line reports a failure. The tool has no diagnostics instance. */\nasync function request(url: string, init: RequestInit): Promise<Answer> {\n try {\n // A browser refuses a preflight that redirects. A redirect can also name another host.\n return await fetch(url, {\n ...init,\n redirect: \"manual\",\n signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),\n });\n } catch (error) {\n // Node gives only \"fetch failed\". The cause holds the reason, for example ECONNREFUSED.\n const reason: unknown = error instanceof Error ? (error.cause ?? error) : error;\n\n return `The request failed. ${reason instanceof Error ? reason.message : String(reason)}`;\n }\n}\n\n/** Gives the wanted values that a comma-separated header omits. A wildcard has each value. */\nfunction absent(response: Response, name: string, wanted: readonly string[]): string[] {\n const values = (response.headers.get(name) ?? \"\")\n .toLowerCase()\n .split(\",\")\n .map((value) => value.trim());\n\n return values.includes(\"*\") ? [] : wanted.filter((value) => !values.includes(value));\n}\n\n/** Tests the status of an answer. */\nconst statusProblem: AnswerTest = (response) =>\n response.ok ? undefined : `The server returned ${String(response.status)}.`;\n\n/** Builds the result of one rule. The first problem is the detail. */\nfunction judge(rule: string, answer: Answer, passed: string, ...tests: AnswerTest[]): DoctorResult {\n const problem =\n typeof answer === \"string\"\n ? answer\n : tests.map((test) => test(answer)).find((found) => found !== undefined);\n\n return { rule, pass: problem === undefined, detail: problem ?? passed };\n}\n\n/**\n * Sends the requests of each rule, one at a time. Two requests with one batch id must not overlap.\n * @param url Ingest URL.\n * @param origin Origin of the app.\n * @returns One result for each rule.\n */\nexport async function runDoctor(url: string, origin: string): Promise<DoctorResult[]> {\n const originProblem: AnswerTest = (response) => {\n const allowed = response.headers.get(\"Access-Control-Allow-Origin\");\n\n return allowed === origin || allowed === \"*\"\n ? undefined\n : `Access-Control-Allow-Origin is ${String(allowed)}. It must allow ${origin}.`;\n };\n\n const preflight = await request(url, {\n method: \"OPTIONS\",\n headers: {\n Origin: origin,\n \"Access-Control-Request-Method\": \"POST\",\n \"Access-Control-Request-Headers\": REQUEST_HEADERS.join(\", \"),\n },\n });\n\n const { body, contentType } = otlpSerializer.serialize([testRecord()]);\n const post = (\n id: string,\n attempt: number,\n payload: BodyInit,\n extra: Record<string, string> = {},\n ): Promise<Answer> =>\n request(url, {\n method: \"POST\",\n headers: {\n Origin: origin,\n [HEADER_CONTENT_TYPE]: contentType,\n [HEADER_BATCH_ID]: id,\n [HEADER_ATTEMPT]: String(attempt),\n ...extra,\n },\n body: payload,\n });\n\n const batchId = crypto.randomUUID();\n const first = await post(batchId, 0, body);\n const repeated = await post(batchId, 1, body);\n const compressed = await gzip(body);\n const zipped = compressed\n ? await post(crypto.randomUUID(), 0, compressed, {\n [HEADER_CONTENT_ENCODING]: ENCODING_GZIP,\n })\n : \"This Node version has no CompressionStream.\";\n\n const hidden = typeof first === \"string\" ? [] : absent(first, EXPOSE_HEADERS, OPTIONAL_EXPOSED);\n const note = hidden.length > 0 ? ` Optional headers stay hidden: ${hidden.join(\", \")}.` : \"\";\n\n return [\n judge(\n \"preflight\",\n preflight,\n \"The server permits POST from this origin.\",\n statusProblem,\n originProblem,\n ),\n judge(\n \"allowed headers\",\n preflight,\n \"The server allows each request header of the library.\",\n (response) => {\n const missing = absent(response, \"Access-Control-Allow-Headers\", REQUEST_HEADERS);\n\n return missing.length > 0\n ? `Access-Control-Allow-Headers must include ${missing.join(\", \")}.`\n : undefined;\n },\n ),\n judge(\"test batch\", first, \"The server accepted a test batch.\", statusProblem, originProblem),\n judge(\"exposed headers\", first, `The server exposes Retry-After.${note}`, (response) =>\n absent(response, EXPOSE_HEADERS, [HEADER_RETRY_AFTER.toLowerCase()]).length > 0\n ? `${EXPOSE_HEADERS} must include retry-after.`\n : undefined,\n ),\n judge(\"gzip\", zipped, \"The server accepted a gzip batch.\", statusProblem),\n judge(\n \"deduplication\",\n repeated,\n \"The server accepted a repeated batch id. A client cannot see if it stored the batch again.\",\n statusProblem,\n ),\n ];\n}\n\n/** Tests an HTTP URL. */\nfunction isHttpUrl(value: string): boolean {\n return /^https?:\\/\\//i.test(value) && URL.canParse(value);\n}\n\n/** Tests an exact browser origin. A path or a trailing slash does not match. */\nfunction isOrigin(value: string): boolean {\n return URL.canParse(value) && new URL(value).origin === value;\n}\n\n/**\n * Runs the command line tool.\n * @param args Arguments after the program name.\n * @param print Writes one line of output.\n * @returns The exit code.\n */\nexport async function main(\n args: readonly string[],\n print: (line: string) => void,\n): Promise<number> {\n const [command, url, flag, origin] = args;\n\n if (command !== \"doctor\" || flag !== \"--origin\" || !isHttpUrl(url) || !isOrigin(origin)) {\n print(USAGE);\n print(`Received: ${JSON.stringify(args)}`);\n return EXIT_USAGE;\n }\n\n const results = await runDoctor(url, origin);\n\n for (const { rule, pass, detail } of results) {\n print(`${pass ? \"PASS\" : \"FAIL\"} ${rule}: ${detail}`);\n }\n\n return results.every(({ pass }) => pass) ? EXIT_PASS : EXIT_FAIL;\n}\n"],"mappings":"A,gJAqBA,IAAMY,EAAqB,IAGrBC,EAAY,EAGZC,EAAY,EAGZC,EAAa,EAGbC,EACJ,4FAGIC,EAAiB,gCAGjBC,EAAkB,CACtBlB,EAAAA,GACAC,EAAAA,GACAC,EAAAA,GACAC,EAAAA,EACF,CAAC,CAAC,IAAK,GAASgB,EAAK,YAAY,CAAC,EAG5BC,EAAmB,CAAChB,EAAAA,GAAiBC,EAAAA,EAAW,CAAC,CAAC,IAAK,GAASc,EAAK,YAAY,CAAC,EAmBxF,SAASE,GAAwB,CAC/B,IAAMC,EAAU,OAAO,WAAW,CAAC,CAAC,WAAW,IAAK,EAAE,EAEtD,MAAO,CACL,aAAc,GAAG,OAAO,KAAK,IAAI,CAAC,EAAE,QACpC,UACA,OAAQA,EAAQ,MAAM,EAAG,EAAE,EAC3B,WAAY,EACZ,eAAgBhB,EAAAA,GAAgB,KAChC,aAAc,OACd,KAAM,2BACN,WAAY,CAAC,EACb,SAAU,CAAE,eAAgB,cAAe,CAC7C,CACF,CAGA,eAAeiB,EAAQ,EAAa,EAAoC,CACtE,GAAI,CAEF,OAAO,MAAM,MAAMC,EAAK,CACtB,GAAGC,EACH,SAAU,SACV,OAAQ,YAAY,QAAQb,CAAkB,CAChD,CAAC,CACH,OAASc,EAAO,CAEd,IAAMC,EAAkBD,aAAiB,MAASA,EAAM,OAASA,EAASA,EAE1E,MAAO,uBAAuBC,aAAkB,MAAQA,EAAO,QAAU,OAAOA,CAAM,GACxF,CACF,CAGA,SAASC,EAAO,EAAoB,EAAc,EAAqC,CACrF,IAAMC,GAAUC,EAAS,QAAQ,IAAIX,CAAI,GAAK,GAAA,CAC3C,YAAY,CAAC,CACb,MAAM,GAAG,CAAC,CACV,IAAK,GAAUY,EAAM,KAAK,CAAC,EAE9B,OAAOF,EAAO,SAAS,GAAG,EAAI,CAAC,EAAIG,EAAO,OAAQ,GAAU,CAACH,EAAO,SAASE,CAAK,CAAC,CACrF,CAGA,IAAME,EAA6B,GACjCH,EAAS,GAAK,IAAA,GAAY,uBAAuB,OAAOA,EAAS,MAAM,EAAE,GAG3E,SAASI,EAAM,EAAc,EAAgB,EAAgB,GAAGC,EAAmC,CACjG,IAAMC,EACJ,OAAOC,GAAW,SACdA,EACAF,EAAM,IAAK,GAASG,EAAKD,CAAM,CAAC,CAAC,CAAC,KAAM,GAAUE,IAAU,IAAA,EAAS,EAE3E,MAAO,CAAE,OAAM,KAAMH,IAAY,IAAA,GAAW,OAAQA,GAAWI,CAAO,CACxE,CAQA,eAAsBC,EAAU,EAAa,EAAyC,CACpF,IAAMC,EAA6B,GAAa,CAC9C,IAAMC,EAAUb,EAAS,QAAQ,IAAI,6BAA6B,EAElE,OAAOa,IAAYC,GAAUD,IAAY,IACrC,IAAA,GACA,kCAAkC,OAAOA,CAAO,EAAE,kBAAkBC,EAAO,EACjF,EAEMC,EAAY,MAAMtB,EAAQC,EAAK,CACnC,OAAQ,UACR,QAAS,CACP,OAAQoB,EACR,gCAAiC,OACjC,iCAAkC1B,EAAgB,KAAK,IAAI,CAC7D,CACF,CAAC,EAEK,CAAE,OAAM,eAAgBX,EAAAA,EAAe,UAAU,CAACc,EAAW,CAAC,CAAC,EAC/DyB,GACJ,EACA,EACA,EACA,EAAgC,CAAC,IAEjCvB,EAAQC,EAAK,CACX,OAAQ,OACR,QAAS,CACP,OAAQoB,GACP5C,EAAAA,IAAsB+C,GACtB7C,EAAAA,IAAkB8C,GAClB7C,EAAAA,IAAiB,OAAO8C,CAAO,EAChC,GAAGC,CACL,EACA,KAAMC,CACR,CAAC,EAEGC,EAAU,OAAO,WAAW,EAC5BC,EAAQ,MAAMP,EAAKM,EAAS,EAAGE,CAAI,EACnCC,EAAW,MAAMT,EAAKM,EAAS,EAAGE,CAAI,EACtCE,EAAa,MAAMhD,EAAAA,EAAK8C,CAAI,EAC5BG,EAASD,EACX,MAAMV,EAAK,OAAO,WAAW,EAAG,EAAGU,EAAY,EAC5CvD,EAAAA,IAA0BQ,EAAAA,EAC7B,CAAC,EACD,8CAEEiD,EAAS,OAAOL,GAAU,SAAW,CAAC,EAAIzB,EAAOyB,EAAOpC,EAAgBG,CAAgB,EACxFuC,EAAOD,EAAO,OAAS,EAAI,kCAAkCA,EAAO,KAAK,IAAI,EAAE,GAAK,GAE1F,MAAO,CACLxB,EACE,YACAW,EACA,4CACAZ,EACAS,CACF,EACAR,EACE,kBACAW,EACA,wDACC,GAAa,CACZ,IAAMe,EAAUhC,EAAOE,EAAU,+BAAgCZ,CAAe,EAEhF,OAAO0C,EAAQ,OAAS,EACpB,6CAA6CA,EAAQ,KAAK,IAAI,EAAE,GAChE,IAAA,EACN,CACF,EACA1B,EAAM,aAAcmB,EAAO,oCAAqCpB,EAAeS,CAAa,EAC5FR,EAAM,kBAAmBmB,EAAO,kCAAkCM,IAAS,GACzE/B,EAAOE,EAAUb,EAAgB,CAAA,aAAiC,CAAC,CAAC,CAAC,OAAS,EAC1E,GAAGA,EAAe,4BAClB,IAAA,EACN,EACAiB,EAAM,OAAQuB,EAAQ,oCAAqCxB,CAAa,EACxEC,EACE,gBACAqB,EACA,6FACAtB,CACF,CACF,CACF,CAGA,SAAS4B,EAAU,EAAwB,CACzC,MAAO,gBAAgB,KAAK9B,CAAK,GAAK,IAAI,SAASA,CAAK,CAC1D,CAGA,SAAS+B,EAAS,EAAwB,CACxC,OAAO,IAAI,SAAS/B,CAAK,GAAK,IAAI,IAAIA,CAAK,CAAC,CAAC,SAAWA,CAC1D,CAQA,eAAsBgC,EACpB,EACA,EACiB,CACjB,GAAM,CAACC,EAASxC,EAAKyC,EAAMrB,GAAUsB,EAErC,GAAIF,IAAY,UAAYC,IAAS,YAAc,CAACJ,EAAUrC,CAAG,GAAK,CAACsC,EAASlB,CAAM,EAGpF,OAFAuB,EAAMnD,CAAK,EACXmD,EAAM,aAAa,KAAK,UAAUD,CAAI,GAAG,EAClCnD,EAGT,IAAMqD,EAAU,MAAM3B,EAAUjB,EAAKoB,CAAM,EAE3C,IAAK,GAAM,CAAE,OAAM,OAAM,YAAYwB,EACnCD,EAAM,GAAGE,EAAO,OAAS,OAAO,GAAGC,EAAK,IAAIC,GAAQ,EAGtD,OAAOH,EAAQ,OAAO,CAAE,UAAWC,CAAI,EAAIxD,EAAYC,CACzD,C"}
|
package/dist/doctor.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Result of one rule of the ingest contract. */
|
|
2
|
+
export interface DoctorResult {
|
|
3
|
+
/** Rule name. */
|
|
4
|
+
rule: string;
|
|
5
|
+
/** True when the server meets the rule. */
|
|
6
|
+
pass: boolean;
|
|
7
|
+
/** Reason of the result. */
|
|
8
|
+
detail: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Sends the requests of each rule, one at a time. Two requests with one batch id must not overlap.
|
|
12
|
+
* @param url Ingest URL.
|
|
13
|
+
* @param origin Origin of the app.
|
|
14
|
+
* @returns One result for each rule.
|
|
15
|
+
*/
|
|
16
|
+
export declare function runDoctor(url: string, origin: string): Promise<DoctorResult[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Runs the command line tool.
|
|
19
|
+
* @param args Arguments after the program name.
|
|
20
|
+
* @param print Writes one line of output.
|
|
21
|
+
* @returns The exit code.
|
|
22
|
+
*/
|
|
23
|
+
export declare function main(args: readonly string[], print: (line: string) => void): Promise<number>;
|