@utk09/ui-observability 1.0.0 → 1.1.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 +69 -219
- package/README.md +24 -26
- package/dist/{batch-CXmPmTse.js → batch-D3NHhF9L.js} +3 -3
- package/dist/{batch-CXmPmTse.js.map → batch-D3NHhF9L.js.map} +1 -1
- package/dist/{batch-mmPigCpi.cjs → batch-DnYRJqhU.cjs} +2 -2
- package/dist/{batch-mmPigCpi.cjs.map → batch-DnYRJqhU.cjs.map} +1 -1
- package/dist/bus/bus.d.cts +26 -2
- package/dist/bus/bus.d.ts +26 -2
- package/dist/bus-B__467mL.cjs +2 -0
- package/dist/bus-B__467mL.cjs.map +1 -0
- package/dist/{bus-C39wspFV.js → bus-dw7T92sO.js} +37 -24
- package/dist/bus-dw7T92sO.js.map +1 -0
- package/dist/capture/interactions.d.cts +35 -3
- package/dist/capture/interactions.d.ts +35 -3
- package/dist/capture/observed-windows.d.cts +51 -0
- package/dist/capture/observed-windows.d.ts +51 -0
- package/dist/{compression-CvED_Jel.cjs → compression-C0hUHKR-.cjs} +2 -2
- package/dist/{compression-CvED_Jel.cjs.map → compression-C0hUHKR-.cjs.map} +1 -1
- package/dist/{compression-tVtXwVjX.js → compression-SHPAvS4U.js} +2 -2
- package/dist/{compression-tVtXwVjX.js.map → compression-SHPAvS4U.js.map} +1 -1
- package/dist/{config-SgQcCP1_.js → config-CSNcS7OZ.js} +194 -196
- package/dist/config-CSNcS7OZ.js.map +1 -0
- package/dist/config-CybPP5VM.cjs +2 -0
- package/dist/config-CybPP5VM.cjs.map +1 -0
- package/dist/{console-BGgGnjSi.js → console-BsM-fSCQ.js} +4 -4
- package/dist/{console-BGgGnjSi.js.map → console-BsM-fSCQ.js.map} +1 -1
- package/dist/{console-CSZ5_Vx5.cjs → console-Dkxs6IVQ.cjs} +2 -2
- package/dist/{console-CSZ5_Vx5.cjs.map → console-Dkxs6IVQ.cjs.map} +1 -1
- package/dist/{constants-CUyd9cTZ.js → constants-BwJDXzj6.js} +23 -23
- package/dist/constants-BwJDXzj6.js.map +1 -0
- package/dist/constants-CtF52hIV.cjs +2 -0
- package/dist/constants-CtF52hIV.cjs.map +1 -0
- package/dist/constants.d.cts +12 -0
- package/dist/constants.d.ts +12 -0
- package/dist/core/diagnostics.d.cts +1 -1
- package/dist/core/diagnostics.d.ts +1 -1
- package/dist/core/rotation.d.cts +26 -2
- package/dist/core/rotation.d.ts +26 -2
- package/dist/core/runtime.d.cts +9 -0
- package/dist/core/runtime.d.ts +9 -0
- package/dist/{debug-bundle-BXIlwDKM.cjs → debug-bundle-B2v6Cym-.cjs} +2 -2
- package/dist/{debug-bundle-BXIlwDKM.cjs.map → debug-bundle-B2v6Cym-.cjs.map} +1 -1
- package/dist/{debug-bundle-CRpYV_ui.js → debug-bundle-Cs_YWzTa.js} +4 -4
- package/dist/{debug-bundle-CRpYV_ui.js.map → debug-bundle-Cs_YWzTa.js.map} +1 -1
- package/dist/doctor.cjs +1 -1
- package/dist/doctor.js +31 -31
- package/dist/doctor.js.map +1 -1
- package/dist/{errors-CNPbesMs.cjs → errors-DP2RUm4V.cjs} +2 -2
- package/dist/{errors-CNPbesMs.cjs.map → errors-DP2RUm4V.cjs.map} +1 -1
- package/dist/{errors-BE_EZV7Q.js → errors-Q3Ng1ciC.js} +3 -3
- package/dist/{errors-BE_EZV7Q.js.map → errors-Q3Ng1ciC.js.map} +1 -1
- package/dist/{factory-CTi0Is3F.js → factory-DV17sm2p.js} +22 -22
- package/dist/{factory-CTi0Is3F.js.map → factory-DV17sm2p.js.map} +1 -1
- package/dist/{factory-hRrH32v5.cjs → factory-K8O6gpux.cjs} +2 -2
- package/dist/{factory-hRrH32v5.cjs.map → factory-K8O6gpux.cjs.map} +1 -1
- package/dist/{identity-DdhKgrpk.js → identity-BgtHyY4u.js} +38 -27
- package/dist/identity-BgtHyY4u.js.map +1 -0
- package/dist/identity-CvuyqZk7.cjs +2 -0
- package/dist/identity-CvuyqZk7.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +600 -569
- package/dist/index.js.map +1 -1
- package/dist/{indexeddb-storage-CL9uqBCy.cjs → indexeddb-storage-D4KVcqdD.cjs} +2 -2
- package/dist/{indexeddb-storage-CL9uqBCy.cjs.map → indexeddb-storage-D4KVcqdD.cjs.map} +1 -1
- package/dist/{indexeddb-storage-GHdl0t8A.js → indexeddb-storage-e-13ZLWm.js} +17 -17
- package/dist/{indexeddb-storage-GHdl0t8A.js.map → indexeddb-storage-e-13ZLWm.js.map} +1 -1
- package/dist/interactions-Byxf1C82.js +207 -0
- package/dist/interactions-Byxf1C82.js.map +1 -0
- package/dist/interactions-OK85T-Dk.cjs +2 -0
- package/dist/interactions-OK85T-Dk.cjs.map +1 -0
- package/dist/{journey-D2_sia57.js → journey-C93FTYcs.js} +14 -14
- package/dist/{journey-D2_sia57.js.map → journey-C93FTYcs.js.map} +1 -1
- package/dist/{journey-B4Adltjm.cjs → journey-nMbob3OB.cjs} +2 -2
- package/dist/{journey-B4Adltjm.cjs.map → journey-nMbob3OB.cjs.map} +1 -1
- package/dist/{library-console-CPW6bvZH.cjs → library-console-DJUQzcgM.cjs} +2 -2
- package/dist/{library-console-CPW6bvZH.cjs.map → library-console-DJUQzcgM.cjs.map} +1 -1
- package/dist/{library-console-Btrzt814.js → library-console-DklSmucS.js} +2 -2
- package/dist/{library-console-Btrzt814.js.map → library-console-DklSmucS.js.map} +1 -1
- package/dist/{library-request-BJ9PLRaD.js → library-request-UGEwOHpf.js} +2 -2
- package/dist/{library-request-BJ9PLRaD.js.map → library-request-UGEwOHpf.js.map} +1 -1
- package/dist/{library-request-D7OvTxZV.cjs → library-request-kY9iTpIF.cjs} +2 -2
- package/dist/{library-request-D7OvTxZV.cjs.map → library-request-kY9iTpIF.cjs.map} +1 -1
- package/dist/{lifecycle-22CUCrc9.js → lifecycle-B2PlIuQu.js} +2 -2
- package/dist/{lifecycle-22CUCrc9.js.map → lifecycle-B2PlIuQu.js.map} +1 -1
- package/dist/{lifecycle-IaAm1mOC.cjs → lifecycle-DaMdH_X7.cjs} +2 -2
- package/dist/{lifecycle-IaAm1mOC.cjs.map → lifecycle-DaMdH_X7.cjs.map} +1 -1
- package/dist/{log-record-CkivuiEl.cjs → log-record-Bmx6etMh.cjs} +2 -2
- package/dist/{log-record-CkivuiEl.cjs.map → log-record-Bmx6etMh.cjs.map} +1 -1
- package/dist/{log-record-BNiLfqtL.js → log-record-DSt2P-Sr.js} +2 -2
- package/dist/{log-record-BNiLfqtL.js.map → log-record-DSt2P-Sr.js.map} +1 -1
- package/dist/{long-frames-DNFaRnC3.js → long-frames-Bamjs1WV.js} +3 -3
- package/dist/{long-frames-DNFaRnC3.js.map → long-frames-Bamjs1WV.js.map} +1 -1
- package/dist/{long-frames-BUUbXd-B.cjs → long-frames-lhtONgGt.cjs} +2 -2
- package/dist/{long-frames-BUUbXd-B.cjs.map → long-frames-lhtONgGt.cjs.map} +1 -1
- package/dist/models/bus.d.cts +6 -1
- package/dist/models/bus.d.ts +6 -1
- package/dist/models/config.d.cts +23 -8
- package/dist/models/config.d.ts +23 -8
- package/dist/models/serializer.d.cts +3 -1
- package/dist/models/serializer.d.ts +3 -1
- package/dist/{network-CGMLQ-mA.cjs → network-BCn8Gn47.cjs} +2 -2
- package/dist/{network-CGMLQ-mA.cjs.map → network-BCn8Gn47.cjs.map} +1 -1
- package/dist/{network-on2zZT6H.js → network-Cg1L2w2r.js} +12 -12
- package/dist/{network-on2zZT6H.js.map → network-Cg1L2w2r.js.map} +1 -1
- package/dist/observed-windows-B3gJkdql.cjs +2 -0
- package/dist/observed-windows-B3gJkdql.cjs.map +1 -0
- package/dist/observed-windows-BrwaJNlj.js +64 -0
- package/dist/observed-windows-BrwaJNlj.js.map +1 -0
- package/dist/{otlp-BENHf3g9.cjs → otlp-CrAWkQdO.cjs} +2 -2
- package/dist/{otlp-BENHf3g9.cjs.map → otlp-CrAWkQdO.cjs.map} +1 -1
- package/dist/{otlp-DimfrRor.js → otlp-D6dRZyB8.js} +6 -6
- package/dist/{otlp-DimfrRor.js.map → otlp-D6dRZyB8.js.map} +1 -1
- package/dist/{platform-BaaFIPCU.js → platform-8DLhjddo.js} +7 -7
- package/dist/{platform-BaaFIPCU.js.map → platform-8DLhjddo.js.map} +1 -1
- package/dist/{platform-CfA3-7sJ.cjs → platform-BqRc-7RO.cjs} +2 -2
- package/dist/{platform-CfA3-7sJ.cjs.map → platform-BqRc-7RO.cjs.map} +1 -1
- package/dist/{profiler-BAZoh7A4.js → profiler-BaXSqCfz.js} +59 -59
- package/dist/{profiler-BAZoh7A4.js.map → profiler-BaXSqCfz.js.map} +1 -1
- package/dist/{profiler-D4tJpDRc.cjs → profiler-BvWW2kNM.cjs} +2 -2
- package/dist/{profiler-D4tJpDRc.cjs.map → profiler-BvWW2kNM.cjs.map} +1 -1
- package/dist/{profiler-frames-cJMx9wNM.js → profiler-frames-C4ySHN0X.js} +16 -16
- package/dist/{profiler-frames-cJMx9wNM.js.map → profiler-frames-C4ySHN0X.js.map} +1 -1
- package/dist/{profiler-frames-C4xr7KfH.cjs → profiler-frames-DeaBiB-5.cjs} +2 -2
- package/dist/{profiler-frames-C4xr7KfH.cjs.map → profiler-frames-DeaBiB-5.cjs.map} +1 -1
- package/dist/{remote-rules-_tY0zj5o.cjs → remote-rules-D7L6D_D2.cjs} +2 -2
- package/dist/{remote-rules-_tY0zj5o.cjs.map → remote-rules-D7L6D_D2.cjs.map} +1 -1
- package/dist/{remote-rules-Dz9MRAsB.js → remote-rules-Dq9xe7Qn.js} +22 -22
- package/dist/{remote-rules-Dz9MRAsB.js.map → remote-rules-Dq9xe7Qn.js.map} +1 -1
- package/dist/{replay-Ds-ANH34.js → replay-B0M8kWz_.js} +24 -24
- package/dist/{replay-Ds-ANH34.js.map → replay-B0M8kWz_.js.map} +1 -1
- package/dist/{replay-B3gFXIZd.cjs → replay-QOFBpAXh.cjs} +2 -2
- package/dist/{replay-B3gFXIZd.cjs.map → replay-QOFBpAXh.cjs.map} +1 -1
- package/dist/{reports-C-thq-bk.js → reports--8APRLa-.js} +3 -3
- package/dist/{reports-C-thq-bk.js.map → reports--8APRLa-.js.map} +1 -1
- package/dist/{reports-BDSe4dFH.cjs → reports-ojuMKGO7.cjs} +2 -2
- package/dist/{reports-BDSe4dFH.cjs.map → reports-ojuMKGO7.cjs.map} +1 -1
- package/dist/{resource-timing-eUl2dNgC.js → resource-timing-BzR05rE-.js} +4 -4
- package/dist/{resource-timing-eUl2dNgC.js.map → resource-timing-BzR05rE-.js.map} +1 -1
- package/dist/{resource-timing-C576gFIQ.cjs → resource-timing-pAG3ZhB5.cjs} +2 -2
- package/dist/{resource-timing-C576gFIQ.cjs.map → resource-timing-pAG3ZhB5.cjs.map} +1 -1
- package/dist/{response-body-eoSQpLiH.js → response-body-BWvwKQ2p.js} +106 -106
- package/dist/{response-body-eoSQpLiH.js.map → response-body-BWvwKQ2p.js.map} +1 -1
- package/dist/{response-body-YdNl-HkR.cjs → response-body-CKEJ5itk.cjs} +3 -3
- package/dist/{response-body-YdNl-HkR.cjs.map → response-body-CKEJ5itk.cjs.map} +1 -1
- package/dist/{rotation-Cwct4ckk.js → rotation-BylN1B9e.js} +10 -11
- package/dist/rotation-BylN1B9e.js.map +1 -0
- package/dist/rotation-E2eKClIs.cjs +2 -0
- package/dist/rotation-E2eKClIs.cjs.map +1 -0
- package/dist/{sampling-mXt4dstx.cjs → sampling-B46LW0cy.cjs} +2 -2
- package/dist/{sampling-mXt4dstx.cjs.map → sampling-B46LW0cy.cjs.map} +1 -1
- package/dist/{sampling-BlrI8jor.js → sampling-zXA6r-Nw.js} +16 -16
- package/dist/{sampling-BlrI8jor.js.map → sampling-zXA6r-Nw.js.map} +1 -1
- package/dist/{sanitize-Ba0KqU06.js → sanitize-DjnR6RXR.js} +2 -2
- package/dist/{sanitize-Ba0KqU06.js.map → sanitize-DjnR6RXR.js.map} +1 -1
- package/dist/{sanitize-DQyiI_KY.cjs → sanitize-Qj6LuZqp.cjs} +2 -2
- package/dist/{sanitize-DQyiI_KY.cjs.map → sanitize-Qj6LuZqp.cjs.map} +1 -1
- package/dist/{sender-Dv8rAmpV.js → sender-Bdp-TAS4.js} +71 -71
- package/dist/{sender-Dv8rAmpV.js.map → sender-Bdp-TAS4.js.map} +1 -1
- package/dist/{sender-BdRuNVhF.cjs → sender-DR7ZycZY.cjs} +2 -2
- package/dist/{sender-BdRuNVhF.cjs.map → sender-DR7ZycZY.cjs.map} +1 -1
- package/dist/{stored-context-CXt7eHZL.cjs → stored-context-BOu54M8Y.cjs} +2 -2
- package/dist/{stored-context-CXt7eHZL.cjs.map → stored-context-BOu54M8Y.cjs.map} +1 -1
- package/dist/{stored-context-B2EzVuYm.js → stored-context-CSttrAsw.js} +6 -6
- package/dist/{stored-context-B2EzVuYm.js.map → stored-context-CSttrAsw.js.map} +1 -1
- package/dist/{storm-C-zYSdDX.cjs → storm-BHgI12iS.cjs} +2 -2
- package/dist/{storm-C-zYSdDX.cjs.map → storm-BHgI12iS.cjs.map} +1 -1
- package/dist/{storm-DjKetLKZ.js → storm-DKlpv0FL.js} +2 -2
- package/dist/{storm-DjKetLKZ.js.map → storm-DKlpv0FL.js.map} +1 -1
- package/dist/{unclean-exit-py99ApzT.cjs → unclean-exit-BYPYYkQ5.cjs} +2 -2
- package/dist/{unclean-exit-py99ApzT.cjs.map → unclean-exit-BYPYYkQ5.cjs.map} +1 -1
- package/dist/{unclean-exit-DQD1cT7c.js → unclean-exit-BcOB8A2e.js} +2 -2
- package/dist/{unclean-exit-DQD1cT7c.js.map → unclean-exit-BcOB8A2e.js.map} +1 -1
- package/dist/{user-timing-BePqb1uN.js → user-timing-4KIJ74Vi.js} +2 -2
- package/dist/{user-timing-BePqb1uN.js.map → user-timing-4KIJ74Vi.js.map} +1 -1
- package/dist/{user-timing-D6XTmpuM.cjs → user-timing-BsU2wQKE.cjs} +2 -2
- package/dist/{user-timing-D6XTmpuM.cjs.map → user-timing-BsU2wQKE.cjs.map} +1 -1
- package/dist/utils/identity.d.cts +5 -0
- package/dist/utils/identity.d.ts +5 -0
- package/dist/{web-socket-CoIUBM3C.cjs → web-socket-Cs1ZbmmN.cjs} +2 -2
- package/dist/{web-socket-CoIUBM3C.cjs.map → web-socket-Cs1ZbmmN.cjs.map} +1 -1
- package/dist/{web-socket-DSHgDiZ6.js → web-socket-Zg0hj1LB.js} +4 -4
- package/dist/{web-socket-DSHgDiZ6.js.map → web-socket-Zg0hj1LB.js.map} +1 -1
- package/dist/{worker-protocol-x074Rpet.js → worker-protocol-CYpAbrVl.js} +4 -4
- package/dist/{worker-protocol-x074Rpet.js.map → worker-protocol-CYpAbrVl.js.map} +1 -1
- package/dist/{worker-protocol-QbvqNazn.cjs → worker-protocol-DFYXIFus.cjs} +2 -2
- package/dist/{worker-protocol-QbvqNazn.cjs.map → worker-protocol-DFYXIFus.cjs.map} +1 -1
- package/dist/{worker-server-CFe4nvos.cjs → worker-server--yGTadTA.cjs} +2 -2
- package/dist/{worker-server-CFe4nvos.cjs.map → worker-server--yGTadTA.cjs.map} +1 -1
- package/dist/{worker-server-iUVSjH8L.js → worker-server-BokySIII.js} +25 -25
- package/dist/{worker-server-iUVSjH8L.js.map → worker-server-BokySIII.js.map} +1 -1
- package/dist/worker-transport-BdEvh_-a.cjs +2 -0
- package/dist/worker-transport-BdEvh_-a.cjs.map +1 -0
- package/dist/{worker-transport-Dy1KMA7t.js → worker-transport-JK-Fby9J.js} +23 -19
- package/dist/worker-transport-JK-Fby9J.js.map +1 -0
- package/llms.txt +13 -10
- package/package.json +13 -5
- package/dist/bus-C39wspFV.js.map +0 -1
- package/dist/bus-_EaOVPGq.cjs +0 -2
- package/dist/bus-_EaOVPGq.cjs.map +0 -1
- package/dist/config-DUs7uHHt.cjs +0 -2
- package/dist/config-DUs7uHHt.cjs.map +0 -1
- package/dist/config-SgQcCP1_.js.map +0 -1
- package/dist/constants-CUyd9cTZ.js.map +0 -1
- package/dist/constants-CqdJhTxH.cjs +0 -2
- package/dist/constants-CqdJhTxH.cjs.map +0 -1
- package/dist/identity-DdhKgrpk.js.map +0 -1
- package/dist/identity-DlWRIuwy.cjs +0 -2
- package/dist/identity-DlWRIuwy.cjs.map +0 -1
- package/dist/interactions-CUkzK8sR.cjs +0 -2
- package/dist/interactions-CUkzK8sR.cjs.map +0 -1
- package/dist/interactions-DiFvCosX.js +0 -111
- package/dist/interactions-DiFvCosX.js.map +0 -1
- package/dist/rotation-Cwct4ckk.js.map +0 -1
- package/dist/rotation-D4qUAHAu.cjs +0 -2
- package/dist/rotation-D4qUAHAu.cjs.map +0 -1
- package/dist/worker-transport-CRAX-09c.cjs +0 -2
- package/dist/worker-transport-CRAX-09c.cjs.map +0 -1
- package/dist/worker-transport-Dy1KMA7t.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as r } from "./profiler-
|
|
3
|
-
import { t as i } from "./storm-
|
|
1
|
+
import { en as e, nn as t, tn as n } from "./constants-BwJDXzj6.js";
|
|
2
|
+
import { t as r } from "./profiler-BaXSqCfz.js";
|
|
3
|
+
import { t as i } from "./storm-DKlpv0FL.js";
|
|
4
4
|
import { t as a } from "./defineProperty-s2S8BXUc.js";
|
|
5
5
|
// src/capture/profiler-frames.ts
|
|
6
6
|
var o = "long-animation-frame", s = class {
|
|
@@ -26,22 +26,22 @@ var o = "long-animation-frame", s = class {
|
|
|
26
26
|
uninstall() {
|
|
27
27
|
this.observer && (this.observer.disconnect(), this.observer = void 0, r().link(Infinity));
|
|
28
28
|
}
|
|
29
|
-
record(
|
|
30
|
-
let a =
|
|
29
|
+
record(n) {
|
|
30
|
+
let a = n.startTime, o = a + n.duration, s = r().linked(a, o);
|
|
31
31
|
if (s.length === 0) return;
|
|
32
32
|
let { captureLimits: c } = this.ctx.config;
|
|
33
33
|
if (!i(this.window, c.longFramesPerWindow, this.ctx.diagnostics, "profiler frames", c.windowMs)) return;
|
|
34
|
-
let l = (e = 0) => e > 0 ? e : o, u = l(
|
|
35
|
-
for (let e of
|
|
34
|
+
let l = (e = 0) => e > 0 ? e : o, u = l(n.renderStart), d = l(n.styleAndLayoutStart), f = 0;
|
|
35
|
+
for (let e of n.scripts ?? []) f += e.forcedStyleAndLayoutDuration ?? 0;
|
|
36
36
|
let p = [
|
|
37
37
|
["script", u - a],
|
|
38
38
|
["render", d - u],
|
|
39
39
|
["style_layout", o - d],
|
|
40
40
|
["forced_layout", f]
|
|
41
41
|
];
|
|
42
|
-
for (let
|
|
43
|
-
[
|
|
44
|
-
[
|
|
42
|
+
for (let n of s) for (let [r, i] of p) this.ctx.logger.logMetric(e, i, "ms", "histogram", {
|
|
43
|
+
[t.probe]: n,
|
|
44
|
+
[t.framePhase]: r
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
}, c = class {
|
|
@@ -51,22 +51,22 @@ var o = "long-animation-frame", s = class {
|
|
|
51
51
|
}), this.ctx = e;
|
|
52
52
|
}
|
|
53
53
|
install() {
|
|
54
|
-
let e = globalThis, { requestAnimationFrame:
|
|
54
|
+
let e = globalThis, { requestAnimationFrame: t } = e;
|
|
55
55
|
if (this.handle !== void 0) return;
|
|
56
|
-
if (typeof
|
|
56
|
+
if (typeof t != "function") {
|
|
57
57
|
let { once: e } = this.ctx;
|
|
58
58
|
e.framePacing || (e.framePacing = !0, this.ctx.diagnostics.report("capture.install_failed", "This context has no frame callback. The frame pacing of the profiler is off."));
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
|
-
let i = r().probe(
|
|
61
|
+
let i = r().probe(n, void 0, this.ctx.diagnostics), a = (e) => {
|
|
62
62
|
try {
|
|
63
63
|
this.last >= 0 && i.record(e - this.last);
|
|
64
64
|
} catch (e) {
|
|
65
65
|
this.ctx.diagnostics.report("capture.record_failed", "The library could not record a frame interval of the profiler.", void 0, e);
|
|
66
66
|
}
|
|
67
|
-
this.last = e, this.handle =
|
|
67
|
+
this.last = e, this.handle = t(a);
|
|
68
68
|
};
|
|
69
|
-
e.document?.addEventListener("visibilitychange", this.onVisibility), this.handle =
|
|
69
|
+
e.document?.addEventListener("visibilitychange", this.onVisibility), this.handle = t(a);
|
|
70
70
|
}
|
|
71
71
|
uninstall() {
|
|
72
72
|
let e = globalThis;
|
|
@@ -75,4 +75,4 @@ var o = "long-animation-frame", s = class {
|
|
|
75
75
|
};
|
|
76
76
|
export { c as FramePacingCapture, s as FramePhasesCapture };
|
|
77
77
|
|
|
78
|
-
//# sourceMappingURL=profiler-frames-
|
|
78
|
+
//# sourceMappingURL=profiler-frames-C4ySHN0X.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiler-frames-cJMx9wNM.js","names":["PROFILE_KEYS","PROFILE_FRAME_PROBE","PROFILE_FRAME_METRIC_NAME","profilerCore","allowInWindow","_defineProperty","FRAME_TYPE","FramePhasesCapture","ctx","entry","list","once","start","end","names","captureLimits","phaseStart","value","renderStart","layoutStart","forced","script","phases","name","phase","ms","FramePacingCapture","scope","request","probe","frame","time","error"],"sources":["../src/capture/profiler-frames.ts"],"sourcesContent":["// src/capture/profiler-frames.ts\n//\n// Ties the profiler to the browser's rendering work. The frame phases capture attributes the\n// phases of each long animation frame to the probes that ran in it. Frame pacing measures the\n// time between consecutive frames.\n\nimport {\n PROFILE_FRAME_METRIC_NAME,\n PROFILE_FRAME_PROBE,\n PROFILE_KEYS,\n PROFILER_LINK_MIN_MS,\n} from \"../constants\";\nimport { profilerCore } from \"../core/profiler\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Long animation frames, not long tasks: long tasks don't have phases. */\nconst FRAME_TYPE = \"long-animation-frame\";\n\n/** One script in a long animation frame. */\ninterface FrameScript {\n /** Style and layout time the script forced, in ms. */\n forcedStyleAndLayoutDuration?: number;\n}\n\n/** A long animation frame. Some versions of the DOM typings don't declare these fields. */\ninterface PhaseEntry extends PerformanceEntry {\n /** When the render callbacks started. 0 if the frame didn't render. */\n renderStart?: number;\n /** When style and layout started. 0 if the frame didn't render. */\n styleAndLayoutStart?: number;\n /** The scripts that ran in the frame. */\n scripts?: FrameScript[];\n}\n\n/** The page globals frame pacing needs. A worker or Node.js may have none of them. */\ninterface FrameScope {\n /** Calls a function before the next paint, passing the frame's start time. */\n requestAnimationFrame?: (callback: (time: number) => void) => number;\n cancelAnimationFrame?: (handle: number) => void;\n document?: Pick<Document, \"addEventListener\" | \"removeEventListener\">;\n}\n\n/** Attributes the phases of each long animation frame to every probe with a span in it. */\nexport class FramePhasesCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"frame-phases\";\n\n /** The active observer. Undefined while the capture isn't installed. */\n private observer: PerformanceObserver | undefined;\n\n /** Rate limit for this capture, so a frozen tab can't flood the pipeline. */\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n /**\n * @param ctx Capture context: configuration, diagnostics and logger.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Starts observing long animation frames and turns on the recent-span ring. */\n install(): void {\n if (this.observer) {\n return;\n }\n\n // Older browsers have no supportedEntryTypes. The capture just stays off there.\n const supported: readonly string[] | undefined =\n typeof PerformanceObserver === \"undefined\"\n ? undefined\n : PerformanceObserver.supportedEntryTypes;\n\n if (!supported?.includes(FRAME_TYPE)) {\n // Report on the first install in a document only, not on every reinstall after configure().\n const { once } = this.ctx;\n\n if (!once.framePhases) {\n once.framePhases = true;\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The browser does not report long animation frames. profiler.framePhases is off.\",\n );\n }\n\n return;\n }\n\n profilerCore().link(PROFILER_LINK_MIN_MS);\n this.observer = new PerformanceObserver((list) => {\n // The browser calls this directly, so anything we throw is an uncaught error on the page.\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not record a long animation frame of the profiler.\",\n () => {\n for (const entry of list.getEntries()) {\n this.record(entry);\n }\n },\n );\n });\n\n // Not buffered: a buffered frame is older than anything in the ring and would link to nothing.\n this.observer.observe({ type: FRAME_TYPE });\n }\n\n /** Disconnects the observer and turns the recent-span ring off. */\n uninstall(): void {\n if (!this.observer) {\n return;\n }\n\n this.observer.disconnect();\n this.observer = undefined;\n profilerCore().link(Infinity);\n }\n\n /**\n * Records one frame's phases for every probe that had a span in the frame.\n * @param entry Long animation frame entry.\n */\n private record(entry: PhaseEntry): void {\n const start = entry.startTime;\n const end = start + entry.duration;\n const names = profilerCore().linked(start, end);\n\n if (names.length === 0) {\n return;\n }\n\n const { captureLimits } = this.ctx.config;\n\n if (\n !allowInWindow(\n this.window,\n captureLimits.longFramesPerWindow,\n this.ctx.diagnostics,\n \"profiler frames\",\n captureLimits.windowMs,\n )\n ) {\n return;\n }\n\n // A frame that didn't render has 0 in both fields. The whole frame then counts as script.\n const phaseStart = (value = 0): number => (value > 0 ? value : end);\n const renderStart = phaseStart(entry.renderStart);\n const layoutStart = phaseStart(entry.styleAndLayoutStart);\n let forced = 0;\n\n for (const script of entry.scripts ?? []) {\n forced += script.forcedStyleAndLayoutDuration ?? 0;\n }\n\n const phases: [string, number][] = [\n [\"script\", renderStart - start],\n [\"render\", layoutStart - renderStart],\n [\"style_layout\", end - layoutStart],\n [\"forced_layout\", forced],\n ];\n\n for (const name of names) {\n for (const [phase, ms] of phases) {\n this.ctx.logger.logMetric(PROFILE_FRAME_METRIC_NAME, ms, \"ms\", \"histogram\", {\n [PROFILE_KEYS.probe]: name,\n [PROFILE_KEYS.framePhase]: phase,\n });\n }\n }\n }\n}\n\n/** Measures the time between consecutive frames with the frame pacing probe. */\nexport class FramePacingCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"frame-pacing\";\n\n /** Handle of the pending frame callback. Undefined while the capture isn't installed. */\n private handle: number | undefined;\n\n /** Start time of the last frame. -1 before the first frame and after the page was hidden. */\n private last = -1;\n\n /**\n * @param ctx Capture context: configuration, diagnostics and logger.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** A hidden page gets no frame callbacks, so the first frame back isn't an interval. */\n private readonly onVisibility = (): void => {\n this.last = -1;\n };\n\n /** Starts the frame callback loop. */\n install(): void {\n const scope = globalThis as FrameScope;\n const { requestAnimationFrame: request } = scope;\n\n if (this.handle !== undefined) {\n return;\n }\n\n if (typeof request !== \"function\") {\n const { once } = this.ctx;\n\n if (!once.framePacing) {\n once.framePacing = true;\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"This context has no frame callback. The frame pacing of the profiler is off.\",\n );\n }\n\n return;\n }\n\n const probe = profilerCore().probe(PROFILE_FRAME_PROBE, undefined, this.ctx.diagnostics);\n const frame = (time: number): void => {\n // The browser calls this directly, so anything we throw is an uncaught error on the page.\n // It also runs every frame, which is why the try block allocates nothing.\n try {\n if (this.last >= 0) {\n probe.record(time - this.last);\n }\n } catch (error) {\n this.ctx.diagnostics.report(\n \"capture.record_failed\",\n \"The library could not record a frame interval of the profiler.\",\n undefined,\n error,\n );\n }\n\n this.last = time;\n this.handle = request(frame);\n };\n\n scope.document?.addEventListener(\"visibilitychange\", this.onVisibility);\n this.handle = request(frame);\n }\n\n /** Stops the frame callback loop. */\n uninstall(): void {\n const scope = globalThis as FrameScope;\n\n if (this.handle === undefined) {\n return;\n }\n\n scope.cancelAnimationFrame?.(this.handle);\n scope.document?.removeEventListener(\"visibilitychange\", this.onVisibility);\n this.handle = undefined;\n this.last = -1;\n }\n}\n"],"mappings":";;;;;AAiBA,IAAMM,IAAa,wBA2BNC,IAAb,MAAmD;CAajD,YAAY,GAAsC;EAArB,AAAAF,EAAA,MAAA,OAAA,KAAA,CAAA,GAX7BA,EAAA,MAAA,QAAgB,cAAA,GAGhBA,EAAA,MAAA,YAAA,KAAA,CAAA,GAGAA,EAAA,MAAA,UAAuC;GAAE,OAAO;GAAG,OAAO;EAAE,CAAA,GAK/B,KAAA,MAAAG;CAAsB;CAGnD,UAAgB;EACd,IAAI,MAAK,UAUT;QAJE,OAA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AAuB,KAAK,MAAM,GACxCA,EAAM,UAAU,oBAAoB,oBAAoB,KAAK,YAAY,GACzE,KAAK,SAAS,KAAA,GACd,KAAK,OAAO;CACd;AACF"}
|
|
1
|
+
{"version":3,"file":"profiler-frames-C4ySHN0X.js","names":["PROFILE_FRAME_METRIC_NAME","PROFILE_KEYS","PROFILE_FRAME_PROBE","profilerCore","allowInWindow","_defineProperty","FRAME_TYPE","FramePhasesCapture","ctx","entry","list","once","start","end","names","captureLimits","phaseStart","value","renderStart","layoutStart","forced","script","phases","name","phase","ms","FramePacingCapture","scope","request","probe","frame","time","error"],"sources":["../src/capture/profiler-frames.ts"],"sourcesContent":["// src/capture/profiler-frames.ts\n//\n// Ties the profiler to the browser's rendering work. The frame phases capture attributes the\n// phases of each long animation frame to the probes that ran in it. Frame pacing measures the\n// time between consecutive frames.\n\nimport {\n PROFILE_FRAME_METRIC_NAME,\n PROFILE_FRAME_PROBE,\n PROFILE_KEYS,\n PROFILER_LINK_MIN_MS,\n} from \"../constants\";\nimport { profilerCore } from \"../core/profiler\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Long animation frames, not long tasks: long tasks don't have phases. */\nconst FRAME_TYPE = \"long-animation-frame\";\n\n/** One script in a long animation frame. */\ninterface FrameScript {\n /** Style and layout time the script forced, in ms. */\n forcedStyleAndLayoutDuration?: number;\n}\n\n/** A long animation frame. Some versions of the DOM typings don't declare these fields. */\ninterface PhaseEntry extends PerformanceEntry {\n /** When the render callbacks started. 0 if the frame didn't render. */\n renderStart?: number;\n /** When style and layout started. 0 if the frame didn't render. */\n styleAndLayoutStart?: number;\n /** The scripts that ran in the frame. */\n scripts?: FrameScript[];\n}\n\n/** The page globals frame pacing needs. A worker or Node.js may have none of them. */\ninterface FrameScope {\n /** Calls a function before the next paint, passing the frame's start time. */\n requestAnimationFrame?: (callback: (time: number) => void) => number;\n cancelAnimationFrame?: (handle: number) => void;\n document?: Pick<Document, \"addEventListener\" | \"removeEventListener\">;\n}\n\n/** Attributes the phases of each long animation frame to every probe with a span in it. */\nexport class FramePhasesCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"frame-phases\";\n\n /** The active observer. Undefined while the capture isn't installed. */\n private observer: PerformanceObserver | undefined;\n\n /** Rate limit for this capture, so a frozen tab can't flood the pipeline. */\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n /**\n * @param ctx Capture context: configuration, diagnostics and logger.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Starts observing long animation frames and turns on the recent-span ring. */\n install(): void {\n if (this.observer) {\n return;\n }\n\n // Older browsers have no supportedEntryTypes. The capture just stays off there.\n const supported: readonly string[] | undefined =\n typeof PerformanceObserver === \"undefined\"\n ? undefined\n : PerformanceObserver.supportedEntryTypes;\n\n if (!supported?.includes(FRAME_TYPE)) {\n // Report on the first install in a document only, not on every reinstall after configure().\n const { once } = this.ctx;\n\n if (!once.framePhases) {\n once.framePhases = true;\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The browser does not report long animation frames. profiler.framePhases is off.\",\n );\n }\n\n return;\n }\n\n profilerCore().link(PROFILER_LINK_MIN_MS);\n this.observer = new PerformanceObserver((list) => {\n // The browser calls this directly, so anything we throw is an uncaught error on the page.\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not record a long animation frame of the profiler.\",\n () => {\n for (const entry of list.getEntries()) {\n this.record(entry);\n }\n },\n );\n });\n\n // Not buffered: a buffered frame is older than anything in the ring and would link to nothing.\n this.observer.observe({ type: FRAME_TYPE });\n }\n\n /** Disconnects the observer and turns the recent-span ring off. */\n uninstall(): void {\n if (!this.observer) {\n return;\n }\n\n this.observer.disconnect();\n this.observer = undefined;\n profilerCore().link(Infinity);\n }\n\n /**\n * Records one frame's phases for every probe that had a span in the frame.\n * @param entry Long animation frame entry.\n */\n private record(entry: PhaseEntry): void {\n const start = entry.startTime;\n const end = start + entry.duration;\n const names = profilerCore().linked(start, end);\n\n if (names.length === 0) {\n return;\n }\n\n const { captureLimits } = this.ctx.config;\n\n if (\n !allowInWindow(\n this.window,\n captureLimits.longFramesPerWindow,\n this.ctx.diagnostics,\n \"profiler frames\",\n captureLimits.windowMs,\n )\n ) {\n return;\n }\n\n // A frame that didn't render has 0 in both fields. The whole frame then counts as script.\n const phaseStart = (value = 0): number => (value > 0 ? value : end);\n const renderStart = phaseStart(entry.renderStart);\n const layoutStart = phaseStart(entry.styleAndLayoutStart);\n let forced = 0;\n\n for (const script of entry.scripts ?? []) {\n forced += script.forcedStyleAndLayoutDuration ?? 0;\n }\n\n const phases: [string, number][] = [\n [\"script\", renderStart - start],\n [\"render\", layoutStart - renderStart],\n [\"style_layout\", end - layoutStart],\n [\"forced_layout\", forced],\n ];\n\n for (const name of names) {\n for (const [phase, ms] of phases) {\n this.ctx.logger.logMetric(PROFILE_FRAME_METRIC_NAME, ms, \"ms\", \"histogram\", {\n [PROFILE_KEYS.probe]: name,\n [PROFILE_KEYS.framePhase]: phase,\n });\n }\n }\n }\n}\n\n/** Measures the time between consecutive frames with the frame pacing probe. */\nexport class FramePacingCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"frame-pacing\";\n\n /** Handle of the pending frame callback. Undefined while the capture isn't installed. */\n private handle: number | undefined;\n\n /** Start time of the last frame. -1 before the first frame and after the page was hidden. */\n private last = -1;\n\n /**\n * @param ctx Capture context: configuration, diagnostics and logger.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** A hidden page gets no frame callbacks, so the first frame back isn't an interval. */\n private readonly onVisibility = (): void => {\n this.last = -1;\n };\n\n /** Starts the frame callback loop. */\n install(): void {\n const scope = globalThis as FrameScope;\n const { requestAnimationFrame: request } = scope;\n\n if (this.handle !== undefined) {\n return;\n }\n\n if (typeof request !== \"function\") {\n const { once } = this.ctx;\n\n if (!once.framePacing) {\n once.framePacing = true;\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"This context has no frame callback. The frame pacing of the profiler is off.\",\n );\n }\n\n return;\n }\n\n const probe = profilerCore().probe(PROFILE_FRAME_PROBE, undefined, this.ctx.diagnostics);\n const frame = (time: number): void => {\n // The browser calls this directly, so anything we throw is an uncaught error on the page.\n // It also runs every frame, which is why the try block allocates nothing.\n try {\n if (this.last >= 0) {\n probe.record(time - this.last);\n }\n } catch (error) {\n this.ctx.diagnostics.report(\n \"capture.record_failed\",\n \"The library could not record a frame interval of the profiler.\",\n undefined,\n error,\n );\n }\n\n this.last = time;\n this.handle = request(frame);\n };\n\n scope.document?.addEventListener(\"visibilitychange\", this.onVisibility);\n this.handle = request(frame);\n }\n\n /** Stops the frame callback loop. */\n uninstall(): void {\n const scope = globalThis as FrameScope;\n\n if (this.handle === undefined) {\n return;\n }\n\n scope.cancelAnimationFrame?.(this.handle);\n scope.document?.removeEventListener(\"visibilitychange\", this.onVisibility);\n this.handle = undefined;\n this.last = -1;\n }\n}\n"],"mappings":";;;;;AAiBA,IAAMM,IAAa,wBA2BNC,IAAb,MAAmD;CAajD,YAAY,GAAsC;EAArB,AAAAF,EAAA,MAAA,OAAA,KAAA,CAAA,GAX7BA,EAAA,MAAA,QAAgB,cAAA,GAGhBA,EAAA,MAAA,YAAA,KAAA,CAAA,GAGAA,EAAA,MAAA,UAAuC;GAAE,OAAO;GAAG,OAAO;EAAE,CAAA,GAK/B,KAAA,MAAAG;CAAsB;CAGnD,UAAgB;EACd,IAAI,MAAK,UAUT;QAJE,OAAO,sBAAwB,MAC3B,KAAA,IACA,oBAAoB,oBAAA,EAEV,SAASF,CAAU,GA8BnC,AAfAH,EAAa,CAAC,CAAC,KAAA,CAAyB,GACxC,KAAK,WAAW,IAAI,qBAAqB,MAAS;IAEhD,KAAK,IAAI,YAAY,MACnB,yBACA,8EACM;KACJ,KAAK,IAAMM,KAASC,EAAK,WAAW,GAClC,KAAK,OAAOD,CAAK;IAErB,CACF;GACF,CAAC,GAGD,KAAK,SAAS,QAAQ,EAAE,MAAMH,EAAW,CAAC;QA9BJ;IAEpC,I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UAAA,KAAA,CAAA,GAGAA,EAAA,MAAA,QAAe,EAAA,GAQfA,EAAA,MAAA,sBAA4C;GAC1C,KAAK,OAAO;EACd,CAAA,GAL6B,KAAA,MAAAG;CAAsB;CAQnD,UAAgB;EACd,IAAMmB,IAAQ,YACR,EAAE,uBAAuBC,MAAYD;EAE3C,IAAI,KAAK,WAAW,KAAA,GAClB;EAGF,IAAI,OAAOC,KAAY,YAAY;GACjC,IAAM,EAAE,YAAS,KAAK;GAEtB,AAAKjB,EAAK,gBACR,EAAK,cAAc,IACnB,KAAK,IAAI,YAAY,OACnB,0BACA,8EACF;GAGF;EACF;EAEA,IAAMkB,IAAQ1B,EAAa,CAAC,CAAC,MAAMD,GAAqB,KAAA,GAAW,KAAK,IAAI,WAAW,GACjF4B,KAAS,MAAuB;GAGpC,IAAI;IACF,AAAI,KAAK,QAAQ,KACfD,EAAM,OAAOE,IAAO,KAAK,IAAI;GAEjC,SAASC,GAAO;IACd,KAAK,IAAI,YAAY,OACnB,yBACA,kEACA,KAAA,GACAA,CACF;GACF;GAGA,AADA,KAAK,OAAOD,GACZ,KAAK,SAASH,EAAQE,CAAK;EAC7B;EAGA,AADAH,EAAM,UAAU,iBAAiB,oBAAoB,KAAK,YAAY,GACtE,KAAK,SAASC,EAAQE,CAAK;CAC7B;CAGA,YAAkB;EAChB,IAAMH,IAAQ;EAEd,AAAI,KAAK,WAAW,KAAA,MAIpBA,EAAM,uBAAuB,KAAK,MAAM,GACxCA,EAAM,UAAU,oBAAoB,oBAAoB,KAAK,YAAY,GACzE,KAAK,SAAS,KAAA,GACd,KAAK,OAAO;CACd;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./constants-
|
|
2
|
-
//# sourceMappingURL=profiler-frames-
|
|
1
|
+
const e=require("./constants-CtF52hIV.cjs"),t=require("./profiler-BvWW2kNM.cjs"),n=require("./storm-BHgI12iS.cjs"),r=require("./defineProperty-X1c4tIPD.cjs");var i=`long-animation-frame`,a=class{constructor(e){r.t(this,`ctx`,void 0),r.t(this,`name`,`frame-phases`),r.t(this,`observer`,void 0),r.t(this,`window`,{start:0,count:0}),this.ctx=e}install(){if(!this.observer){if((typeof PerformanceObserver>`u`?void 0:PerformanceObserver.supportedEntryTypes)?.includes(i))t.t().link(1),this.observer=new PerformanceObserver(e=>{this.ctx.diagnostics.guard(`capture.record_failed`,`The library could not record a long animation frame of the profiler.`,()=>{for(let t of e.getEntries())this.record(t)})}),this.observer.observe({type:i});else{let{once:e}=this.ctx;e.framePhases||(e.framePhases=!0,this.ctx.diagnostics.report(`capture.install_failed`,`The browser does not report long animation frames. profiler.framePhases is off.`))}}}uninstall(){this.observer&&(this.observer.disconnect(),this.observer=void 0,t.t().link(1/0))}record(r){let i=r.startTime,a=i+r.duration,o=t.t().linked(i,a);if(o.length===0)return;let{captureLimits:s}=this.ctx.config;if(!n.t(this.window,s.longFramesPerWindow,this.ctx.diagnostics,`profiler frames`,s.windowMs))return;let c=(e=0)=>e>0?e:a,l=c(r.renderStart),u=c(r.styleAndLayoutStart),d=0;for(let e of r.scripts??[])d+=e.forcedStyleAndLayoutDuration??0;let f=[[`script`,l-i],[`render`,u-l],[`style_layout`,a-u],[`forced_layout`,d]];for(let t of o)for(let[n,r]of f)this.ctx.logger.logMetric(e.en,r,`ms`,`histogram`,{[e.nn.probe]:t,[e.nn.framePhase]:n})}},o=class{constructor(e){r.t(this,`ctx`,void 0),r.t(this,`name`,`frame-pacing`),r.t(this,`handle`,void 0),r.t(this,`last`,-1),r.t(this,`onVisibility`,()=>{this.last=-1}),this.ctx=e}install(){let n=globalThis,{requestAnimationFrame:r}=n;if(this.handle!==void 0)return;if(typeof r!=`function`){let{once:e}=this.ctx;e.framePacing||(e.framePacing=!0,this.ctx.diagnostics.report(`capture.install_failed`,`This context has no frame callback. The frame pacing of the profiler is off.`));return}let i=t.t().probe(e.tn,void 0,this.ctx.diagnostics),a=e=>{try{this.last>=0&&i.record(e-this.last)}catch(e){this.ctx.diagnostics.report(`capture.record_failed`,`The library could not record a frame interval of the profiler.`,void 0,e)}this.last=e,this.handle=r(a)};n.document?.addEventListener(`visibilitychange`,this.onVisibility),this.handle=r(a)}uninstall(){let e=globalThis;this.handle!==void 0&&(e.cancelAnimationFrame?.(this.handle),e.document?.removeEventListener(`visibilitychange`,this.onVisibility),this.handle=void 0,this.last=-1)}};exports.FramePacingCapture=o,exports.FramePhasesCapture=a;
|
|
2
|
+
//# sourceMappingURL=profiler-frames-DeaBiB-5.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiler-frames-C4xr7KfH.cjs","names":["profilerCore","allowInWindow","PROFILE_FRAME_METRIC_NAME","PROFILE_KEYS","PROFILE_FRAME_PROBE","require_constants","require_profiler","require_storm","require_defineProperty","FRAME_TYPE","FramePhasesCapture","ctx","entry","list","once","start","end","names","captureLimits","phaseStart","value","renderStart","layoutStart","forced","script","phases","name","phase","ms","FramePacingCapture","scope","request","probe","frame","time","error"],"sources":["../src/capture/profiler-frames.ts"],"sourcesContent":["// src/capture/profiler-frames.ts\n//\n// Ties the profiler to the browser's rendering work. The frame phases capture attributes the\n// phases of each long animation frame to the probes that ran in it. Frame pacing measures the\n// time between consecutive frames.\n\nimport {\n PROFILE_FRAME_METRIC_NAME,\n PROFILE_FRAME_PROBE,\n PROFILE_KEYS,\n PROFILER_LINK_MIN_MS,\n} from \"../constants\";\nimport { profilerCore } from \"../core/profiler\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Long animation frames, not long tasks: long tasks don't have phases. */\nconst FRAME_TYPE = \"long-animation-frame\";\n\n/** One script in a long animation frame. */\ninterface FrameScript {\n /** Style and layout time the script forced, in ms. */\n forcedStyleAndLayoutDuration?: number;\n}\n\n/** A long animation frame. Some versions of the DOM typings don't declare these fields. */\ninterface PhaseEntry extends PerformanceEntry {\n /** When the render callbacks started. 0 if the frame didn't render. */\n renderStart?: number;\n /** When style and layout started. 0 if the frame didn't render. */\n styleAndLayoutStart?: number;\n /** The scripts that ran in the frame. */\n scripts?: FrameScript[];\n}\n\n/** The page globals frame pacing needs. A worker or Node.js may have none of them. */\ninterface FrameScope {\n /** Calls a function before the next paint, passing the frame's start time. */\n requestAnimationFrame?: (callback: (time: number) => void) => number;\n cancelAnimationFrame?: (handle: number) => void;\n document?: Pick<Document, \"addEventListener\" | \"removeEventListener\">;\n}\n\n/** Attributes the phases of each long animation frame to every probe with a span in it. */\nexport class FramePhasesCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"frame-phases\";\n\n /** The active observer. Undefined while the capture isn't installed. */\n private observer: PerformanceObserver | undefined;\n\n /** Rate limit for this capture, so a frozen tab can't flood the pipeline. */\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n /**\n * @param ctx Capture context: configuration, diagnostics and logger.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Starts observing long animation frames and turns on the recent-span ring. */\n install(): void {\n if (this.observer) {\n return;\n }\n\n // Older browsers have no supportedEntryTypes. The capture just stays off there.\n const supported: readonly string[] | undefined =\n typeof PerformanceObserver === \"undefined\"\n ? undefined\n : PerformanceObserver.supportedEntryTypes;\n\n if (!supported?.includes(FRAME_TYPE)) {\n // Report on the first install in a document only, not on every reinstall after configure().\n const { once } = this.ctx;\n\n if (!once.framePhases) {\n once.framePhases = true;\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The browser does not report long animation frames. profiler.framePhases is off.\",\n );\n }\n\n return;\n }\n\n profilerCore().link(PROFILER_LINK_MIN_MS);\n this.observer = new PerformanceObserver((list) => {\n // The browser calls this directly, so anything we throw is an uncaught error on the page.\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not record a long animation frame of the profiler.\",\n () => {\n for (const entry of list.getEntries()) {\n this.record(entry);\n }\n },\n );\n });\n\n // Not buffered: a buffered frame is older than anything in the ring and would link to nothing.\n this.observer.observe({ type: FRAME_TYPE });\n }\n\n /** Disconnects the observer and turns the recent-span ring off. */\n uninstall(): void {\n if (!this.observer) {\n return;\n }\n\n this.observer.disconnect();\n this.observer = undefined;\n profilerCore().link(Infinity);\n }\n\n /**\n * Records one frame's phases for every probe that had a span in the frame.\n * @param entry Long animation frame entry.\n */\n private record(entry: PhaseEntry): void {\n const start = entry.startTime;\n const end = start + entry.duration;\n const names = profilerCore().linked(start, end);\n\n if (names.length === 0) {\n return;\n }\n\n const { captureLimits } = this.ctx.config;\n\n if (\n !allowInWindow(\n this.window,\n captureLimits.longFramesPerWindow,\n this.ctx.diagnostics,\n \"profiler frames\",\n captureLimits.windowMs,\n )\n ) {\n return;\n }\n\n // A frame that didn't render has 0 in both fields. The whole frame then counts as script.\n const phaseStart = (value = 0): number => (value > 0 ? value : end);\n const renderStart = phaseStart(entry.renderStart);\n const layoutStart = phaseStart(entry.styleAndLayoutStart);\n let forced = 0;\n\n for (const script of entry.scripts ?? []) {\n forced += script.forcedStyleAndLayoutDuration ?? 0;\n }\n\n const phases: [string, number][] = [\n [\"script\", renderStart - start],\n [\"render\", layoutStart - renderStart],\n [\"style_layout\", end - layoutStart],\n [\"forced_layout\", forced],\n ];\n\n for (const name of names) {\n for (const [phase, ms] of phases) {\n this.ctx.logger.logMetric(PROFILE_FRAME_METRIC_NAME, ms, \"ms\", \"histogram\", {\n [PROFILE_KEYS.probe]: name,\n [PROFILE_KEYS.framePhase]: phase,\n });\n }\n }\n }\n}\n\n/** Measures the time between consecutive frames with the frame pacing probe. */\nexport class FramePacingCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"frame-pacing\";\n\n /** Handle of the pending frame callback. Undefined while the capture isn't installed. */\n private handle: number | undefined;\n\n /** Start time of the last frame. -1 before the first frame and after the page was hidden. */\n private last = -1;\n\n /**\n * @param ctx Capture context: configuration, diagnostics and logger.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** A hidden page gets no frame callbacks, so the first frame back isn't an interval. */\n private readonly onVisibility = (): void => {\n this.last = -1;\n };\n\n /** Starts the frame callback loop. */\n install(): void {\n const scope = globalThis as FrameScope;\n const { requestAnimationFrame: request } = scope;\n\n if (this.handle !== undefined) {\n return;\n }\n\n if (typeof request !== \"function\") {\n const { once } = this.ctx;\n\n if (!once.framePacing) {\n once.framePacing = true;\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"This context has no frame callback. The frame pacing of the profiler is off.\",\n );\n }\n\n return;\n }\n\n const probe = profilerCore().probe(PROFILE_FRAME_PROBE, undefined, this.ctx.diagnostics);\n const frame = (time: number): void => {\n // The browser calls this directly, so anything we throw is an uncaught error on the page.\n // It also runs every frame, which is why the try block allocates nothing.\n try {\n if (this.last >= 0) {\n probe.record(time - this.last);\n }\n } catch (error) {\n this.ctx.diagnostics.report(\n \"capture.record_failed\",\n \"The library could not record a frame interval of the profiler.\",\n undefined,\n error,\n );\n }\n\n this.last = time;\n this.handle = request(frame);\n };\n\n scope.document?.addEventListener(\"visibilitychange\", this.onVisibility);\n this.handle = request(frame);\n }\n\n /** Stops the frame callback loop. */\n uninstall(): void {\n const scope = globalThis as FrameScope;\n\n if (this.handle === undefined) {\n return;\n }\n\n scope.cancelAnimationFrame?.(this.handle);\n scope.document?.removeEventListener(\"visibilitychange\", this.onVisibility);\n this.handle = undefined;\n this.last = -1;\n }\n}\n"],"mappings":"A,8JAiBA,IAAMS,EAAa,uBA2BNC,EAAb,KAAmD,CAajD,YAAY,EAAsC,CAArBF,EAAA,EAAA,KAAA,MAAA,IAAA,EAAA,EAX7BA,EAAA,EAAA,KAAA,OAAgB,cAAA,EAGhBA,EAAA,EAAA,KAAA,WAAA,IAAA,EAAA,EAGAA,EAAA,EAAA,KAAA,SAAuC,CAAE,MAAO,EAAG,MAAO,CAAE,CAAA,EAK/B,KAAA,IAAAG,CAAsB,CAGnD,SAAgB,CACd,GAAI,MAAK,SAUT,KAJE,OAAO,oBAAwB,IAC3B,IAAA,GACA,oBAAoB,oBAAA,EAEV,SAASF,CAAU,EAenCH,EAAA,EAAa,CAAC,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B,KAAK,YAAY,EACzE,KAAK,OAAS,IAAA,GACd,KAAK,KAAO,GACd,CACF,E"}
|
|
1
|
+
{"version":3,"file":"profiler-frames-DeaBiB-5.cjs","names":["profilerCore","allowInWindow","PROFILE_FRAME_METRIC_NAME","PROFILE_KEYS","PROFILE_FRAME_PROBE","require_constants","require_profiler","require_storm","require_defineProperty","FRAME_TYPE","FramePhasesCapture","ctx","entry","list","once","start","end","names","captureLimits","phaseStart","value","renderStart","layoutStart","forced","script","phases","name","phase","ms","FramePacingCapture","scope","request","probe","frame","time","error"],"sources":["../src/capture/profiler-frames.ts"],"sourcesContent":["// src/capture/profiler-frames.ts\n//\n// Ties the profiler to the browser's rendering work. The frame phases capture attributes the\n// phases of each long animation frame to the probes that ran in it. Frame pacing measures the\n// time between consecutive frames.\n\nimport {\n PROFILE_FRAME_METRIC_NAME,\n PROFILE_FRAME_PROBE,\n PROFILE_KEYS,\n PROFILER_LINK_MIN_MS,\n} from \"../constants\";\nimport { profilerCore } from \"../core/profiler\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Long animation frames, not long tasks: long tasks don't have phases. */\nconst FRAME_TYPE = \"long-animation-frame\";\n\n/** One script in a long animation frame. */\ninterface FrameScript {\n /** Style and layout time the script forced, in ms. */\n forcedStyleAndLayoutDuration?: number;\n}\n\n/** A long animation frame. Some versions of the DOM typings don't declare these fields. */\ninterface PhaseEntry extends PerformanceEntry {\n /** When the render callbacks started. 0 if the frame didn't render. */\n renderStart?: number;\n /** When style and layout started. 0 if the frame didn't render. */\n styleAndLayoutStart?: number;\n /** The scripts that ran in the frame. */\n scripts?: FrameScript[];\n}\n\n/** The page globals frame pacing needs. A worker or Node.js may have none of them. */\ninterface FrameScope {\n /** Calls a function before the next paint, passing the frame's start time. */\n requestAnimationFrame?: (callback: (time: number) => void) => number;\n cancelAnimationFrame?: (handle: number) => void;\n document?: Pick<Document, \"addEventListener\" | \"removeEventListener\">;\n}\n\n/** Attributes the phases of each long animation frame to every probe with a span in it. */\nexport class FramePhasesCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"frame-phases\";\n\n /** The active observer. Undefined while the capture isn't installed. */\n private observer: PerformanceObserver | undefined;\n\n /** Rate limit for this capture, so a frozen tab can't flood the pipeline. */\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n /**\n * @param ctx Capture context: configuration, diagnostics and logger.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Starts observing long animation frames and turns on the recent-span ring. */\n install(): void {\n if (this.observer) {\n return;\n }\n\n // Older browsers have no supportedEntryTypes. The capture just stays off there.\n const supported: readonly string[] | undefined =\n typeof PerformanceObserver === \"undefined\"\n ? undefined\n : PerformanceObserver.supportedEntryTypes;\n\n if (!supported?.includes(FRAME_TYPE)) {\n // Report on the first install in a document only, not on every reinstall after configure().\n const { once } = this.ctx;\n\n if (!once.framePhases) {\n once.framePhases = true;\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The browser does not report long animation frames. profiler.framePhases is off.\",\n );\n }\n\n return;\n }\n\n profilerCore().link(PROFILER_LINK_MIN_MS);\n this.observer = new PerformanceObserver((list) => {\n // The browser calls this directly, so anything we throw is an uncaught error on the page.\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not record a long animation frame of the profiler.\",\n () => {\n for (const entry of list.getEntries()) {\n this.record(entry);\n }\n },\n );\n });\n\n // Not buffered: a buffered frame is older than anything in the ring and would link to nothing.\n this.observer.observe({ type: FRAME_TYPE });\n }\n\n /** Disconnects the observer and turns the recent-span ring off. */\n uninstall(): void {\n if (!this.observer) {\n return;\n }\n\n this.observer.disconnect();\n this.observer = undefined;\n profilerCore().link(Infinity);\n }\n\n /**\n * Records one frame's phases for every probe that had a span in the frame.\n * @param entry Long animation frame entry.\n */\n private record(entry: PhaseEntry): void {\n const start = entry.startTime;\n const end = start + entry.duration;\n const names = profilerCore().linked(start, end);\n\n if (names.length === 0) {\n return;\n }\n\n const { captureLimits } = this.ctx.config;\n\n if (\n !allowInWindow(\n this.window,\n captureLimits.longFramesPerWindow,\n this.ctx.diagnostics,\n \"profiler frames\",\n captureLimits.windowMs,\n )\n ) {\n return;\n }\n\n // A frame that didn't render has 0 in both fields. The whole frame then counts as script.\n const phaseStart = (value = 0): number => (value > 0 ? value : end);\n const renderStart = phaseStart(entry.renderStart);\n const layoutStart = phaseStart(entry.styleAndLayoutStart);\n let forced = 0;\n\n for (const script of entry.scripts ?? []) {\n forced += script.forcedStyleAndLayoutDuration ?? 0;\n }\n\n const phases: [string, number][] = [\n [\"script\", renderStart - start],\n [\"render\", layoutStart - renderStart],\n [\"style_layout\", end - layoutStart],\n [\"forced_layout\", forced],\n ];\n\n for (const name of names) {\n for (const [phase, ms] of phases) {\n this.ctx.logger.logMetric(PROFILE_FRAME_METRIC_NAME, ms, \"ms\", \"histogram\", {\n [PROFILE_KEYS.probe]: name,\n [PROFILE_KEYS.framePhase]: phase,\n });\n }\n }\n }\n}\n\n/** Measures the time between consecutive frames with the frame pacing probe. */\nexport class FramePacingCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"frame-pacing\";\n\n /** Handle of the pending frame callback. Undefined while the capture isn't installed. */\n private handle: number | undefined;\n\n /** Start time of the last frame. -1 before the first frame and after the page was hidden. */\n private last = -1;\n\n /**\n * @param ctx Capture context: configuration, diagnostics and logger.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** A hidden page gets no frame callbacks, so the first frame back isn't an interval. */\n private readonly onVisibility = (): void => {\n this.last = -1;\n };\n\n /** Starts the frame callback loop. */\n install(): void {\n const scope = globalThis as FrameScope;\n const { requestAnimationFrame: request } = scope;\n\n if (this.handle !== undefined) {\n return;\n }\n\n if (typeof request !== \"function\") {\n const { once } = this.ctx;\n\n if (!once.framePacing) {\n once.framePacing = true;\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"This context has no frame callback. The frame pacing of the profiler is off.\",\n );\n }\n\n return;\n }\n\n const probe = profilerCore().probe(PROFILE_FRAME_PROBE, undefined, this.ctx.diagnostics);\n const frame = (time: number): void => {\n // The browser calls this directly, so anything we throw is an uncaught error on the page.\n // It also runs every frame, which is why the try block allocates nothing.\n try {\n if (this.last >= 0) {\n probe.record(time - this.last);\n }\n } catch (error) {\n this.ctx.diagnostics.report(\n \"capture.record_failed\",\n \"The library could not record a frame interval of the profiler.\",\n undefined,\n error,\n );\n }\n\n this.last = time;\n this.handle = request(frame);\n };\n\n scope.document?.addEventListener(\"visibilitychange\", this.onVisibility);\n this.handle = request(frame);\n }\n\n /** Stops the frame callback loop. */\n uninstall(): void {\n const scope = globalThis as FrameScope;\n\n if (this.handle === undefined) {\n return;\n }\n\n scope.cancelAnimationFrame?.(this.handle);\n scope.document?.removeEventListener(\"visibilitychange\", this.onVisibility);\n this.handle = undefined;\n this.last = -1;\n }\n}\n"],"mappings":"A,8JAiBA,IAAMS,EAAa,uBA2BNC,EAAb,KAAmD,CAajD,YAAY,EAAsC,CAArBF,EAAA,EAAA,KAAA,MAAA,IAAA,EAAA,EAX7BA,EAAA,EAAA,KAAA,OAAgB,cAAA,EAGhBA,EAAA,EAAA,KAAA,WAAA,IAAA,EAAA,EAGAA,EAAA,EAAA,KAAA,SAAuC,CAAE,MAAO,EAAG,MAAO,CAAE,CAAA,EAK/B,KAAA,IAAAG,CAAsB,CAGnD,SAAgB,CACd,GAAI,MAAK,SAUT,KAJE,OAAO,oBAAwB,IAC3B,IAAA,GACA,oBAAoB,oBAAA,EAEV,SAASF,CAAU,EAenCH,EAAA,EAAa,CAAC,CAAC,KAAA,CAAyB,EACxC,KAAK,SAAW,IAAI,oBAAqB,GAAS,CAEhD,KAAK,IAAI,YAAY,MACnB,wBACA,2EACM,CACJ,IAAK,IAAMM,KAASC,EAAK,WAAW,EAClC,KAAK,OAAOD,CAAK,CAErB,CACF,CACF,CAAC,EAGD,KAAK,SAAS,QAAQ,CAAE,KAAMH,CAAW,CAAC,MA9BJ,CAEpC,GAAM,CAAE,Q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AAA,EAGhBA,EAAA,EAAA,KAAA,SAAA,IAAA,EAAA,EAGAA,EAAA,EAAA,KAAA,OAAe,EAAA,EAQfA,EAAA,EAAA,KAAA,mBAA4C,CAC1C,KAAK,KAAO,EACd,CAAA,EAL6B,KAAA,IAAAG,CAAsB,CAQnD,SAAgB,CACd,IAAMmB,EAAQ,WACR,CAAE,sBAAuBC,GAAYD,EAE3C,GAAI,KAAK,SAAW,IAAA,GAClB,OAGF,GAAI,OAAOC,GAAY,WAAY,CACjC,GAAM,CAAE,QAAS,KAAK,IAEjBjB,EAAK,cACR,EAAK,YAAc,GACnB,KAAK,IAAI,YAAY,OACnB,yBACA,8EACF,GAGF,MACF,CAEA,IAAMkB,EAAQhC,EAAAA,EAAa,CAAC,CAAC,MAAMI,EAAAA,GAAqB,IAAA,GAAW,KAAK,IAAI,WAAW,EACjF6B,EAAS,GAAuB,CAGpC,GAAI,CACE,KAAK,MAAQ,GACfD,EAAM,OAAOE,EAAO,KAAK,IAAI,CAEjC,OAASC,EAAO,CACd,KAAK,IAAI,YAAY,OACnB,wBACA,iEACA,IAAA,GACAA,CACF,CACF,CAEA,KAAK,KAAOD,EACZ,KAAK,OAASH,EAAQE,CAAK,CAC7B,EAEAH,EAAM,UAAU,iBAAiB,mBAAoB,KAAK,YAAY,EACtE,KAAK,OAASC,EAAQE,CAAK,CAC7B,CAGA,WAAkB,CAChB,IAAMH,EAAQ,WAEV,KAAK,SAAW,IAAA,KAIpBA,EAAM,uBAAuB,KAAK,MAAM,EACxCA,EAAM,UAAU,oBAAoB,mBAAoB,KAAK,YAAY,EACzE,KAAK,OAAS,IAAA,GACd,KAAK,KAAO,GACd,CACF,E"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./constants-
|
|
2
|
-
//# sourceMappingURL=remote-rules-
|
|
1
|
+
const e=require("./constants-CtF52hIV.cjs"),t=require("./guards-EjG3ahFp.cjs"),n=require("./sampling-B46LW0cy.cjs"),r=require("./defineProperty-X1c4tIPD.cjs");var i=class{constructor(e){r.t(this,`config`,void 0),r.t(this,`rules`,null),r.t(this,`receivedAt`,0),r.t(this,`until`,0),this.config=e}apply(e){if(!e){this.rules=null;return}let t=Date.now();this.rules=e.rules,this.receivedAt=t,this.until=t+e.ttlMs}current(){if(!this.rules)return null;let e=Date.now();return!this.config.sampling.remote||e<this.receivedAt||e>=this.until?(this.rules=null,null):this.rules}minLevelFor(t){let r=n.n(t,this.config),i=this.current(),a=n.r(t,i?.minLevels??{})?.value??i?.minLevel;return a!==void 0&&e.At[a]<e.At[r]?a:r}wire(){let e=this.current();return e?{...e,v:1,ttlMs:this.until-Date.now()}:null}},a=class extends Error{};function o(e){return typeof e==`number`&&e>=0&&e<=1}function s(t){if(t.length>4096)throw new a(`The header is longer than ${String(e.dn)} characters.`);try{return JSON.parse(t)}catch{throw new a(`The header is not valid JSON.`)}}function c(e){if(e===void 0)return{};let n=`rates must be an object with at most 100 rates from 0 to 1.`;if(!t.n(e))throw new a(n);let r=Object.entries(e);if(r.length>100||!r.every(([,e])=>o(e)))throw new a(n);return Object.fromEntries(r)}function l(n){let r=`minLevels must be an object with at most 100 level names.`;if(!t.n(n))throw new a(r);let i=Object.entries(n),o=i.every(([,n])=>typeof n==`string`&&t.t(e.At,n));if(i.length>100||!o)throw new a(r);return Object.fromEntries(i)}function u(n){if(!t.n(n))throw new a(`The rules must be an object.`);if(n.v!==1)throw new a(`The version must be 1.`);let{ttlMs:r,defaultRate:i,minLevel:s}=n;if(typeof r!=`number`||!(r>0&&r<=36e5))throw new a(`ttlMs must be a number more than 0 and at most ${String(e.fn)}.`);if(i!==void 0&&!o(i))throw new a(`defaultRate must be a number from 0 to 1.`);if(s!==void 0&&!(typeof s==`string`&&t.t(e.At,s)))throw new a(`minLevel must be a level name, for example DEBUG.`);let u={rates:c(n.rates)};if(i!==void 0&&(u.defaultRate=i),s!==void 0&&(u.minLevel=s),n.minLevels!==void 0&&(u.minLevels=l(n.minLevels)),n.capture!==void 0){let r=n.capture;if(!t.n(r))throw new a(`capture must be an object of capture switches.`);let i=Object.entries(r);if(!i.every(([t,n])=>e.un.some(e=>e===t)&&typeof n==`boolean`))throw new a(`capture must contain boolean capture switches without privacy controls.`);u.capture=Object.fromEntries(i)}return{rules:u,ttlMs:r}}function d(e,t){try{return u(typeof e==`string`?s(e):e)}catch(e){let n=e instanceof a?` ${e.message}`:``;return t.report(`config.invalid`,`The library ignores the sampling rules from the server.${n}`,void 0,e),null}}function f(e,t,n){n&&(e.sampling??=new i(t)),e.sampling?.apply(n),e.changed?.()}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return f}});
|
|
2
|
+
//# sourceMappingURL=remote-rules-D7L6D_D2.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-rules-_tY0zj5o.cjs","names":["levelFor","longestPrefix","LEVEL_ORDER","REMOTE_SAMPLING_MAX_CHARS","isObject","hasOwn","LEVEL_ORDER","REMOTE_SAMPLING_MAX_TTL_MS","REMOTE_CAPTURE_FLAGS","require_constants","require_guards","require_sampling","require_defineProperty","RemoteSampling","config","update","now","local","namespace","rules","remote","RuleError","isRate","value","parseText","text","readRates","rule","entries","rate","readMinLevels","valid","level","readRules","ttlMs","defaultRate","minLevel","capture","key","flag","name","parseRemoteRules","raw","error","reason","diagnostics","applyRemote","slot"],"sources":["../src/core/remote-sampling.ts","../src/core/remote-rules.ts"],"sourcesContent":["// src/core/remote-sampling.ts\n//\n// Holds the sampling rules from the ingest server for their TTL. The rules are an overlay\n// and are never written into the config, which keeps a later configure() and the TTL simple.\n// Only the lazy chunks import this class. The main bundle imports just the types.\n\nimport { LEVEL_ORDER, REMOTE_SAMPLING_VERSION } from \"../constants\";\nimport type { RemoteCaptureFlag, ResolvedConfig } from \"../models/config\";\nimport type { LogLevel } from \"../models/log-record\";\nimport { levelFor, longestPrefix } from \"./sampling\";\n\n/** Sampling rules from the ingest server, after validation. */\nexport interface RemoteRules {\n /** Rate used when no namespace rate matches. Without it, the config rate applies. */\n defaultRate?: number;\n /** Rate per namespace prefix. These apply on top of the config rates. */\n rates: Record<string, number>;\n /** Temporary capture switches. Every context applies its own allowlist. */\n capture?: Partial<Record<RemoteCaptureFlag, boolean>>;\n /** Lowest level the library sends. Can only lower `minLevel`. */\n minLevel?: LogLevel;\n /** Lowest level per namespace prefix. Can only lower the config's level. */\n minLevels?: Record<string, LogLevel>;\n}\n\n/** Rules and their TTL, after validation. */\nexport interface RemoteUpdate {\n /** Validated rules. */\n rules: RemoteRules;\n /** How long the rules stay in effect, in milliseconds. */\n ttlMs: number;\n}\n\n/** Rules in the header's shape. A context sends them to a forwarder over the bus. */\nexport interface RemoteWire extends RemoteRules {\n /** Rules version. */\n v: typeof REMOTE_SAMPLING_VERSION;\n /** How long the rules stay in effect, in milliseconds. */\n ttlMs: number;\n}\n\n/** The runtime's overlay slot. The sender or the bus fills it when the first rules arrive. */\nexport interface RemoteSlot {\n /** Overlay, or null before the first rules. */\n sampling: RemoteSampling | null;\n /** Refreshes captures after a trusted rule update. */\n changed?: () => void;\n}\n\n/** The remote sampling rules in effect for this context. */\nexport class RemoteSampling {\n /** Current rules, or null. */\n private rules: RemoteRules | null = null;\n\n /** When the rules arrived, in epoch milliseconds. */\n private receivedAt = 0;\n\n /** When the rules end, in epoch milliseconds. */\n private until = 0;\n\n /**\n * @param config Active configuration instance. A reconfigure changes it in place.\n */\n constructor(private readonly config: ResolvedConfig) {}\n\n /**\n * Puts new rules into effect, replacing the current ones.\n * @param update Validated rules and their TTL, or null when the upstream has no rules.\n */\n apply(update: RemoteUpdate | null): void {\n if (!update) {\n this.rules = null;\n return;\n }\n\n const now = Date.now();\n\n this.rules = update.rules;\n this.receivedAt = now;\n this.until = now + update.ttlMs;\n }\n\n /**\n * Returns the current rules.\n * @returns The rules, or null after the TTL or when `sampling.remote` is off.\n */\n current(): RemoteRules | null {\n if (!this.rules) {\n return null;\n }\n\n const now = Date.now();\n\n // Drop the rules when remote sampling is off, so turning it on again can't bring them back.\n // Also guard against a clock that moves back, which would keep the rules past their TTL.\n if (!this.config.sampling.remote || now < this.receivedAt || now >= this.until) {\n this.rules = null;\n return null;\n }\n\n return this.rules;\n }\n\n /**\n * Returns the lowest level the library sends for a namespace. A remote prefix level wins\n * over the remote `minLevel`, and a remote level applies only when it is lower than the\n * config level.\n * @param namespace Target application namespace.\n * @returns The lower of the remote level and the namespace's config level.\n */\n minLevelFor(namespace: string): LogLevel {\n const local = levelFor(namespace, this.config);\n const rules = this.current();\n const remote = longestPrefix(namespace, rules?.minLevels ?? {})?.value ?? rules?.minLevel;\n\n return remote !== undefined && LEVEL_ORDER[remote] < LEVEL_ORDER[local] ? remote : local;\n }\n\n /**\n * Returns the current rules in the header's shape, with the remaining TTL.\n * @returns The rules, or null if none are in effect.\n */\n wire(): RemoteWire | null {\n const rules = this.current();\n\n if (!rules) {\n return null;\n }\n\n return { ...rules, v: REMOTE_SAMPLING_VERSION, ttlMs: this.until - Date.now() };\n }\n}\n","// src/core/remote-rules.ts\n//\n// Validates the sampling rules from the ingest server and puts them into effect.\n// Imported by the sender and the bus. The main bundle doesn't include it.\n\nimport {\n LEVEL_ORDER,\n REMOTE_CAPTURE_FLAGS,\n REMOTE_SAMPLING_MAX_CHARS,\n REMOTE_SAMPLING_MAX_RATES,\n REMOTE_SAMPLING_MAX_TTL_MS,\n REMOTE_SAMPLING_VERSION,\n SAMPLING_RATE_MAX,\n SAMPLING_RATE_MIN,\n} from \"../constants\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { LogLevel } from \"../models/log-record\";\nimport { hasOwn, isObject } from \"../utils/guards\";\nimport type { Diagnostics } from \"./diagnostics\";\nimport {\n type RemoteRules,\n RemoteSampling,\n type RemoteSlot,\n type RemoteUpdate,\n} from \"./remote-sampling\";\n\n/** One validation step failed. The message states the rule. */\nclass RuleError extends Error {}\n\n/**\n * Checks whether a value is a rate.\n * @param value Value to check.\n * @returns True for a number from 0 to 1. NaN fails.\n */\nfunction isRate(value: unknown): value is number {\n return typeof value === \"number\" && value >= SAMPLING_RATE_MIN && value <= SAMPLING_RATE_MAX;\n}\n\n/**\n * Parses the header text as JSON.\n * @param text Header text.\n * @returns The parsed value.\n * @throws RuleError when the text is too long or isn't JSON.\n */\nfunction parseText(text: string): unknown {\n if (text.length > REMOTE_SAMPLING_MAX_CHARS) {\n throw new RuleError(\n `The header is longer than ${String(REMOTE_SAMPLING_MAX_CHARS)} characters.`,\n );\n }\n\n try {\n return JSON.parse(text);\n } catch {\n // The caller reports the RuleError.\n throw new RuleError(\"The header is not valid JSON.\");\n }\n}\n\n/**\n * Reads the namespace rates.\n * @param value Value of `rates`.\n * @returns The rates.\n * @throws RuleError when a rate is invalid.\n */\nfunction readRates(value: unknown): Record<string, number> {\n if (value === undefined) {\n return {};\n }\n\n const rule = `rates must be an object with at most ${String(REMOTE_SAMPLING_MAX_RATES)} rates from 0 to 1.`;\n\n if (!isObject(value)) {\n throw new RuleError(rule);\n }\n\n const entries = Object.entries(value);\n\n if (entries.length > REMOTE_SAMPLING_MAX_RATES || !entries.every(([, rate]) => isRate(rate))) {\n throw new RuleError(rule);\n }\n\n // fromEntries creates own properties, so a \"__proto__\" key can't change the prototype.\n return Object.fromEntries(entries) as Record<string, number>;\n}\n\n/**\n * Reads the level for every namespace prefix.\n * @param value Value of `minLevels`.\n * @returns The levels.\n * @throws RuleError when a level is invalid.\n */\nfunction readMinLevels(value: unknown): Record<string, LogLevel> {\n const rule = `minLevels must be an object with at most ${String(REMOTE_SAMPLING_MAX_RATES)} level names.`;\n\n if (!isObject(value)) {\n throw new RuleError(rule);\n }\n\n const entries = Object.entries(value);\n const valid = entries.every(\n ([, level]) => typeof level === \"string\" && hasOwn(LEVEL_ORDER, level),\n );\n\n if (entries.length > REMOTE_SAMPLING_MAX_RATES || !valid) {\n throw new RuleError(rule);\n }\n\n // fromEntries creates own properties, so a \"__proto__\" key can't change the prototype.\n return Object.fromEntries(entries) as Record<string, LogLevel>;\n}\n\n/**\n * Validates the rules. Sampling applies `remoteMaxRate` when it reads them.\n * @param value Parsed header value.\n * @returns The rules and their TTL.\n * @throws RuleError when a field is invalid.\n */\nfunction readRules(value: unknown): RemoteUpdate {\n if (!isObject(value)) {\n throw new RuleError(\"The rules must be an object.\");\n }\n\n if (value.v !== REMOTE_SAMPLING_VERSION) {\n throw new RuleError(`The version must be ${String(REMOTE_SAMPLING_VERSION)}.`);\n }\n\n const { ttlMs, defaultRate, minLevel } = value;\n\n if (typeof ttlMs !== \"number\" || !(ttlMs > 0 && ttlMs <= REMOTE_SAMPLING_MAX_TTL_MS)) {\n throw new RuleError(\n `ttlMs must be a number more than 0 and at most ${String(REMOTE_SAMPLING_MAX_TTL_MS)}.`,\n );\n }\n\n if (defaultRate !== undefined && !isRate(defaultRate)) {\n throw new RuleError(\"defaultRate must be a number from 0 to 1.\");\n }\n\n if (minLevel !== undefined && !(typeof minLevel === \"string\" && hasOwn(LEVEL_ORDER, minLevel))) {\n throw new RuleError(\"minLevel must be a level name, for example DEBUG.\");\n }\n\n const rules: RemoteRules = { rates: readRates(value.rates) };\n\n if (defaultRate !== undefined) {\n rules.defaultRate = defaultRate;\n }\n\n if (minLevel !== undefined) {\n rules.minLevel = minLevel as LogLevel;\n }\n\n if (value.minLevels !== undefined) {\n rules.minLevels = readMinLevels(value.minLevels);\n }\n\n if (value.capture !== undefined) {\n const capture = value.capture;\n if (!isObject(capture)) {\n throw new RuleError(\"capture must be an object of capture switches.\");\n }\n\n const entries = Object.entries(capture);\n if (\n !entries.every(\n ([key, flag]) =>\n REMOTE_CAPTURE_FLAGS.some((name) => name === key) && typeof flag === \"boolean\",\n )\n ) {\n throw new RuleError(\n \"capture must contain boolean capture switches without privacy controls.\",\n );\n }\n\n rules.capture = Object.fromEntries(entries);\n }\n\n return { rules, ttlMs };\n}\n\n/**\n * Validates sampling rules from the server. One invalid rule rejects all of them.\n * @param raw Header text, or a parsed object from a custom transport or the bus.\n * @param diagnostics Diagnostics reporter.\n * @returns The rules and their TTL, or null if they are invalid.\n */\nexport function parseRemoteRules(raw: unknown, diagnostics: Diagnostics): RemoteUpdate | null {\n try {\n return readRules(typeof raw === \"string\" ? parseText(raw) : raw);\n } catch (error) {\n const reason = error instanceof RuleError ? ` ${error.message}` : \"\";\n\n diagnostics.report(\n \"config.invalid\",\n `The library ignores the sampling rules from the server.${reason}`,\n undefined,\n error,\n );\n return null;\n }\n}\n\n/**\n * Puts rules into effect in the runtime's slot. Creates the overlay for the first rules.\n * @param slot The runtime's slot.\n * @param config Active configuration instance.\n * @param update Validated rules, or null when the upstream has no rules.\n */\nexport function applyRemote(\n slot: RemoteSlot,\n config: ResolvedConfig,\n update: RemoteUpdate | null,\n): void {\n if (update) {\n slot.sampling ??= new RemoteSampling(config);\n }\n\n slot.sampling?.apply(update);\n slot.changed?.();\n}\n"],"mappings":"A,+JAkDA,IAAaa,EAAb,KAA4B,CAa1B,YAAY,EAAyC,CAAxBD,EAAA,EAAA,KAAA,SAAA,IAAA,EAAA,EAX7BA,EAAA,EAAA,KAAA,QAAoC,IAAA,EAGpCA,EAAA,EAAA,KAAA,aAAqB,CAAA,EAGrBA,EAAA,EAAA,KAAA,QAAgB,CAAA,EAKa,KAAA,OAAAE,CAAyB,CAMtD,MAAM,EAAmC,CACvC,GAAI,CAACC,EAAQ,CACX,KAAK,MAAQ,KACb,MACF,CAEA,IAAMC,EAAM,KAAK,IAAI,EAErB,KAAK,MAAQD,EAAO,MACpB,KAAK,WAAaC,EAClB,KAAK,MAAQA,EAAMD,EAAO,KAC5B,CAMA,SAA8B,CAC5B,GAAI,CAAC,KAAK,MACR,OAAO,KAGT,IAAMC,EAAM,KAAK,IAAI,EASrB,MALI,CAAC,KAAK,OAAO,SAAS,QAAUA,EAAM,KAAK,YAAcA,GAAO,KAAK,OACvE,KAAK,MAAQ,KACN,MAGF,KAAK,KACd,CASA,YAAY,EAA6B,CACvC,IAAMC,EAAQjB,EAAAA,EAASkB,EA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,GAAK,OAAOC,GAAS,SACzE,EAEA,MAAM,IAAIlB,EACR,yEACF,EAGF,EAAM,QAAU,OAAO,YAAYO,CAAO,CAC5C,CAEA,MAAO,CAAE,QAAO,OAAM,CACxB,CAQA,SAAgBa,EAAiB,EAAc,EAA+C,CAC5F,GAAI,CACF,OAAOR,EAAU,OAAOS,GAAQ,SAAWlB,EAAUkB,CAAG,EAAIA,CAAG,CACjE,OAASC,EAAO,CACd,IAAMC,EAASD,aAAiBtB,EAAY,IAAIsB,EAAM,UAAY,GAQlE,OANAE,EAAY,OACV,iBACA,0DAA0DD,IAC1D,IAAA,GACAD,CACF,EACO,IACT,CACF,CAQA,SAAgBG,EACd,EACA,EACA,EACM,CACF/B,IACF,EAAK,WAAa,IAAIF,EAAeC,CAAM,GAG7CiC,EAAK,UAAU,MAAMhC,CAAM,EAC3BgC,EAAK,UAAU,CACjB,C"}
|
|
1
|
+
{"version":3,"file":"remote-rules-D7L6D_D2.cjs","names":["levelFor","longestPrefix","LEVEL_ORDER","REMOTE_SAMPLING_MAX_CHARS","isObject","hasOwn","LEVEL_ORDER","REMOTE_SAMPLING_MAX_TTL_MS","REMOTE_CAPTURE_FLAGS","require_constants","require_guards","require_sampling","require_defineProperty","RemoteSampling","config","update","now","local","namespace","rules","remote","RuleError","isRate","value","parseText","text","readRates","rule","entries","rate","readMinLevels","valid","level","readRules","ttlMs","defaultRate","minLevel","capture","key","flag","name","parseRemoteRules","raw","error","reason","diagnostics","applyRemote","slot"],"sources":["../src/core/remote-sampling.ts","../src/core/remote-rules.ts"],"sourcesContent":["// src/core/remote-sampling.ts\n//\n// Holds the sampling rules from the ingest server for their TTL. The rules are an overlay\n// and are never written into the config, which keeps a later configure() and the TTL simple.\n// Only the lazy chunks import this class. The main bundle imports just the types.\n\nimport { LEVEL_ORDER, REMOTE_SAMPLING_VERSION } from \"../constants\";\nimport type { RemoteCaptureFlag, ResolvedConfig } from \"../models/config\";\nimport type { LogLevel } from \"../models/log-record\";\nimport { levelFor, longestPrefix } from \"./sampling\";\n\n/** Sampling rules from the ingest server, after validation. */\nexport interface RemoteRules {\n /** Rate used when no namespace rate matches. Without it, the config rate applies. */\n defaultRate?: number;\n /** Rate per namespace prefix. These apply on top of the config rates. */\n rates: Record<string, number>;\n /** Temporary capture switches. Every context applies its own allowlist. */\n capture?: Partial<Record<RemoteCaptureFlag, boolean>>;\n /** Lowest level the library sends. Can only lower `minLevel`. */\n minLevel?: LogLevel;\n /** Lowest level per namespace prefix. Can only lower the config's level. */\n minLevels?: Record<string, LogLevel>;\n}\n\n/** Rules and their TTL, after validation. */\nexport interface RemoteUpdate {\n /** Validated rules. */\n rules: RemoteRules;\n /** How long the rules stay in effect, in milliseconds. */\n ttlMs: number;\n}\n\n/** Rules in the header's shape. A context sends them to a forwarder over the bus. */\nexport interface RemoteWire extends RemoteRules {\n /** Rules version. */\n v: typeof REMOTE_SAMPLING_VERSION;\n /** How long the rules stay in effect, in milliseconds. */\n ttlMs: number;\n}\n\n/** The runtime's overlay slot. The sender or the bus fills it when the first rules arrive. */\nexport interface RemoteSlot {\n /** Overlay, or null before the first rules. */\n sampling: RemoteSampling | null;\n /** Refreshes captures after a trusted rule update. */\n changed?: () => void;\n}\n\n/** The remote sampling rules in effect for this context. */\nexport class RemoteSampling {\n /** Current rules, or null. */\n private rules: RemoteRules | null = null;\n\n /** When the rules arrived, in epoch milliseconds. */\n private receivedAt = 0;\n\n /** When the rules end, in epoch milliseconds. */\n private until = 0;\n\n /**\n * @param config Active configuration instance. A reconfigure changes it in place.\n */\n constructor(private readonly config: ResolvedConfig) {}\n\n /**\n * Puts new rules into effect, replacing the current ones.\n * @param update Validated rules and their TTL, or null when the upstream has no rules.\n */\n apply(update: RemoteUpdate | null): void {\n if (!update) {\n this.rules = null;\n return;\n }\n\n const now = Date.now();\n\n this.rules = update.rules;\n this.receivedAt = now;\n this.until = now + update.ttlMs;\n }\n\n /**\n * Returns the current rules.\n * @returns The rules, or null after the TTL or when `sampling.remote` is off.\n */\n current(): RemoteRules | null {\n if (!this.rules) {\n return null;\n }\n\n const now = Date.now();\n\n // Drop the rules when remote sampling is off, so turning it on again can't bring them back.\n // Also guard against a clock that moves back, which would keep the rules past their TTL.\n if (!this.config.sampling.remote || now < this.receivedAt || now >= this.until) {\n this.rules = null;\n return null;\n }\n\n return this.rules;\n }\n\n /**\n * Returns the lowest level the library sends for a namespace. A remote prefix level wins\n * over the remote `minLevel`, and a remote level applies only when it is lower than the\n * config level.\n * @param namespace Target application namespace.\n * @returns The lower of the remote level and the namespace's config level.\n */\n minLevelFor(namespace: string): LogLevel {\n const local = levelFor(namespace, this.config);\n const rules = this.current();\n const remote = longestPrefix(namespace, rules?.minLevels ?? {})?.value ?? rules?.minLevel;\n\n return remote !== undefined && LEVEL_ORDER[remote] < LEVEL_ORDER[local] ? remote : local;\n }\n\n /**\n * Returns the current rules in the header's shape, with the remaining TTL.\n * @returns The rules, or null if none are in effect.\n */\n wire(): RemoteWire | null {\n const rules = this.current();\n\n if (!rules) {\n return null;\n }\n\n return { ...rules, v: REMOTE_SAMPLING_VERSION, ttlMs: this.until - Date.now() };\n }\n}\n","// src/core/remote-rules.ts\n//\n// Validates the sampling rules from the ingest server and puts them into effect.\n// Imported by the sender and the bus. The main bundle doesn't include it.\n\nimport {\n LEVEL_ORDER,\n REMOTE_CAPTURE_FLAGS,\n REMOTE_SAMPLING_MAX_CHARS,\n REMOTE_SAMPLING_MAX_RATES,\n REMOTE_SAMPLING_MAX_TTL_MS,\n REMOTE_SAMPLING_VERSION,\n SAMPLING_RATE_MAX,\n SAMPLING_RATE_MIN,\n} from \"../constants\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { LogLevel } from \"../models/log-record\";\nimport { hasOwn, isObject } from \"../utils/guards\";\nimport type { Diagnostics } from \"./diagnostics\";\nimport {\n type RemoteRules,\n RemoteSampling,\n type RemoteSlot,\n type RemoteUpdate,\n} from \"./remote-sampling\";\n\n/** One validation step failed. The message states the rule. */\nclass RuleError extends Error {}\n\n/**\n * Checks whether a value is a rate.\n * @param value Value to check.\n * @returns True for a number from 0 to 1. NaN fails.\n */\nfunction isRate(value: unknown): value is number {\n return typeof value === \"number\" && value >= SAMPLING_RATE_MIN && value <= SAMPLING_RATE_MAX;\n}\n\n/**\n * Parses the header text as JSON.\n * @param text Header text.\n * @returns The parsed value.\n * @throws RuleError when the text is too long or isn't JSON.\n */\nfunction parseText(text: string): unknown {\n if (text.length > REMOTE_SAMPLING_MAX_CHARS) {\n throw new RuleError(\n `The header is longer than ${String(REMOTE_SAMPLING_MAX_CHARS)} characters.`,\n );\n }\n\n try {\n return JSON.parse(text);\n } catch {\n // The caller reports the RuleError.\n throw new RuleError(\"The header is not valid JSON.\");\n }\n}\n\n/**\n * Reads the namespace rates.\n * @param value Value of `rates`.\n * @returns The rates.\n * @throws RuleError when a rate is invalid.\n */\nfunction readRates(value: unknown): Record<string, number> {\n if (value === undefined) {\n return {};\n }\n\n const rule = `rates must be an object with at most ${String(REMOTE_SAMPLING_MAX_RATES)} rates from 0 to 1.`;\n\n if (!isObject(value)) {\n throw new RuleError(rule);\n }\n\n const entries = Object.entries(value);\n\n if (entries.length > REMOTE_SAMPLING_MAX_RATES || !entries.every(([, rate]) => isRate(rate))) {\n throw new RuleError(rule);\n }\n\n // fromEntries creates own properties, so a \"__proto__\" key can't change the prototype.\n return Object.fromEntries(entries) as Record<string, number>;\n}\n\n/**\n * Reads the level for every namespace prefix.\n * @param value Value of `minLevels`.\n * @returns The levels.\n * @throws RuleError when a level is invalid.\n */\nfunction readMinLevels(value: unknown): Record<string, LogLevel> {\n const rule = `minLevels must be an object with at most ${String(REMOTE_SAMPLING_MAX_RATES)} level names.`;\n\n if (!isObject(value)) {\n throw new RuleError(rule);\n }\n\n const entries = Object.entries(value);\n const valid = entries.every(\n ([, level]) => typeof level === \"string\" && hasOwn(LEVEL_ORDER, level),\n );\n\n if (entries.length > REMOTE_SAMPLING_MAX_RATES || !valid) {\n throw new RuleError(rule);\n }\n\n // fromEntries creates own properties, so a \"__proto__\" key can't change the prototype.\n return Object.fromEntries(entries) as Record<string, LogLevel>;\n}\n\n/**\n * Validates the rules. Sampling applies `remoteMaxRate` when it reads them.\n * @param value Parsed header value.\n * @returns The rules and their TTL.\n * @throws RuleError when a field is invalid.\n */\nfunction readRules(value: unknown): RemoteUpdate {\n if (!isObject(value)) {\n throw new RuleError(\"The rules must be an object.\");\n }\n\n if (value.v !== REMOTE_SAMPLING_VERSION) {\n throw new RuleError(`The version must be ${String(REMOTE_SAMPLING_VERSION)}.`);\n }\n\n const { ttlMs, defaultRate, minLevel } = value;\n\n if (typeof ttlMs !== \"number\" || !(ttlMs > 0 && ttlMs <= REMOTE_SAMPLING_MAX_TTL_MS)) {\n throw new RuleError(\n `ttlMs must be a number more than 0 and at most ${String(REMOTE_SAMPLING_MAX_TTL_MS)}.`,\n );\n }\n\n if (defaultRate !== undefined && !isRate(defaultRate)) {\n throw new RuleError(\"defaultRate must be a number from 0 to 1.\");\n }\n\n if (minLevel !== undefined && !(typeof minLevel === \"string\" && hasOwn(LEVEL_ORDER, minLevel))) {\n throw new RuleError(\"minLevel must be a level name, for example DEBUG.\");\n }\n\n const rules: RemoteRules = { rates: readRates(value.rates) };\n\n if (defaultRate !== undefined) {\n rules.defaultRate = defaultRate;\n }\n\n if (minLevel !== undefined) {\n rules.minLevel = minLevel as LogLevel;\n }\n\n if (value.minLevels !== undefined) {\n rules.minLevels = readMinLevels(value.minLevels);\n }\n\n if (value.capture !== undefined) {\n const capture = value.capture;\n if (!isObject(capture)) {\n throw new RuleError(\"capture must be an object of capture switches.\");\n }\n\n const entries = Object.entries(capture);\n if (\n !entries.every(\n ([key, flag]) =>\n REMOTE_CAPTURE_FLAGS.some((name) => name === key) && typeof flag === \"boolean\",\n )\n ) {\n throw new RuleError(\n \"capture must contain boolean capture switches without privacy controls.\",\n );\n }\n\n rules.capture = Object.fromEntries(entries);\n }\n\n return { rules, ttlMs };\n}\n\n/**\n * Validates sampling rules from the server. One invalid rule rejects all of them.\n * @param raw Header text, or a parsed object from a custom transport or the bus.\n * @param diagnostics Diagnostics reporter.\n * @returns The rules and their TTL, or null if they are invalid.\n */\nexport function parseRemoteRules(raw: unknown, diagnostics: Diagnostics): RemoteUpdate | null {\n try {\n return readRules(typeof raw === \"string\" ? parseText(raw) : raw);\n } catch (error) {\n const reason = error instanceof RuleError ? ` ${error.message}` : \"\";\n\n diagnostics.report(\n \"config.invalid\",\n `The library ignores the sampling rules from the server.${reason}`,\n undefined,\n error,\n );\n return null;\n }\n}\n\n/**\n * Puts rules into effect in the runtime's slot. Creates the overlay for the first rules.\n * @param slot The runtime's slot.\n * @param config Active configuration instance.\n * @param update Validated rules, or null when the upstream has no rules.\n */\nexport function applyRemote(\n slot: RemoteSlot,\n config: ResolvedConfig,\n update: RemoteUpdate | null,\n): void {\n if (update) {\n slot.sampling ??= new RemoteSampling(config);\n }\n\n slot.sampling?.apply(update);\n slot.changed?.();\n}\n"],"mappings":"A,+JAkDA,IAAaa,EAAb,KAA4B,CAa1B,YAAY,EAAyC,CAAxBD,EAAA,EAAA,KAAA,SAAA,IAAA,EAAA,EAX7BA,EAAA,EAAA,KAAA,QAAoC,IAAA,EAGpCA,EAAA,EAAA,KAAA,aAAqB,CAAA,EAGrBA,EAAA,EAAA,KAAA,QAAgB,CAAA,EAKa,KAAA,OAAAE,CAAyB,CAMtD,MAAM,EAAmC,CACvC,GAAI,CAACC,EAAQ,CACX,KAAK,MAAQ,KACb,MACF,CAEA,IAAMC,EAAM,KAAK,IAAI,EAErB,KAAK,MAAQD,EAAO,MACpB,KAAK,WAAaC,EAClB,KAAK,MAAQA,EAAMD,EAAO,KAC5B,CAMA,SAA8B,CAC5B,GAAI,CAAC,KAAK,MACR,OAAO,KAGT,IAAMC,EAAM,KAAK,IAAI,EASrB,MALI,CAAC,KAAK,OAAO,SAAS,QAAUA,EAAM,KAAK,YAAcA,GAAO,KAAK,OACvE,KAAK,MAAQ,KACN,MAGF,KAAK,KACd,CAS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,EAAKC,KACL/B,EAAAA,GAAqB,KAAM,GAASgC,IAASF,CAAG,GAAK,OAAOC,GAAS,SACzE,EAEA,MAAM,IAAIlB,EACR,yEACF,EAGF,EAAM,QAAU,OAAO,YAAYO,CAAO,CAC5C,CAEA,MAAO,CAAE,QAAO,OAAM,CACxB,CAQA,SAAgBa,EAAiB,EAAc,EAA+C,CAC5F,GAAI,CACF,OAAOR,EAAU,OAAOS,GAAQ,SAAWlB,EAAUkB,CAAG,EAAIA,CAAG,CACjE,OAASC,EAAO,CACd,IAAMC,EAASD,aAAiBtB,EAAY,IAAIsB,EAAM,UAAY,GAQlE,OANAE,EAAY,OACV,iBACA,0DAA0DD,IAC1D,IAAA,GACAD,CACF,EACO,IACT,CACF,CAQA,SAAgBG,EACd,EACA,EACA,EACM,CACF/B,IACF,EAAK,WAAa,IAAIF,EAAeC,CAAM,GAG7CiC,EAAK,UAAU,MAAMhC,CAAM,EAC3BgC,EAAK,UAAU,CACjB,C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { At as e, dn as t, fn as n, un as r } from "./constants-BwJDXzj6.js";
|
|
2
2
|
import { n as i, t as a } from "./guards-BlYGRK4l.js";
|
|
3
|
-
import { n as o, r as s } from "./sampling-
|
|
3
|
+
import { n as o, r as s } from "./sampling-zXA6r-Nw.js";
|
|
4
4
|
import { t as c } from "./defineProperty-s2S8BXUc.js";
|
|
5
5
|
// src/core/remote-sampling.ts
|
|
6
6
|
var l = class {
|
|
@@ -20,9 +20,9 @@ var l = class {
|
|
|
20
20
|
let e = Date.now();
|
|
21
21
|
return !this.config.sampling.remote || e < this.receivedAt || e >= this.until ? (this.rules = null, null) : this.rules;
|
|
22
22
|
}
|
|
23
|
-
minLevelFor(
|
|
24
|
-
let n = o(
|
|
25
|
-
return i !== void 0 &&
|
|
23
|
+
minLevelFor(t) {
|
|
24
|
+
let n = o(t, this.config), r = this.current(), i = s(t, r?.minLevels ?? {})?.value ?? r?.minLevel;
|
|
25
|
+
return i !== void 0 && e[i] < e[n] ? i : n;
|
|
26
26
|
}
|
|
27
27
|
wire() {
|
|
28
28
|
let e = this.current();
|
|
@@ -36,10 +36,10 @@ var l = class {
|
|
|
36
36
|
function d(e) {
|
|
37
37
|
return typeof e == "number" && e >= 0 && e <= 1;
|
|
38
38
|
}
|
|
39
|
-
function f(
|
|
40
|
-
if (
|
|
39
|
+
function f(e) {
|
|
40
|
+
if (e.length > 4096) throw new u(`The header is longer than ${String(t)} characters.`);
|
|
41
41
|
try {
|
|
42
|
-
return JSON.parse(
|
|
42
|
+
return JSON.parse(e);
|
|
43
43
|
} catch {
|
|
44
44
|
throw new u("The header is not valid JSON.");
|
|
45
45
|
}
|
|
@@ -52,25 +52,25 @@ function p(e) {
|
|
|
52
52
|
if (n.length > 100 || !n.every(([, e]) => d(e))) throw new u(t);
|
|
53
53
|
return Object.fromEntries(n);
|
|
54
54
|
}
|
|
55
|
-
function m(
|
|
55
|
+
function m(t) {
|
|
56
56
|
let n = "minLevels must be an object with at most 100 level names.";
|
|
57
|
-
if (!i(
|
|
58
|
-
let r = Object.entries(
|
|
57
|
+
if (!i(t)) throw new u(n);
|
|
58
|
+
let r = Object.entries(t), o = r.every(([, t]) => typeof t == "string" && a(e, t));
|
|
59
59
|
if (r.length > 100 || !o) throw new u(n);
|
|
60
60
|
return Object.fromEntries(r);
|
|
61
61
|
}
|
|
62
|
-
function h(
|
|
63
|
-
if (!i(
|
|
64
|
-
if (
|
|
65
|
-
let { ttlMs: o, defaultRate: s, minLevel: c } =
|
|
62
|
+
function h(t) {
|
|
63
|
+
if (!i(t)) throw new u("The rules must be an object.");
|
|
64
|
+
if (t.v !== 1) throw new u("The version must be 1.");
|
|
65
|
+
let { ttlMs: o, defaultRate: s, minLevel: c } = t;
|
|
66
66
|
if (typeof o != "number" || !(o > 0 && o <= 36e5)) throw new u(`ttlMs must be a number more than 0 and at most ${String(n)}.`);
|
|
67
67
|
if (s !== void 0 && !d(s)) throw new u("defaultRate must be a number from 0 to 1.");
|
|
68
|
-
if (c !== void 0 && !(typeof c == "string" && a(
|
|
69
|
-
let l = { rates: p(
|
|
70
|
-
if (s !== void 0 && (l.defaultRate = s), c !== void 0 && (l.minLevel = c),
|
|
71
|
-
let
|
|
72
|
-
if (!i(
|
|
73
|
-
let n = Object.entries(
|
|
68
|
+
if (c !== void 0 && !(typeof c == "string" && a(e, c))) throw new u("minLevel must be a level name, for example DEBUG.");
|
|
69
|
+
let l = { rates: p(t.rates) };
|
|
70
|
+
if (s !== void 0 && (l.defaultRate = s), c !== void 0 && (l.minLevel = c), t.minLevels !== void 0 && (l.minLevels = m(t.minLevels)), t.capture !== void 0) {
|
|
71
|
+
let e = t.capture;
|
|
72
|
+
if (!i(e)) throw new u("capture must be an object of capture switches.");
|
|
73
|
+
let n = Object.entries(e);
|
|
74
74
|
if (!n.every(([e, t]) => r.some((t) => t === e) && typeof t == "boolean")) throw new u("capture must contain boolean capture switches without privacy controls.");
|
|
75
75
|
l.capture = Object.fromEntries(n);
|
|
76
76
|
}
|
|
@@ -92,4 +92,4 @@ function _(e, t, n) {
|
|
|
92
92
|
}
|
|
93
93
|
export { g as n, _ as t };
|
|
94
94
|
|
|
95
|
-
//# sourceMappingURL=remote-rules-
|
|
95
|
+
//# sourceMappingURL=remote-rules-Dq9xe7Qn.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-rules-Dz9MRAsB.js","names":["REMOTE_SAMPLING_MAX_CHARS","LEVEL_ORDER","REMOTE_SAMPLING_MAX_TTL_MS","REMOTE_CAPTURE_FLAGS","isObject","hasOwn","levelFor","longestPrefix","_defineProperty","RemoteSampling","config","update","now","local","namespace","rules","remote","RuleError","isRate","value","parseText","text","readRates","rule","entries","rate","readMinLevels","valid","level","readRules","ttlMs","defaultRate","minLevel","capture","key","flag","name","parseRemoteRules","raw","error","reason","diagnostics","applyRemote","slot"],"sources":["../src/core/remote-sampling.ts","../src/core/remote-rules.ts"],"sourcesContent":["// src/core/remote-sampling.ts\n//\n// Holds the sampling rules from the ingest server for their TTL. The rules are an overlay\n// and are never written into the config, which keeps a later configure() and the TTL simple.\n// Only the lazy chunks import this class. The main bundle imports just the types.\n\nimport { LEVEL_ORDER, REMOTE_SAMPLING_VERSION } from \"../constants\";\nimport type { RemoteCaptureFlag, ResolvedConfig } from \"../models/config\";\nimport type { LogLevel } from \"../models/log-record\";\nimport { levelFor, longestPrefix } from \"./sampling\";\n\n/** Sampling rules from the ingest server, after validation. */\nexport interface RemoteRules {\n /** Rate used when no namespace rate matches. Without it, the config rate applies. */\n defaultRate?: number;\n /** Rate per namespace prefix. These apply on top of the config rates. */\n rates: Record<string, number>;\n /** Temporary capture switches. Every context applies its own allowlist. */\n capture?: Partial<Record<RemoteCaptureFlag, boolean>>;\n /** Lowest level the library sends. Can only lower `minLevel`. */\n minLevel?: LogLevel;\n /** Lowest level per namespace prefix. Can only lower the config's level. */\n minLevels?: Record<string, LogLevel>;\n}\n\n/** Rules and their TTL, after validation. */\nexport interface RemoteUpdate {\n /** Validated rules. */\n rules: RemoteRules;\n /** How long the rules stay in effect, in milliseconds. */\n ttlMs: number;\n}\n\n/** Rules in the header's shape. A context sends them to a forwarder over the bus. */\nexport interface RemoteWire extends RemoteRules {\n /** Rules version. */\n v: typeof REMOTE_SAMPLING_VERSION;\n /** How long the rules stay in effect, in milliseconds. */\n ttlMs: number;\n}\n\n/** The runtime's overlay slot. The sender or the bus fills it when the first rules arrive. */\nexport interface RemoteSlot {\n /** Overlay, or null before the first rules. */\n sampling: RemoteSampling | null;\n /** Refreshes captures after a trusted rule update. */\n changed?: () => void;\n}\n\n/** The remote sampling rules in effect for this context. */\nexport class RemoteSampling {\n /** Current rules, or null. */\n private rules: RemoteRules | null = null;\n\n /** When the rules arrived, in epoch milliseconds. */\n private receivedAt = 0;\n\n /** When the rules end, in epoch milliseconds. */\n private until = 0;\n\n /**\n * @param config Active configuration instance. A reconfigure changes it in place.\n */\n constructor(private readonly config: ResolvedConfig) {}\n\n /**\n * Puts new rules into effect, replacing the current ones.\n * @param update Validated rules and their TTL, or null when the upstream has no rules.\n */\n apply(update: RemoteUpdate | null): void {\n if (!update) {\n this.rules = null;\n return;\n }\n\n const now = Date.now();\n\n this.rules = update.rules;\n this.receivedAt = now;\n this.until = now + update.ttlMs;\n }\n\n /**\n * Returns the current rules.\n * @returns The rules, or null after the TTL or when `sampling.remote` is off.\n */\n current(): RemoteRules | null {\n if (!this.rules) {\n return null;\n }\n\n const now = Date.now();\n\n // Drop the rules when remote sampling is off, so turning it on again can't bring them back.\n // Also guard against a clock that moves back, which would keep the rules past their TTL.\n if (!this.config.sampling.remote || now < this.receivedAt || now >= this.until) {\n this.rules = null;\n return null;\n }\n\n return this.rules;\n }\n\n /**\n * Returns the lowest level the library sends for a namespace. A remote prefix level wins\n * over the remote `minLevel`, and a remote level applies only when it is lower than the\n * config level.\n * @param namespace Target application namespace.\n * @returns The lower of the remote level and the namespace's config level.\n */\n minLevelFor(namespace: string): LogLevel {\n const local = levelFor(namespace, this.config);\n const rules = this.current();\n const remote = longestPrefix(namespace, rules?.minLevels ?? {})?.value ?? rules?.minLevel;\n\n return remote !== undefined && LEVEL_ORDER[remote] < LEVEL_ORDER[local] ? remote : local;\n }\n\n /**\n * Returns the current rules in the header's shape, with the remaining TTL.\n * @returns The rules, or null if none are in effect.\n */\n wire(): RemoteWire | null {\n const rules = this.current();\n\n if (!rules) {\n return null;\n }\n\n return { ...rules, v: REMOTE_SAMPLING_VERSION, ttlMs: this.until - Date.now() };\n }\n}\n","// src/core/remote-rules.ts\n//\n// Validates the sampling rules from the ingest server and puts them into effect.\n// Imported by the sender and the bus. The main bundle doesn't include it.\n\nimport {\n LEVEL_ORDER,\n REMOTE_CAPTURE_FLAGS,\n REMOTE_SAMPLING_MAX_CHARS,\n REMOTE_SAMPLING_MAX_RATES,\n REMOTE_SAMPLING_MAX_TTL_MS,\n REMOTE_SAMPLING_VERSION,\n SAMPLING_RATE_MAX,\n SAMPLING_RATE_MIN,\n} from \"../constants\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { LogLevel } from \"../models/log-record\";\nimport { hasOwn, isObject } from \"../utils/guards\";\nimport type { Diagnostics } from \"./diagnostics\";\nimport {\n type RemoteRules,\n RemoteSampling,\n type RemoteSlot,\n type RemoteUpdate,\n} from \"./remote-sampling\";\n\n/** One validation step failed. The message states the rule. */\nclass RuleError extends Error {}\n\n/**\n * Checks whether a value is a rate.\n * @param value Value to check.\n * @returns True for a number from 0 to 1. NaN fails.\n */\nfunction isRate(value: unknown): value is number {\n return typeof value === \"number\" && value >= SAMPLING_RATE_MIN && value <= SAMPLING_RATE_MAX;\n}\n\n/**\n * Parses the header text as JSON.\n * @param text Header text.\n * @returns The parsed value.\n * @throws RuleError when the text is too long or isn't JSON.\n */\nfunction parseText(text: string): unknown {\n if (text.length > REMOTE_SAMPLING_MAX_CHARS) {\n throw new RuleError(\n `The header is longer than ${String(REMOTE_SAMPLING_MAX_CHARS)} characters.`,\n );\n }\n\n try {\n return JSON.parse(text);\n } catch {\n // The caller reports the RuleError.\n throw new RuleError(\"The header is not valid JSON.\");\n }\n}\n\n/**\n * Reads the namespace rates.\n * @param value Value of `rates`.\n * @returns The rates.\n * @throws RuleError when a rate is invalid.\n */\nfunction readRates(value: unknown): Record<string, number> {\n if (value === undefined) {\n return {};\n }\n\n const rule = `rates must be an object with at most ${String(REMOTE_SAMPLING_MAX_RATES)} rates from 0 to 1.`;\n\n if (!isObject(value)) {\n throw new RuleError(rule);\n }\n\n const entries = Object.entries(value);\n\n if (entries.length > REMOTE_SAMPLING_MAX_RATES || !entries.every(([, rate]) => isRate(rate))) {\n throw new RuleError(rule);\n }\n\n // fromEntries creates own properties, so a \"__proto__\" key can't change the prototype.\n return Object.fromEntries(entries) as Record<string, number>;\n}\n\n/**\n * Reads the level for every namespace prefix.\n * @param value Value of `minLevels`.\n * @returns The levels.\n * @throws RuleError when a level is invalid.\n */\nfunction readMinLevels(value: unknown): Record<string, LogLevel> {\n const rule = `minLevels must be an object with at most ${String(REMOTE_SAMPLING_MAX_RATES)} level names.`;\n\n if (!isObject(value)) {\n throw new RuleError(rule);\n }\n\n const entries = Object.entries(value);\n const valid = entries.every(\n ([, level]) => typeof level === \"string\" && hasOwn(LEVEL_ORDER, level),\n );\n\n if (entries.length > REMOTE_SAMPLING_MAX_RATES || !valid) {\n throw new RuleError(rule);\n }\n\n // fromEntries creates own properties, so a \"__proto__\" key can't change the prototype.\n return Object.fromEntries(entries) as Record<string, LogLevel>;\n}\n\n/**\n * Validates the rules. Sampling applies `remoteMaxRate` when it reads them.\n * @param value Parsed header value.\n * @returns The rules and their TTL.\n * @throws RuleError when a field is invalid.\n */\nfunction readRules(value: unknown): RemoteUpdate {\n if (!isObject(value)) {\n throw new RuleError(\"The rules must be an object.\");\n }\n\n if (value.v !== REMOTE_SAMPLING_VERSION) {\n throw new RuleError(`The version must be ${String(REMOTE_SAMPLING_VERSION)}.`);\n }\n\n const { ttlMs, defaultRate, minLevel } = value;\n\n if (typeof ttlMs !== \"number\" || !(ttlMs > 0 && ttlMs <= REMOTE_SAMPLING_MAX_TTL_MS)) {\n throw new RuleError(\n `ttlMs must be a number more than 0 and at most ${String(REMOTE_SAMPLING_MAX_TTL_MS)}.`,\n );\n }\n\n if (defaultRate !== undefined && !isRate(defaultRate)) {\n throw new RuleError(\"defaultRate must be a number from 0 to 1.\");\n }\n\n if (minLevel !== undefined && !(typeof minLevel === \"string\" && hasOwn(LEVEL_ORDER, minLevel))) {\n throw new RuleError(\"minLevel must be a level name, for example DEBUG.\");\n }\n\n const rules: RemoteRules = { rates: readRates(value.rates) };\n\n if (defaultRate !== undefined) {\n rules.defaultRate = defaultRate;\n }\n\n if (minLevel !== undefined) {\n rules.minLevel = minLevel as LogLevel;\n }\n\n if (value.minLevels !== undefined) {\n rules.minLevels = readMinLevels(value.minLevels);\n }\n\n if (value.capture !== undefined) {\n const capture = value.capture;\n if (!isObject(capture)) {\n throw new RuleError(\"capture must be an object of capture switches.\");\n }\n\n const entries = Object.entries(capture);\n if (\n !entries.every(\n ([key, flag]) =>\n REMOTE_CAPTURE_FLAGS.some((name) => name === key) && typeof flag === \"boolean\",\n )\n ) {\n throw new RuleError(\n \"capture must contain boolean capture switches without privacy controls.\",\n );\n }\n\n rules.capture = Object.fromEntries(entries);\n }\n\n return { rules, ttlMs };\n}\n\n/**\n * Validates sampling rules from the server. One invalid rule rejects all of them.\n * @param raw Header text, or a parsed object from a custom transport or the bus.\n * @param diagnostics Diagnostics reporter.\n * @returns The rules and their TTL, or null if they are invalid.\n */\nexport function parseRemoteRules(raw: unknown, diagnostics: Diagnostics): RemoteUpdate | null {\n try {\n return readRules(typeof raw === \"string\" ? parseText(raw) : raw);\n } catch (error) {\n const reason = error instanceof RuleError ? ` ${error.message}` : \"\";\n\n diagnostics.report(\n \"config.invalid\",\n `The library ignores the sampling rules from the server.${reason}`,\n undefined,\n error,\n );\n return null;\n }\n}\n\n/**\n * Puts rules into effect in the runtime's slot. Creates the overlay for the first rules.\n * @param slot The runtime's slot.\n * @param config Active configuration instance.\n * @param update Validated rules, or null when the upstream has no rules.\n */\nexport function applyRemote(\n slot: RemoteSlot,\n config: ResolvedConfig,\n update: RemoteUpdate | null,\n): void {\n if (update) {\n slot.sampling ??= new RemoteSampling(config);\n }\n\n slot.sampling?.apply(update);\n slot.changed?.();\n}\n"],"mappings":";;;;;AAkDA,IAAaS,IAAb,MAA4B;CAa1B,YAAY,GAAyC;EAAxB,AAAAD,EAAA,MAAA,UAAA,KAAA,CAAA,GAX7BA,EAAA,MAAA,SAAoC,IAAA,GAGpCA,EAAA,MAAA,cAAqB,CAAA,GAGrBA,EAAA,MAAA,SAAgB,CAAA,GAKa,KAAA,SAAAE;CAAyB;CAMtD,MAAM,GAAmC;EACvC,IAAI,CAACC,GAAQ;GACX,KAAK,QAAQ;GACb;EACF;EAEA,IAAMC,IAAM,KAAK,IAAI;EAIrB,AAFA,KAAK,QAAQD,EAAO,OACp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AM;EACtB,IAAI,CAACf,EAAS6B,CAAO,GACnB,MAAM,IAAIhB,EAAU,gDAAgD;EAGtE,IAAMO,IAAU,OAAO,QAAQS,CAAO;EACtC,IACE,CAACT,EAAQ,OACN,CAACU,GAAKC,OACLhC,EAAqB,MAAM,MAASiC,MAASF,CAAG,KAAK,OAAOC,KAAS,SACzE,GAEA,MAAM,IAAIlB,EACR,yEACF;EAGF,EAAM,UAAU,OAAO,YAAYO,CAAO;CAC5C;CAEA,OAAO;EAAE;EAAO;CAAM;AACxB;AAQA,SAAgBa,EAAiB,GAAc,GAA+C;CAC5F,IAAI;EACF,OAAOR,EAAU,OAAOS,KAAQ,WAAWlB,EAAUkB,CAAG,IAAIA,CAAG;CACjE,SAASC,GAAO;EACd,IAAMC,IAASD,aAAiBtB,IAAY,IAAIsB,EAAM,YAAY;EAQlE,OANAE,EAAY,OACV,kBACA,0DAA0DD,KAC1D,KAAA,GACAD,CACF,GACO;CACT;AACF;AAQA,SAAgBG,EACd,GACA,GACA,GACM;CAMN,AALI/B,MACF,EAAK,aAAa,IAAIF,EAAeC,CAAM,IAG7CiC,EAAK,UAAU,MAAMhC,CAAM,GAC3BgC,EAAK,UAAU;AACjB"}
|
|
1
|
+
{"version":3,"file":"remote-rules-Dq9xe7Qn.js","names":["LEVEL_ORDER","REMOTE_SAMPLING_MAX_CHARS","REMOTE_SAMPLING_MAX_TTL_MS","REMOTE_CAPTURE_FLAGS","isObject","hasOwn","levelFor","longestPrefix","_defineProperty","RemoteSampling","config","update","now","local","namespace","rules","remote","RuleError","isRate","value","parseText","text","readRates","rule","entries","rate","readMinLevels","valid","level","readRules","ttlMs","defaultRate","minLevel","capture","key","flag","name","parseRemoteRules","raw","error","reason","diagnostics","applyRemote","slot"],"sources":["../src/core/remote-sampling.ts","../src/core/remote-rules.ts"],"sourcesContent":["// src/core/remote-sampling.ts\n//\n// Holds the sampling rules from the ingest server for their TTL. The rules are an overlay\n// and are never written into the config, which keeps a later configure() and the TTL simple.\n// Only the lazy chunks import this class. The main bundle imports just the types.\n\nimport { LEVEL_ORDER, REMOTE_SAMPLING_VERSION } from \"../constants\";\nimport type { RemoteCaptureFlag, ResolvedConfig } from \"../models/config\";\nimport type { LogLevel } from \"../models/log-record\";\nimport { levelFor, longestPrefix } from \"./sampling\";\n\n/** Sampling rules from the ingest server, after validation. */\nexport interface RemoteRules {\n /** Rate used when no namespace rate matches. Without it, the config rate applies. */\n defaultRate?: number;\n /** Rate per namespace prefix. These apply on top of the config rates. */\n rates: Record<string, number>;\n /** Temporary capture switches. Every context applies its own allowlist. */\n capture?: Partial<Record<RemoteCaptureFlag, boolean>>;\n /** Lowest level the library sends. Can only lower `minLevel`. */\n minLevel?: LogLevel;\n /** Lowest level per namespace prefix. Can only lower the config's level. */\n minLevels?: Record<string, LogLevel>;\n}\n\n/** Rules and their TTL, after validation. */\nexport interface RemoteUpdate {\n /** Validated rules. */\n rules: RemoteRules;\n /** How long the rules stay in effect, in milliseconds. */\n ttlMs: number;\n}\n\n/** Rules in the header's shape. A context sends them to a forwarder over the bus. */\nexport interface RemoteWire extends RemoteRules {\n /** Rules version. */\n v: typeof REMOTE_SAMPLING_VERSION;\n /** How long the rules stay in effect, in milliseconds. */\n ttlMs: number;\n}\n\n/** The runtime's overlay slot. The sender or the bus fills it when the first rules arrive. */\nexport interface RemoteSlot {\n /** Overlay, or null before the first rules. */\n sampling: RemoteSampling | null;\n /** Refreshes captures after a trusted rule update. */\n changed?: () => void;\n}\n\n/** The remote sampling rules in effect for this context. */\nexport class RemoteSampling {\n /** Current rules, or null. */\n private rules: RemoteRules | null = null;\n\n /** When the rules arrived, in epoch milliseconds. */\n private receivedAt = 0;\n\n /** When the rules end, in epoch milliseconds. */\n private until = 0;\n\n /**\n * @param config Active configuration instance. A reconfigure changes it in place.\n */\n constructor(private readonly config: ResolvedConfig) {}\n\n /**\n * Puts new rules into effect, replacing the current ones.\n * @param update Validated rules and their TTL, or null when the upstream has no rules.\n */\n apply(update: RemoteUpdate | null): void {\n if (!update) {\n this.rules = null;\n return;\n }\n\n const now = Date.now();\n\n this.rules = update.rules;\n this.receivedAt = now;\n this.until = now + update.ttlMs;\n }\n\n /**\n * Returns the current rules.\n * @returns The rules, or null after the TTL or when `sampling.remote` is off.\n */\n current(): RemoteRules | null {\n if (!this.rules) {\n return null;\n }\n\n const now = Date.now();\n\n // Drop the rules when remote sampling is off, so turning it on again can't bring them back.\n // Also guard against a clock that moves back, which would keep the rules past their TTL.\n if (!this.config.sampling.remote || now < this.receivedAt || now >= this.until) {\n this.rules = null;\n return null;\n }\n\n return this.rules;\n }\n\n /**\n * Returns the lowest level the library sends for a namespace. A remote prefix level wins\n * over the remote `minLevel`, and a remote level applies only when it is lower than the\n * config level.\n * @param namespace Target application namespace.\n * @returns The lower of the remote level and the namespace's config level.\n */\n minLevelFor(namespace: string): LogLevel {\n const local = levelFor(namespace, this.config);\n const rules = this.current();\n const remote = longestPrefix(namespace, rules?.minLevels ?? {})?.value ?? rules?.minLevel;\n\n return remote !== undefined && LEVEL_ORDER[remote] < LEVEL_ORDER[local] ? remote : local;\n }\n\n /**\n * Returns the current rules in the header's shape, with the remaining TTL.\n * @returns The rules, or null if none are in effect.\n */\n wire(): RemoteWire | null {\n const rules = this.current();\n\n if (!rules) {\n return null;\n }\n\n return { ...rules, v: REMOTE_SAMPLING_VERSION, ttlMs: this.until - Date.now() };\n }\n}\n","// src/core/remote-rules.ts\n//\n// Validates the sampling rules from the ingest server and puts them into effect.\n// Imported by the sender and the bus. The main bundle doesn't include it.\n\nimport {\n LEVEL_ORDER,\n REMOTE_CAPTURE_FLAGS,\n REMOTE_SAMPLING_MAX_CHARS,\n REMOTE_SAMPLING_MAX_RATES,\n REMOTE_SAMPLING_MAX_TTL_MS,\n REMOTE_SAMPLING_VERSION,\n SAMPLING_RATE_MAX,\n SAMPLING_RATE_MIN,\n} from \"../constants\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { LogLevel } from \"../models/log-record\";\nimport { hasOwn, isObject } from \"../utils/guards\";\nimport type { Diagnostics } from \"./diagnostics\";\nimport {\n type RemoteRules,\n RemoteSampling,\n type RemoteSlot,\n type RemoteUpdate,\n} from \"./remote-sampling\";\n\n/** One validation step failed. The message states the rule. */\nclass RuleError extends Error {}\n\n/**\n * Checks whether a value is a rate.\n * @param value Value to check.\n * @returns True for a number from 0 to 1. NaN fails.\n */\nfunction isRate(value: unknown): value is number {\n return typeof value === \"number\" && value >= SAMPLING_RATE_MIN && value <= SAMPLING_RATE_MAX;\n}\n\n/**\n * Parses the header text as JSON.\n * @param text Header text.\n * @returns The parsed value.\n * @throws RuleError when the text is too long or isn't JSON.\n */\nfunction parseText(text: string): unknown {\n if (text.length > REMOTE_SAMPLING_MAX_CHARS) {\n throw new RuleError(\n `The header is longer than ${String(REMOTE_SAMPLING_MAX_CHARS)} characters.`,\n );\n }\n\n try {\n return JSON.parse(text);\n } catch {\n // The caller reports the RuleError.\n throw new RuleError(\"The header is not valid JSON.\");\n }\n}\n\n/**\n * Reads the namespace rates.\n * @param value Value of `rates`.\n * @returns The rates.\n * @throws RuleError when a rate is invalid.\n */\nfunction readRates(value: unknown): Record<string, number> {\n if (value === undefined) {\n return {};\n }\n\n const rule = `rates must be an object with at most ${String(REMOTE_SAMPLING_MAX_RATES)} rates from 0 to 1.`;\n\n if (!isObject(value)) {\n throw new RuleError(rule);\n }\n\n const entries = Object.entries(value);\n\n if (entries.length > REMOTE_SAMPLING_MAX_RATES || !entries.every(([, rate]) => isRate(rate))) {\n throw new RuleError(rule);\n }\n\n // fromEntries creates own properties, so a \"__proto__\" key can't change the prototype.\n return Object.fromEntries(entries) as Record<string, number>;\n}\n\n/**\n * Reads the level for every namespace prefix.\n * @param value Value of `minLevels`.\n * @returns The levels.\n * @throws RuleError when a level is invalid.\n */\nfunction readMinLevels(value: unknown): Record<string, LogLevel> {\n const rule = `minLevels must be an object with at most ${String(REMOTE_SAMPLING_MAX_RATES)} level names.`;\n\n if (!isObject(value)) {\n throw new RuleError(rule);\n }\n\n const entries = Object.entries(value);\n const valid = entries.every(\n ([, level]) => typeof level === \"string\" && hasOwn(LEVEL_ORDER, level),\n );\n\n if (entries.length > REMOTE_SAMPLING_MAX_RATES || !valid) {\n throw new RuleError(rule);\n }\n\n // fromEntries creates own properties, so a \"__proto__\" key can't change the prototype.\n return Object.fromEntries(entries) as Record<string, LogLevel>;\n}\n\n/**\n * Validates the rules. Sampling applies `remoteMaxRate` when it reads them.\n * @param value Parsed header value.\n * @returns The rules and their TTL.\n * @throws RuleError when a field is invalid.\n */\nfunction readRules(value: unknown): RemoteUpdate {\n if (!isObject(value)) {\n throw new RuleError(\"The rules must be an object.\");\n }\n\n if (value.v !== REMOTE_SAMPLING_VERSION) {\n throw new RuleError(`The version must be ${String(REMOTE_SAMPLING_VERSION)}.`);\n }\n\n const { ttlMs, defaultRate, minLevel } = value;\n\n if (typeof ttlMs !== \"number\" || !(ttlMs > 0 && ttlMs <= REMOTE_SAMPLING_MAX_TTL_MS)) {\n throw new RuleError(\n `ttlMs must be a number more than 0 and at most ${String(REMOTE_SAMPLING_MAX_TTL_MS)}.`,\n );\n }\n\n if (defaultRate !== undefined && !isRate(defaultRate)) {\n throw new RuleError(\"defaultRate must be a number from 0 to 1.\");\n }\n\n if (minLevel !== undefined && !(typeof minLevel === \"string\" && hasOwn(LEVEL_ORDER, minLevel))) {\n throw new RuleError(\"minLevel must be a level name, for example DEBUG.\");\n }\n\n const rules: RemoteRules = { rates: readRates(value.rates) };\n\n if (defaultRate !== undefined) {\n rules.defaultRate = defaultRate;\n }\n\n if (minLevel !== undefined) {\n rules.minLevel = minLevel as LogLevel;\n }\n\n if (value.minLevels !== undefined) {\n rules.minLevels = readMinLevels(value.minLevels);\n }\n\n if (value.capture !== undefined) {\n const capture = value.capture;\n if (!isObject(capture)) {\n throw new RuleError(\"capture must be an object of capture switches.\");\n }\n\n const entries = Object.entries(capture);\n if (\n !entries.every(\n ([key, flag]) =>\n REMOTE_CAPTURE_FLAGS.some((name) => name === key) && typeof flag === \"boolean\",\n )\n ) {\n throw new RuleError(\n \"capture must contain boolean capture switches without privacy controls.\",\n );\n }\n\n rules.capture = Object.fromEntries(entries);\n }\n\n return { rules, ttlMs };\n}\n\n/**\n * Validates sampling rules from the server. One invalid rule rejects all of them.\n * @param raw Header text, or a parsed object from a custom transport or the bus.\n * @param diagnostics Diagnostics reporter.\n * @returns The rules and their TTL, or null if they are invalid.\n */\nexport function parseRemoteRules(raw: unknown, diagnostics: Diagnostics): RemoteUpdate | null {\n try {\n return readRules(typeof raw === \"string\" ? parseText(raw) : raw);\n } catch (error) {\n const reason = error instanceof RuleError ? ` ${error.message}` : \"\";\n\n diagnostics.report(\n \"config.invalid\",\n `The library ignores the sampling rules from the server.${reason}`,\n undefined,\n error,\n );\n return null;\n }\n}\n\n/**\n * Puts rules into effect in the runtime's slot. Creates the overlay for the first rules.\n * @param slot The runtime's slot.\n * @param config Active configuration instance.\n * @param update Validated rules, or null when the upstream has no rules.\n */\nexport function applyRemote(\n slot: RemoteSlot,\n config: ResolvedConfig,\n update: RemoteUpdate | null,\n): void {\n if (update) {\n slot.sampling ??= new RemoteSampling(config);\n }\n\n slot.sampling?.apply(update);\n slot.changed?.();\n}\n"],"mappings":";;;;;AAkDA,IAAaS,IAAb,MAA4B;CAa1B,YAAY,GAAyC;EAAxB,AAAAD,EAAA,MAAA,UAAA,KAAA,CAAA,GAX7BA,EAAA,MAAA,SAAoC,IAAA,GAGpCA,EAAA,MAAA,cAAqB,CAAA,GAGrBA,EAAA,MAAA,SAAgB,CAAA,GAKa,KAAA,SAAAE;CAAyB;CAMtD,MAAM,GAAmC;EACvC,IAAI,CAACC,GAAQ;GACX,KAAK,QAAQ;GACb;EACF;EAEA,IAAMC,IAAM,KAAK,IAAI;EAIrB,AAFA,KAAK,QAAQD,EAAO,OACpB,KAAK,aAAaC,GAClB,KAAK,QAAQA,IAAMD,EAAO;CAC5B;CAMA,UAA8B;EAC5B,IAAI,CAAC,KAAK,OACR,OA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S,CAAO;EACtC,IACE,CAACT,EAAQ,OACN,CAACU,GAAKC,OACLhC,EAAqB,MAAM,MAASiC,MAASF,CAAG,KAAK,OAAOC,KAAS,SACzE,GAEA,MAAM,IAAIlB,EACR,yEACF;EAGF,EAAM,UAAU,OAAO,YAAYO,CAAO;CAC5C;CAEA,OAAO;EAAE;EAAO;CAAM;AACxB;AAQA,SAAgBa,EAAiB,GAAc,GAA+C;CAC5F,IAAI;EACF,OAAOR,EAAU,OAAOS,KAAQ,WAAWlB,EAAUkB,CAAG,IAAIA,CAAG;CACjE,SAASC,GAAO;EACd,IAAMC,IAASD,aAAiBtB,IAAY,IAAIsB,EAAM,YAAY;EAQlE,OANAE,EAAY,OACV,kBACA,0DAA0DD,KAC1D,KAAA,GACAD,CACF,GACO;CACT;AACF;AAQA,SAAgBG,EACd,GACA,GACA,GACM;CAMN,AALI/B,MACF,EAAK,aAAa,IAAIF,EAAeC,CAAM,IAG7CiC,EAAK,UAAU,MAAMhC,CAAM,GAC3BgC,EAAK,UAAU;AACjB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as c } from "./identity-
|
|
3
|
-
import { r as l, t as u } from "./library-request-
|
|
1
|
+
import { dt as e, ft as t, mn as n, nt as r, pt as i, ut as a, yt as o, z as s } from "./constants-BwJDXzj6.js";
|
|
2
|
+
import { i as c } from "./identity-BgtHyY4u.js";
|
|
3
|
+
import { r as l, t as u } from "./library-request-UGEwOHpf.js";
|
|
4
4
|
import { t as d } from "./unref-DgHPQeWv.js";
|
|
5
5
|
import { t as f } from "./defineProperty-s2S8BXUc.js";
|
|
6
|
-
import { t as p } from "./compression-
|
|
6
|
+
import { t as p } from "./compression-SHPAvS4U.js";
|
|
7
7
|
import { n as m } from "./deadline-C4ccAuk5.js";
|
|
8
|
-
import { t as h } from "./storm-
|
|
8
|
+
import { t as h } from "./storm-DKlpv0FL.js";
|
|
9
9
|
import { t as g } from "./types-BAerHgCq.js";
|
|
10
10
|
// src/capture/replay-buffer.ts
|
|
11
11
|
var _ = 4, v = 3, y = class {
|
|
@@ -97,10 +97,10 @@ var _ = 4, v = 3, y = class {
|
|
|
97
97
|
sequence: e.sequence
|
|
98
98
|
}), this.busy = !1, this.drain();
|
|
99
99
|
}
|
|
100
|
-
async send(
|
|
100
|
+
async send(n, o, c) {
|
|
101
101
|
let u = this.config(), { onSegment: f, endpoint: h, headers: g } = u.replay, _ = u.delivery.requestTimeoutMs;
|
|
102
102
|
if (f) try {
|
|
103
|
-
return await m(Promise.resolve(f(
|
|
103
|
+
return await m(Promise.resolve(f(n)), _), "sent";
|
|
104
104
|
} catch (e) {
|
|
105
105
|
return this.diagnostics.report("capture.record_failed", `The replay.onSegment function threw an error, or it did not end in ${String(_)} ms.`, void 0, e), "drop";
|
|
106
106
|
}
|
|
@@ -111,11 +111,11 @@ var _ = 4, v = 3, y = class {
|
|
|
111
111
|
d(y);
|
|
112
112
|
try {
|
|
113
113
|
let d = typeof g == "function" ? await m(Promise.resolve(g()), _) : g, f = new Headers(d ?? {});
|
|
114
|
-
f.set(
|
|
115
|
-
let { payload: y, events: x, ...w } =
|
|
114
|
+
f.set(i, s), f.set(e, `${n["replay.id"]}-${String(n.sequence)}`), f.set(a, String(o - 1));
|
|
115
|
+
let { payload: y, events: x, ...w } = n, T = `${JSON.stringify(w).slice(0, -1)},"events":${y}}`, E = T;
|
|
116
116
|
if (u.compression === "gzip" && T.length >= 1024) {
|
|
117
117
|
let e = await p(T);
|
|
118
|
-
e && (E = e, f.set(t,
|
|
118
|
+
e && (E = e, f.set(t, r));
|
|
119
119
|
}
|
|
120
120
|
if (c !== this.generation) return "drop";
|
|
121
121
|
this.inFlight = v;
|
|
@@ -217,34 +217,34 @@ var _ = 4, v = 3, y = class {
|
|
|
217
217
|
this.installed = !1, this.ctx.onError?.(void 0), this.stop();
|
|
218
218
|
}
|
|
219
219
|
async start() {
|
|
220
|
-
let { diagnostics:
|
|
220
|
+
let { diagnostics: e } = this.ctx, { loader: t, endpoint: r, onSegment: i, plugins: a } = this.ctx.config.replay;
|
|
221
221
|
if (!this.installed || this.record || this.starting) return;
|
|
222
222
|
if (typeof document > "u") {
|
|
223
223
|
this.reportOnce("This context has no document. The session replay is off.");
|
|
224
224
|
return;
|
|
225
225
|
}
|
|
226
|
-
if (!
|
|
227
|
-
|
|
226
|
+
if (!t || r === null && !i) {
|
|
227
|
+
e.report("config.invalid", "The session replay needs replay.loader, and replay.endpoint or replay.onSegment. The session replay is off.");
|
|
228
228
|
return;
|
|
229
229
|
}
|
|
230
230
|
let o = this.selectors();
|
|
231
231
|
if (!o) return;
|
|
232
232
|
let { generation: s } = this;
|
|
233
233
|
this.starting = !0;
|
|
234
|
-
let l = await
|
|
234
|
+
let l = await e.guardAsync("capture.install_failed", "The library could not load the replay recorder.", t), u = { transformRequest: this.transformRequest }, d = await Promise.all(a.map((t) => e.guardAsync("capture.install_failed", "The library could not load a replay plugin.", () => Promise.resolve(t(u)))));
|
|
235
235
|
if (s !== this.generation || (this.starting = !1, !l)) return;
|
|
236
236
|
let { record: f } = l;
|
|
237
237
|
if (typeof f != "function") {
|
|
238
|
-
|
|
238
|
+
e.report("capture.install_failed", "The replay loader gave no record function. The session replay is off.");
|
|
239
239
|
return;
|
|
240
240
|
}
|
|
241
241
|
let p = this.ctx.config.replay;
|
|
242
|
-
|
|
243
|
-
let
|
|
244
|
-
for (let [e,
|
|
245
|
-
r.length > 0 &&
|
|
242
|
+
e.guard("capture.install_failed", "The replay recorder did not start.", () => {
|
|
243
|
+
let t = {}, r = [];
|
|
244
|
+
for (let [e, n] of Object.entries(p.recordOptions)) O.includes(e) ? t[e] = n : r.push(e);
|
|
245
|
+
r.length > 0 && e.report("config.invalid", `The library ignores these keys of replay.recordOptions: ${r.join(", ")}. It sets the mask, block, canvas, plugin and event options itself.`), this.starvedReported = !1;
|
|
246
246
|
let i = f({
|
|
247
|
-
...
|
|
247
|
+
...t,
|
|
248
248
|
emit: this.emit,
|
|
249
249
|
checkoutEveryNms: p.bufferMs / 2,
|
|
250
250
|
maskAllInputs: !1,
|
|
@@ -257,7 +257,7 @@ var _ = 4, v = 3, y = class {
|
|
|
257
257
|
errorHandler: this.onFault,
|
|
258
258
|
plugins: d.filter((e) => e !== void 0)
|
|
259
259
|
});
|
|
260
|
-
typeof i == "function" ? (this.stopRecorder = i, this.record = f, this.replayId = c(this.ctx.diagnostics), this.ctx.setContext?.(
|
|
260
|
+
typeof i == "function" ? (this.stopRecorder = i, this.record = f, this.replayId = c(this.ctx.diagnostics), this.ctx.setContext?.(n, this.replayId)) : e.report("capture.install_failed", "The replay recorder did not start.");
|
|
261
261
|
});
|
|
262
262
|
}
|
|
263
263
|
reset() {
|
|
@@ -265,8 +265,8 @@ var _ = 4, v = 3, y = class {
|
|
|
265
265
|
this.stop(), e && this.start();
|
|
266
266
|
}
|
|
267
267
|
stop() {
|
|
268
|
-
let { stopRecorder:
|
|
269
|
-
this.generation++, this.starting = !1, this.record = void 0, this.stopRecorder = void 0, this.live = !1, clearTimeout(this.liveTimer), this.liveTimer = void 0, this.buffer.clear(), this.uploader.stop(),
|
|
268
|
+
let { stopRecorder: e } = this;
|
|
269
|
+
this.generation++, this.starting = !1, this.record = void 0, this.stopRecorder = void 0, this.live = !1, clearTimeout(this.liveTimer), this.liveTimer = void 0, this.buffer.clear(), this.uploader.stop(), e && (this.ctx.setContext?.(n, void 0), this.ctx.diagnostics.guard("capture.install_failed", "The replay recorder did not stop.", e));
|
|
270
270
|
}
|
|
271
271
|
selectors() {
|
|
272
272
|
let { maskText: e, maskSelectors: t, blockSelectors: n } = this.ctx.config.replay;
|
|
@@ -307,4 +307,4 @@ var _ = 4, v = 3, y = class {
|
|
|
307
307
|
};
|
|
308
308
|
export { F as ReplayCapture };
|
|
309
309
|
|
|
310
|
-
//# sourceMappingURL=replay-
|
|
310
|
+
//# sourceMappingURL=replay-B0M8kWz_.js.map
|