@utk09/ui-observability 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -1
- package/README.md +50 -11
- package/dist/{batch-BHXypM1j.cjs → batch-C8OcWR2L.cjs} +2 -2
- package/dist/{batch-BHXypM1j.cjs.map → batch-C8OcWR2L.cjs.map} +1 -1
- package/dist/{batch-BMdT9mKm.js → batch-CL9uWYY3.js} +4 -5
- package/dist/{batch-BMdT9mKm.js.map → batch-CL9uWYY3.js.map} +1 -1
- package/dist/{bus-DKfBaica.js → bus-BZ0GldpT.js} +23 -27
- package/dist/{bus-DKfBaica.js.map → bus-BZ0GldpT.js.map} +1 -1
- package/dist/{bus-Dea9rVhy.cjs → bus-VWlmM5xs.cjs} +2 -2
- package/dist/{bus-Dea9rVhy.cjs.map → bus-VWlmM5xs.cjs.map} +1 -1
- package/dist/console-BPZCuSLc.cjs +2 -0
- package/dist/{console-DZEcs7FL.cjs.map → console-BPZCuSLc.cjs.map} +1 -1
- package/dist/{console-BX_0UCV7.js → console-BeCF7n59.js} +14 -15
- package/dist/{console-BX_0UCV7.js.map → console-BeCF7n59.js.map} +1 -1
- package/dist/{constants-CL0ZdI2f.cjs → constants-DqKJH_MP.cjs} +2 -2
- package/dist/{constants-CL0ZdI2f.cjs.map → constants-DqKJH_MP.cjs.map} +1 -1
- package/dist/{constants-CU60FG4w.js → constants-zyrqveN4.js} +3 -4
- package/dist/{constants-CU60FG4w.js.map → constants-zyrqveN4.js.map} +1 -1
- package/dist/context-storage-BjzeBSxH.cjs.map +1 -1
- package/dist/{context-storage-DxZf4Gfh.js → context-storage-BzkoHzkQ.js} +2 -3
- package/dist/{context-storage-DxZf4Gfh.js.map → context-storage-BzkoHzkQ.js.map} +1 -1
- package/dist/{deadline-5_PecIl5.js → deadline-BOjOxNHj.js} +3 -5
- package/dist/{deadline-5_PecIl5.js.map → deadline-BOjOxNHj.js.map} +1 -1
- package/dist/deadline-XSnm95pg.cjs.map +1 -1
- package/dist/{debug-bundle-yRkrU1ny.cjs → debug-bundle-BzJNpbF0.cjs} +2 -2
- package/dist/{debug-bundle-yRkrU1ny.cjs.map → debug-bundle-BzJNpbF0.cjs.map} +1 -1
- package/dist/{debug-bundle-CZZ6SQQh.js → debug-bundle-C7UkHZ-q.js} +5 -6
- package/dist/{debug-bundle-CZZ6SQQh.js.map → debug-bundle-C7UkHZ-q.js.map} +1 -1
- package/dist/doctor.cjs +1 -1
- package/dist/doctor.cjs.map +1 -1
- package/dist/doctor.js +3 -4
- package/dist/{emergency-queue-CQ-9acZf.cjs → emergency-queue-CNTRui5t.cjs} +2 -2
- package/dist/{emergency-queue-CQ-9acZf.cjs.map → emergency-queue-CNTRui5t.cjs.map} +1 -1
- package/dist/{emergency-queue-Cs8-i2xw.js → emergency-queue-Zy6lNafo.js} +15 -17
- package/dist/{emergency-queue-Cs8-i2xw.js.map → emergency-queue-Zy6lNafo.js.map} +1 -1
- package/dist/{error-like-Ywo5uRHo.js → error-like-B11pB4aL.js} +2 -3
- package/dist/{error-like-Ywo5uRHo.js.map → error-like-B11pB4aL.js.map} +1 -1
- package/dist/error-like-gGRx2s36.cjs.map +1 -1
- package/dist/{errors-oyxrpHjY.js → errors-Dh7kef0i.js} +5 -6
- package/dist/{errors-oyxrpHjY.js.map → errors-Dh7kef0i.js.map} +1 -1
- package/dist/{errors-CigX45pL.cjs → errors-tfEr48bS.cjs} +2 -2
- package/dist/{errors-CigX45pL.cjs.map → errors-tfEr48bS.cjs.map} +1 -1
- package/dist/{factory-Bgsky_e0.js → factory-BonqI3NL.js} +9 -13
- package/dist/{factory-Bgsky_e0.js.map → factory-BonqI3NL.js.map} +1 -1
- package/dist/{factory-BkjNzPYL.cjs → factory-CJXVYp0R.cjs} +2 -2
- package/dist/{factory-BkjNzPYL.cjs.map → factory-CJXVYp0R.cjs.map} +1 -1
- package/dist/fixed-window-CvESpFYV.cjs.map +1 -1
- package/dist/{fixed-window-CtaFHanJ.js → fixed-window-Dq3MLUUv.js} +2 -3
- package/dist/{fixed-window-CtaFHanJ.js.map → fixed-window-Dq3MLUUv.js.map} +1 -1
- package/dist/global-scope-BN-Io_yv.cjs.map +1 -1
- package/dist/{global-scope-dp2jADRl.js → global-scope-D9I8s-oN.js} +2 -3
- package/dist/{global-scope-dp2jADRl.js.map → global-scope-D9I8s-oN.js.map} +1 -1
- package/dist/{guards-CpvOpJL6.js → guards-Cidk71ME.js} +2 -3
- package/dist/{guards-CpvOpJL6.js.map → guards-Cidk71ME.js.map} +1 -1
- package/dist/guards-nJ70syPt.cjs.map +1 -1
- package/dist/{identity-BMlKGHUM.cjs → identity-Cxgj6pZX.cjs} +2 -2
- package/dist/{identity-BMlKGHUM.cjs.map → identity-Cxgj6pZX.cjs.map} +1 -1
- package/dist/{identity-DOaHdfhT.js → identity-DT5VmvXy.js} +3 -4
- package/dist/{identity-DOaHdfhT.js.map → identity-DT5VmvXy.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +46 -56
- package/dist/index.js.map +1 -1
- package/dist/{indexeddb-storage-D-lUW_5P.js → indexeddb-storage-BJVtiQKm.js} +5 -6
- package/dist/{indexeddb-storage-D-lUW_5P.js.map → indexeddb-storage-BJVtiQKm.js.map} +1 -1
- package/dist/{indexeddb-storage-CaXGJqDD.cjs → indexeddb-storage-CIoW21Xd.cjs} +2 -2
- package/dist/{indexeddb-storage-CaXGJqDD.cjs.map → indexeddb-storage-CIoW21Xd.cjs.map} +1 -1
- package/dist/{interactions-CqDNrtIR.js → interactions-DTgKy_6K.js} +10 -11
- package/dist/{interactions-CqDNrtIR.js.map → interactions-DTgKy_6K.js.map} +1 -1
- package/dist/{interactions-8DgxtmgO.cjs → interactions-fEN6FbVo.cjs} +2 -2
- package/dist/{interactions-8DgxtmgO.cjs.map → interactions-fEN6FbVo.cjs.map} +1 -1
- package/dist/{journey-DgIjhrIc.js → journey-CuJrHzEg.js} +9 -10
- package/dist/{journey-DgIjhrIc.js.map → journey-CuJrHzEg.js.map} +1 -1
- package/dist/{journey-5tcxEbnG.cjs → journey-pffMVMfa.cjs} +2 -2
- package/dist/{journey-5tcxEbnG.cjs.map → journey-pffMVMfa.cjs.map} +1 -1
- package/dist/keys-BHhw_0Wh.cjs.map +1 -1
- package/dist/{keys-D5r_GH9q.js → keys-BU9j5YqW.js} +2 -3
- package/dist/{keys-D5r_GH9q.js.map → keys-BU9j5YqW.js.map} +1 -1
- package/dist/library-console-C1m6g1BR.js +13 -0
- package/dist/{library-console-CabK2j2-.js.map → library-console-C1m6g1BR.js.map} +1 -1
- package/dist/{library-console-g_VU-wzP.cjs → library-console-D2GY9Or6.cjs} +2 -2
- package/dist/{library-console-g_VU-wzP.cjs.map → library-console-D2GY9Or6.cjs.map} +1 -1
- package/dist/{library-request-FQaiWjCP.cjs → library-request-1BX_UlaX.cjs} +2 -2
- package/dist/{library-request-FQaiWjCP.cjs.map → library-request-1BX_UlaX.cjs.map} +1 -1
- package/dist/{library-request-CyC-9IOk.js → library-request-BQBT9N9Q.js} +4 -5
- package/dist/{library-request-CyC-9IOk.js.map → library-request-BQBT9N9Q.js.map} +1 -1
- package/dist/{lifecycle-C2z_d8OX.cjs → lifecycle-2EtUaRpo.cjs} +2 -2
- package/dist/{lifecycle-C2z_d8OX.cjs.map → lifecycle-2EtUaRpo.cjs.map} +1 -1
- package/dist/{lifecycle-BLC4VU7c.js → lifecycle-BaKx_-32.js} +3 -4
- package/dist/{lifecycle-BLC4VU7c.js.map → lifecycle-BaKx_-32.js.map} +1 -1
- package/dist/{log-record-CndanC-p.js → log-record-CAoGBBf3.js} +3 -4
- package/dist/{log-record-CndanC-p.js.map → log-record-CAoGBBf3.js.map} +1 -1
- package/dist/{log-record-DKvo-B-d.cjs → log-record-i9zOTkpQ.cjs} +2 -2
- package/dist/{log-record-DKvo-B-d.cjs.map → log-record-i9zOTkpQ.cjs.map} +1 -1
- package/dist/{long-frames-CV5ZG2cx.cjs → long-frames-BVg4i5SC.cjs} +2 -2
- package/dist/{long-frames-CV5ZG2cx.cjs.map → long-frames-BVg4i5SC.cjs.map} +1 -1
- package/dist/{long-frames-BQef9rXR.js → long-frames-Czk7IupC.js} +4 -5
- package/dist/{long-frames-BQef9rXR.js.map → long-frames-Czk7IupC.js.map} +1 -1
- package/dist/{network-CvkvYzRU.js → network-DBNwApoF.js} +22 -24
- package/dist/{network-CvkvYzRU.js.map → network-DBNwApoF.js.map} +1 -1
- package/dist/{network-CqnQOqon.cjs → network-xbbuvG_6.cjs} +2 -2
- package/dist/{network-CqnQOqon.cjs.map → network-xbbuvG_6.cjs.map} +1 -1
- package/dist/openfin-Bxelt0yg.js +7 -0
- package/dist/{openfin-BwEN0uj4.js.map → openfin-Bxelt0yg.js.map} +1 -1
- package/dist/openfin-DtH2f7zX.cjs.map +1 -1
- package/dist/{otlp-RVbkNQRh.cjs → otlp-BDvFrLnc.cjs} +2 -2
- package/dist/{otlp-RVbkNQRh.cjs.map → otlp-BDvFrLnc.cjs.map} +1 -1
- package/dist/{otlp-CYIL7MOE.js → otlp-BTJdIa6F.js} +4 -6
- package/dist/{otlp-CYIL7MOE.js.map → otlp-BTJdIa6F.js.map} +1 -1
- package/dist/patch-BX8KrPCT.cjs.map +1 -1
- package/dist/{patch-CCWfuEY7.js → patch-UdPz1ea8.js} +2 -3
- package/dist/{patch-CCWfuEY7.js.map → patch-UdPz1ea8.js.map} +1 -1
- package/dist/{platform-KMWkoI-v.cjs → platform-C2Ez5kDc.cjs} +2 -2
- package/dist/{platform-KMWkoI-v.cjs.map → platform-C2Ez5kDc.cjs.map} +1 -1
- package/dist/{platform-wcAkkv9F.js → platform-DkcuXwe-.js} +4 -5
- package/dist/{platform-wcAkkv9F.js.map → platform-DkcuXwe-.js.map} +1 -1
- package/dist/{remote-rules-CH_7PphT.js → remote-rules-Cfb4K-Nl.js} +5 -6
- package/dist/{remote-rules-CH_7PphT.js.map → remote-rules-Cfb4K-Nl.js.map} +1 -1
- package/dist/{remote-rules-BL8km4xk.cjs → remote-rules-vzvk7aKf.cjs} +2 -2
- package/dist/{remote-rules-BL8km4xk.cjs.map → remote-rules-vzvk7aKf.cjs.map} +1 -1
- package/dist/{reports-Bh_-KpZ2.cjs → reports-Dk2YhKIh.cjs} +2 -2
- package/dist/{reports-Bh_-KpZ2.cjs.map → reports-Dk2YhKIh.cjs.map} +1 -1
- package/dist/{reports-BOKyY3_A.js → reports-TA-zInnq.js} +4 -5
- package/dist/{reports-BOKyY3_A.js.map → reports-TA-zInnq.js.map} +1 -1
- package/dist/{resource-timing-BROnEJ0E.js → resource-timing-BLv3EA2A.js} +6 -7
- package/dist/{resource-timing-BROnEJ0E.js.map → resource-timing-BLv3EA2A.js.map} +1 -1
- package/dist/{resource-timing-CbgwNpog.cjs → resource-timing-Cysw1S1f.cjs} +2 -2
- package/dist/{resource-timing-CbgwNpog.cjs.map → resource-timing-Cysw1S1f.cjs.map} +1 -1
- package/dist/{sampling-BLO_pcV4.js → sampling-C4VV-1MS.js} +4 -5
- package/dist/{sampling-BLO_pcV4.js.map → sampling-C4VV-1MS.js.map} +1 -1
- package/dist/{sampling-ECGVYiDD.cjs → sampling-Ckh2yW9k.cjs} +2 -2
- package/dist/{sampling-ECGVYiDD.cjs.map → sampling-Ckh2yW9k.cjs.map} +1 -1
- package/dist/{sanitize-DS0G4_ea.js → sanitize-6ymPlVvP.js} +4 -5
- package/dist/{sanitize-DS0G4_ea.js.map → sanitize-6ymPlVvP.js.map} +1 -1
- package/dist/{sanitize-Bsn8HQWC.cjs → sanitize-BAWzkZt0.cjs} +2 -2
- package/dist/{sanitize-Bsn8HQWC.cjs.map → sanitize-BAWzkZt0.cjs.map} +1 -1
- package/dist/{select-DWO0-w8_.cjs → select-ZF4by-lF.cjs} +2 -2
- package/dist/{select-DWO0-w8_.cjs.map → select-ZF4by-lF.cjs.map} +1 -1
- package/dist/{select-wqt9Wxio.js → select-xtQaenIi.js} +7 -10
- package/dist/{select-wqt9Wxio.js.map → select-xtQaenIi.js.map} +1 -1
- package/dist/{sender-BkAVt-Rq.js → sender-CiMHC9YG.js} +92 -96
- package/dist/{sender-BkAVt-Rq.js.map → sender-CiMHC9YG.js.map} +1 -1
- package/dist/{sender-D82PxlCY.cjs → sender-D5wBoXA8.cjs} +2 -2
- package/dist/{sender-D82PxlCY.cjs.map → sender-D5wBoXA8.cjs.map} +1 -1
- package/dist/storage-BA9RqRO-.cjs.map +1 -1
- package/dist/{storage-w7Tslvlq.js → storage-DZwed89z.js} +2 -3
- package/dist/{storage-w7Tslvlq.js.map → storage-DZwed89z.js.map} +1 -1
- package/dist/{storm-DCEsqViG.cjs → storm-CYi9Swpx.cjs} +2 -2
- package/dist/{storm-DCEsqViG.cjs.map → storm-CYi9Swpx.cjs.map} +1 -1
- package/dist/{storm-DD4cUkoL.js → storm-VR024_QN.js} +4 -5
- package/dist/{storm-DD4cUkoL.js.map → storm-VR024_QN.js.map} +1 -1
- package/dist/{types-BR9t_w28.js → types-BAerHgCq.js} +2 -3
- package/dist/{types-BR9t_w28.js.map → types-BAerHgCq.js.map} +1 -1
- package/dist/types-C7WNpnG1.cjs.map +1 -1
- package/dist/{unclean-exit-BYZ5yaSI.js → unclean-exit-CwcUhFOn.js} +3 -4
- package/dist/{unclean-exit-BYZ5yaSI.js.map → unclean-exit-CwcUhFOn.js.map} +1 -1
- package/dist/{unclean-exit-CwdpbUDg.cjs → unclean-exit-DFUN57wY.cjs} +2 -2
- package/dist/{unclean-exit-CwdpbUDg.cjs.map → unclean-exit-DFUN57wY.cjs.map} +1 -1
- package/dist/{user-timing-C1kB3JEg.cjs → user-timing-C9kfRq3J.cjs} +2 -2
- package/dist/{user-timing-C1kB3JEg.cjs.map → user-timing-C9kfRq3J.cjs.map} +1 -1
- package/dist/{user-timing-Di2ra5DB.js → user-timing-_jZIhDKI.js} +4 -5
- package/dist/{user-timing-Di2ra5DB.js.map → user-timing-_jZIhDKI.js.map} +1 -1
- package/dist/{web-socket-DwBNhgre.cjs → web-socket-BWUoqBh8.cjs} +2 -2
- package/dist/{web-socket-DwBNhgre.cjs.map → web-socket-BWUoqBh8.cjs.map} +1 -1
- package/dist/{web-socket-B-5qqPy7.js → web-socket-CV7yIMnm.js} +14 -15
- package/dist/{web-socket-B-5qqPy7.js.map → web-socket-CV7yIMnm.js.map} +1 -1
- package/dist/{web-vitals-Bflr5jSA.js → web-vitals-Bq4WFHQo.js} +2 -3
- package/dist/{web-vitals-Bflr5jSA.js.map → web-vitals-Bq4WFHQo.js.map} +1 -1
- package/dist/web-vitals-DFuoTQbZ.cjs.map +1 -1
- package/dist/{worker-protocol-DXekoADQ.cjs → worker-protocol-Bai7GAIA.cjs} +2 -2
- package/dist/{worker-protocol-DXekoADQ.cjs.map → worker-protocol-Bai7GAIA.cjs.map} +1 -1
- package/dist/{worker-protocol-0HMf4-kY.js → worker-protocol-CrsdSDLn.js} +6 -7
- package/dist/{worker-protocol-0HMf4-kY.js.map → worker-protocol-CrsdSDLn.js.map} +1 -1
- package/dist/worker-server-BrIYkfoa.cjs +2 -0
- package/dist/{worker-server-BQK5z2yl.cjs.map → worker-server-BrIYkfoa.cjs.map} +1 -1
- package/dist/{worker-server-CKcmX5m5.js → worker-server-Dp5HYm4b.js} +25 -26
- package/dist/{worker-server-CKcmX5m5.js.map → worker-server-Dp5HYm4b.js.map} +1 -1
- package/dist/{worker-transport-Dj2yCQN5.cjs → worker-transport-Bwej4N2e.cjs} +2 -2
- package/dist/{worker-transport-Dj2yCQN5.cjs.map → worker-transport-Bwej4N2e.cjs.map} +1 -1
- package/dist/{worker-transport-2220ghFZ.js → worker-transport-D6jtgpqN.js} +9 -11
- package/dist/{worker-transport-2220ghFZ.js.map → worker-transport-D6jtgpqN.js.map} +1 -1
- package/package.json +27 -41
- package/dist/console-DZEcs7FL.cjs +0 -2
- package/dist/library-console-CabK2j2-.js +0 -14
- package/dist/openfin-BwEN0uj4.js +0 -8
- package/dist/worker-server-BQK5z2yl.cjs +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./constants-CL0ZdI2f.cjs"),t=require("./log-record-DKvo-B-d.cjs"),n=require("./deadline-XSnm95pg.cjs"),r=require("./openfin-DtH2f7zX.cjs"),i=require("./platform-KMWkoI-v.cjs"),a=require("./library-console-g_VU-wzP.cjs"),o=require("./sanitize-Bsn8HQWC.cjs"),s=require("./identity-BMlKGHUM.cjs"),c=require("./library-request-FQaiWjCP.cjs"),l=require("./batch-BHXypM1j.cjs"),u=require("./sampling-ECGVYiDD.cjs"),d=require("./otlp-RVbkNQRh.cjs"),f=require("./remote-rules-BL8km4xk.cjs"),p=require("./storage-BA9RqRO-.cjs"),m=require("./emergency-queue-CQ-9acZf.cjs"),h=require("./factory-BkjNzPYL.cjs"),g=require("./context-storage-BjzeBSxH.cjs"),_=require("./select-DWO0-w8_.cjs");async function v(e){let t=globalThis.navigator?.storage;return typeof t?.persist==`function`?await e.guardAsync(`storage.unavailable`,`The browser rejected the request for persistent storage.`,()=>t.persist())===!0?`granted`:`denied`:`unsupported`}function y(e){let t=typeof e==`string`?Date.parse(e):NaN;return Number.isNaN(t)?void 0:Math.round(t+500-Date.now())}var b=class{config;diagnostics;onSampling;onLoss;onClock;cancellation=new AbortController;stop(){this.cancellation.abort()}assertContext(e){if(this.cancellation.signal.aborted||this.config.securityContext.isolation&&this.config.securityContext.id&&e.routingContextId!==this.config.securityContext.id)throw this.diagnostics.count(`security.context_mismatch`),new _.s(`permanent`,`The delivery context is inactive or does not match the batch.`)}async untilCancelled(e){if(this.cancellation.signal.aborted)throw new _.s(`permanent`,`The delivery context retired.`);let t,n=new Promise((e,n)=>{t=()=>{n(new _.s(`permanent`,`The delivery context retired.`))},this.cancellation.signal.addEventListener(`abort`,t,{once:!0})});try{return await Promise.race([e,n])}finally{this.cancellation.signal.removeEventListener(`abort`,t)}}throttledUntil={logs:0,metrics:0,traces:0};acceptedAt=null;constructor(e,t,n=()=>void 0,r=()=>void 0,i=()=>void 0){this.config=e,this.diagnostics=t,this.onSampling=n,this.onLoss=r,this.onClock=i}throttledForMs(e){return Math.max(0,this.throttledUntil[_.t(e,this.config)]-Date.now())}lastSendAt(){return this.acceptedAt}serialize(e){let t=_.r(this.config,e,this.diagnostics,`The serializer threw an error. The library dropped the batch.`);return t||this.onLoss(`unserializable`,e.records,[e.id]),t}accept(e,t,n){this.throttledUntil[e]=0,this.acceptedAt=Date.now(),this.config.sampling.remote&&t!=null&&this.onSampling(t);let r=y(n);r!==void 0&&this.onClock(r)}reject(e,t,n,r){let i=String(e);if(e===401||e===403){let t=r.advice===void 0?``:` ${r.advice}`;return this.diagnostics.report(`transport.rejected_credentials`,`The server returned ${i}.${t}`,{status:e,endpoint:_.n(n,this.config)}),new _.s(`permanent`,`The server rejected the batch with ${i}.`,e)}if(e===413)return new _.s(`too_large`,`The payload is too large.`,e,void 0,r.maxBytes);if(e===429||e===503){let t=e===429,i=r.retryAfterMs===void 0?void 0:Math.min(r.retryAfterMs,this.config.delivery.retryMaxDelayMs);return this.throttledUntil[n]=Date.now()+(i??this.config.delivery.retryBaseDelayMs),t&&this.diagnostics.report(`transport.throttled`,`The server throttles the requests.`,{retryAfterMs:i}),new _.s(`throttled`,t?`The server throttles the requests.`:`The service is not available.`,e,i)}return e===408||e>=500?new _.s(`transient`,`The server returned the error ${i}.`,e):(this.diagnostics.report(`transport.dropped_permanent`,`The server rejected the batch with ${i}. The library dropped it.`,{batchId:t,status:e}),new _.s(`permanent`,`The server rejected the batch with ${i}.`,e))}};function x(e,t,n){return{kind:n,body:t.body,contentType:t.contentType,batchId:e.id,attempt:e.attempts,records:e.records,routingContextId:e.routingContextId}}function S(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`status`);return typeof t==`number`&&Number.isInteger(t)&&t>=100&&t<=599}function C(e){return typeof e==`number`&&Number.isFinite(e)?Math.max(0,e):void 0}var w=class extends b{async send(e){this.assertContext(e);let{transport:t}=this.config;if(!t||e.records.length===0)return;let r=this.serialize(e);if(!r)return;let i=_.t(e,this.config),o=x(e,r,i);o.signal=this.cancellation.signal;let s;try{s=await n.n(this.untilCancelled(c.i(()=>c.r(()=>a.n(()=>t(o))))),this.config.delivery.requestTimeoutMs)}catch(e){let t=e instanceof n.t?e:void 0,r=t?`timeout`:`transient`,i=t?.message??`The custom transport failed.`;throw new _.s(r,i,void 0,void 0,void 0,e)}if(this.assertContext(e),!S(s))throw this.diagnostics.report(`transport.http_error`,`The custom transport returned no valid status. The library sends the batch again later.`,{batchId:e.id}),new _.s(`transient`,`The custom transport returned no valid status.`);let{status:l}=s;if(l>=200&&l<300)this.accept(i,s.sampling,s.date);else throw this.reject(l,e.id,i,{retryAfterMs:C(s.retryAfterMs),maxBytes:C(s.maxBytes)})}},T=class{deps;installed=!1;keepaliveBytes=0;onVisibility=()=>{document.visibilityState===`hidden`&&this.flush(`hidden`)};onPageHide=()=>{this.flush(`pagehide`)};onFreeze=()=>{this.flush(`freeze`)};onOpenFinClose=()=>{this.flush(`openfin-close`)};constructor(e){this.deps=e}install(){if(this.installed||typeof addEventListener>`u`)return;this.installed=!0,typeof document<`u`&&(document.addEventListener(`visibilitychange`,this.onVisibility),document.addEventListener(`freeze`,this.onFreeze)),addEventListener(`pagehide`,this.onPageHide);let e=r.t()?.me;this.deps.diagnostics.guard(`openfin.unavailable`,`The library could not subscribe to close-requested.`,()=>{e?.on?.(`close-requested`,this.onOpenFinClose)})}uninstall(){if(!this.installed)return;this.installed=!1,typeof document<`u`&&(document.removeEventListener(`visibilitychange`,this.onVisibility),document.removeEventListener(`freeze`,this.onFreeze)),removeEventListener(`pagehide`,this.onPageHide);let e=r.t()?.me;this.deps.diagnostics.guard(`openfin.unavailable`,`The library could not unsubscribe from close-requested.`,()=>{e?.removeListener?.(`close-requested`,this.onOpenFinClose)})}flush(e){let{config:t,diagnostics:n}=this.deps;if(n.guard(`pipeline.crashed`,`The metric points before the exit flush failed.`,()=>{this.deps.beforeExit?.()}),e===`hidden`){this.flushAlive();return}if(t.transport){this.flushCustom(e,t.transportOnExit);return}let r=this.endpointUrl();if(r!==null){this.keepaliveBytes=0;for(let i of this.deps.drainForExit()){let a=_.t(i,t),o=a===`logs`?r.href:_.n(a,t);o?this.flushBatch(i,e,new URL(o)):n.count(`record.dropped_no_destination`)}}}flushBatch(t,n,r){let{config:i}=this.deps;if(t.records.length===0)return;let a=this.serialize(t,n);if(!a)return;if(o.t(a.body)>6e4){this.park(t);return}r.searchParams.set(e.Ht,t.id),r.searchParams.set(e.Ut,n);let s=r.toString(),c=this.deps.exitHeaders();if(c){this.keepaliveFetch(s,t,a.body,n,()=>{let n=new Headers(c);return n.set(e.lt,a.contentType),n.set(e.st,t.id),n});return}if(i.headers){this.park(t);return}let l=this.beacon(s,a.body);l!==`sent`&&(l===`refused`?this.park(t):this.keepaliveFetch(s,t,a.body,n,()=>new Headers({[e.lt]:e.B})))}flushAlive(){let{diagnostics:e}=this.deps,t=`The flush of the hidden document failed.`;e.guard(`pipeline.crashed`,t,()=>{Promise.resolve(this.deps.flushAlive()).catch(n=>{e.report(`pipeline.crashed`,t,void 0,n)})})}flushCustom(e,t){let{config:n,diagnostics:r}=this.deps;for(let i of this.deps.drainForExit()){let a=this.serialize(i,e);if(!a)continue;let o=x(i,a,_.t(i,n));(t===void 0||r.guard(`transport.http_error`,`The transportOnExit hook threw an error.`,()=>c.r(()=>t(o)))!==!0)&&this.park(i)}}park(e){let{config:t,diagnostics:n,onLoss:r}=this.deps;t.storage===`memory`||t.storage===`none`?r?.(`not_stored`,e.records,[e.id]):m.saveToEmergencyQueue(e,n,r)}serialize(e,t){let n=_.r(this.deps.config,e,this.deps.diagnostics,`The ${t} exit flush could not serialize its batch.`);return n||this.deps.onLoss?.(`unserializable`,e.records,[e.id]),n}endpointUrl(){let{endpoint:e}=this.deps.config;return e?this.deps.diagnostics.guard(`config.invalid`,`The exit flush cannot use the endpoint ${e}.`,()=>new URL(e))??null:null}beacon(e,t){return this.deps.diagnostics.guard(`transport.http_error`,`The sendBeacon call failed.`,()=>{let n=globalThis.navigator;return n?.sendBeacon?n.sendBeacon(e,new Blob([t],{type:`text/plain;charset=UTF-8`}))?`sent`:`refused`:`unavailable`})??`unavailable`}keepaliveFetch(e,t,n,r,i){let{config:a,diagnostics:s}=this.deps,c=()=>{this.park(t)},l=o.t(n);this.keepaliveBytes+l>6e4?c():(this.keepaliveBytes+=l,s.guard(`transport.http_error`,`The keepalive fetch failed.`,()=>(fetch(e,{method:`POST`,body:n,headers:i(),credentials:a.credentials,keepalive:!0}).catch(e=>{s.report(`transport.http_error`,`The exit flush failed.`,{reason:r},e),c()}),!0))!==!0&&c())}},E=new WeakMap;function D(e,t){let{headers:n}=t;if(!n)return;if(typeof n!=`function`)return n;let r=E.get(e);return r?.source===n&&r.endpoint===t.endpoint&&r.metricsEndpoint===t.metricsEndpoint&&r.tracesEndpoint===t.tracesEndpoint?r.headers:void 0}async function O(e,t,n){let{headers:r}=t;if(!r)return{};if(typeof r!=`function`)return r;let{endpoint:i,metricsEndpoint:a,tracesEndpoint:o}=t,s=await n.guardAsync(`transport.http_error`,`The headers() function threw an error.`,()=>Promise.resolve(r()));return s&&E.set(e,{source:r,endpoint:i,metricsEndpoint:a,tracesEndpoint:o,headers:s}),s??{}}function k(e){E.delete(e)}var A=`In a cross-origin iframe, the session cookie is a third-party cookie. The browser often blocks it. Forward the records to the platform document. As an alternative, issue the cookie with the Partitioned attribute.`,j=class extends b{async send(e,t){this.assertContext(e);let{config:n}=this,r=_.t(e,n),i=_.n(r,n);i?e.records.length!==0&&await this.post(e,r,i,t):this.diagnostics.count(`record.dropped_no_destination`)}lastHeaders(){return D(this,this.config)}async post(t,n,r,i){let a=this.serialize(t);if(!a)return;let o=await this.attempt(t,r,a,i);if(this.assertContext(t),this.rejectsCredentials(o.status)&&typeof this.config.headers==`function`&&(k(this),o=await this.attempt(t,r,a,i),this.assertContext(t)),o.ok){let{headers:t}=o;this.accept(n,t.get(e.ft),t.get(e.ut));return}let s=o.status,c=_.c(o.headers.get(e.dt)),l=s===413?await this.readMaxBytes(o):void 0;throw this.reject(s,t.id,n,{retryAfterMs:c,maxBytes:l,advice:A})}rejectsCredentials(e){return e===401||e===403}async attempt(t,n,r,i){let a=Date.now()+this.config.delivery.requestTimeoutMs,o=new Headers(await this.before(this.resolveHeaders(),a,n));o.set(e.lt,r.contentType),o.set(e.st,t.id),o.set(e.ot,String(t.attempts));let s=await this.before(this.encodeBody(r.body),a,n);this.assertContext(t),typeof s!=`string`&&o.set(e.ct,e.tt);let c=this.keepalive(s);return c&&i?.(),this.dispatch(n,o,s,a,c)}async before(e,t,r){try{return await n.n(this.untilCancelled(e),Math.max(0,t-Date.now()))}catch{throw this.cancellation.signal.aborted?new _.s(`permanent`,`The delivery context retired.`):this.timeout(r)}}timeout(e){let t=`The request took longer than ${String(this.config.delivery.requestTimeoutMs)} ms.`;return this.diagnostics.report(`transport.timeout`,t,{endpoint:e}),new _.s(`timeout`,t)}async encodeBody(e){let{config:t}=this;return t.compression!==`gzip`||o.t(e)<1024?e:await this.diagnostics.guardAsync(`transport.http_error`,`The library could not compress the payload.`,()=>d.a(e))??e}async dispatch(e,t,r,a,o){let{config:s}=this,l=new AbortController,u=()=>{l.abort()};this.cancellation.signal.addEventListener(`abort`,u,{once:!0}),this.cancellation.signal.aborted&&l.abort();let d=setTimeout(()=>{l.abort()},Math.max(0,a-Date.now()));n.r(d);try{return await c.r(()=>fetch(e,{method:`POST`,headers:t,body:r,credentials:s.credentials,signal:l.signal,cache:`no-store`,keepalive:o,priority:o?`auto`:s.delivery.priority}))}catch{throw this.cancellation.signal.aborted?new _.s(`permanent`,`The delivery context retired.`):l.signal.aborted?this.timeout(e):new _.s(i.r()?`transient`:`offline`,`A network error occurred.`)}finally{this.cancellation.signal.removeEventListener(`abort`,u),clearTimeout(d)}}keepalive(e){let t=globalThis.document?.visibilityState===`hidden`,n=typeof e==`string`?o.t(e):e.byteLength;return t&&n<=6e4}async readMaxBytes(e){return this.diagnostics.guardAsync(`transport.http_error`,`The library could not read the body of the 413 response.`,async()=>{let t=JSON.parse(await e.text());return typeof t.maxBytes==`number`?t.maxBytes:void 0})}async resolveHeaders(){return O(this,this.config,this.diagnostics)}},M=class{storage;transport;diagnostics;config;batchesPerDrain;onLoss;timer=null;attempt=0;draining=!1;stopped=!1;maxAttempts;onOnline=()=>{this.attempt=0,this.schedule(0)};constructor(e,t,n,r,i,a=()=>void 0){this.storage=e,this.transport=t,this.diagnostics=n,this.config=r,this.batchesPerDrain=i,this.onLoss=a,this.maxAttempts=p.storageLimits(r.retention).maxAttempts}start(){this.stopped=!1,typeof addEventListener<`u`&&addEventListener(`online`,this.onOnline),this.schedule(this.config.delivery.retryIdleDelayMs)}nudge(){this.draining||this.schedule(this.config.delivery.retryBaseDelayMs)}async storeFailed(e,t){let n=this.toStorable(e,t);for(let e of n)await this.bounded(this.storage.save(e));n.length>0&&this.nudge()}stop(){this.stopped=!0,typeof removeEventListener<`u`&&removeEventListener(`online`,this.onOnline),this.clearTimer()}async flush(){this.stopped=!1;try{await this.drain()}finally{this.stop()}}schedule(e){if(this.stopped)return;this.clearTimer();let t=setTimeout(()=>{this.drain()},e);this.timer=t,n.r(t)}bounded(t){return n.n(t,e.Cn)}clearTimer(){this.timer!==null&&(clearTimeout(this.timer),this.timer=null)}backoffMs(){let e=Math.min(this.config.delivery.retryBaseDelayMs*2**this.attempt,this.config.delivery.retryMaxDelayMs);return Math.random()*e}async drain(){if(!this.draining){this.draining=!0;try{let t=m.t(e.Y,this.config.persistence.namespace);await m.n(t,this.diagnostics,()=>this.drainLocked())!==!0&&this.schedule(this.config.delivery.retryIdleDelayMs)}finally{this.draining=!1}}}async drainLocked(){try{if(!i.r())return this.schedule(this.config.delivery.retryIdleDelayMs),!0;let e=await this.bounded(this.storage.take(this.batchesPerDrain??this.config.delivery.batchesPerDrain));if(e.length===0)return this.schedule(this.config.delivery.retryIdleDelayMs),!0;let t=new Set,n=0;for(let r of e){if(this.stopped)return!0;let e=_.t(r,this.config);if(t.has(e))continue;let i=await this.deliver(r);if(i===`stop`)return!0;i!==`next`&&(t.add(e),n=Math.max(n,i))}return t.size>0?this.schedule(n):this.schedule(e.length===(this.batchesPerDrain??this.config.delivery.batchesPerDrain)?0:this.config.delivery.retryIdleDelayMs),!0}catch(e){return this.diagnostics.report(`storage.degraded`,`The drain loop threw an error.`,void 0,e),this.attempt++,this.schedule(this.backoffMs()),!0}}async deliver(e){if(e.attempts>=this.maxAttempts)return this.diagnostics.report(`storage.dead_lettered`,`The library dropped a batch after ${e.attempts.toString()} attempts.`,{batchId:e.id,records:e.records.length}),this.onLoss(`max_attempts`,e.records,[e.id]),await this.bounded(this.storage.remove(e.id)),`next`;try{return await this.transport.send(e),await this.bounded(this.storage.remove(e.id)),this.attempt=0,`next`}catch(t){if(this.stopped)return`stop`;let n=t instanceof _.s?t:void 0;return n?.kind===`permanent`||n?.kind===`too_large`?(await this.replaceStored(e,t),`next`):n?.kind===`offline`?(this.schedule(this.config.delivery.retryIdleDelayMs),`stop`):n?.kind===`throttled`?(this.attempt++,n.retryAfterMs??this.backoffMs()):(await this.bounded(this.storage.bumpAttempts(e.id,e.attempts+1)),this.attempt++,n?.retryAfterMs??this.backoffMs())}}async replaceStored(e,t){let n=this.toStorable(e,t);await this.bounded(this.storage.remove(e.id));for(let e of n)await this.bounded(this.storage.save(e))}toStorable(e,t){let n=t instanceof _.s?t:void 0;if(n?.kind===`permanent`)return this.onLoss(`rejected`,e.records,[e.id]),[];if(n?.kind!==`too_large`)return[e];let r=l.a(e,this.diagnostics);return r?(this.diagnostics.report(`transport.batch_split`,`The server refused the batch because it is too large.`,{from:e.records.length,to:r[0].records.length,serverMaxBytes:n.maxBytes}),r):(this.diagnostics.report(`transport.dropped_permanent`,`One record is larger than the server limit. The library dropped it.`,{batchId:e.id,bodies:e.records.map(e=>e.body)}),this.onLoss(`rejected`,e.records,[e.id]),[])}},N=[`metrics`,`logs`,`traces`];function P(t){let n=t.attributes[e.g];return n===`metric`?`metrics`:n===`span`?`traces`:`logs`}var F=class{options;onFlush;pending=[];timer=null;constructor(e,t){this.options=e,this.onFlush=t}add(e){this.pending.push(e),this.pending.length>=this.options.batchSize?this.onFlush(this):this.arm()}take(){this.clearTimer();let e=this.pending;return this.pending=[],e}get size(){return this.pending.length}stop(){this.clearTimer()}arm(){if(this.timer!==null)return;let e=setTimeout(()=>{this.timer=null,this.onFlush(this)},this.options.flushIntervalMs);this.timer=e,n.r(e)}clearTimer(){this.timer!==null&&(clearTimeout(this.timer),this.timer=null)}},I=class{transport;storage;retry;diagnostics;routingContextId;policy;onLoss;clockOffset;streams;unconfirmed=new Map;queue=[];open=new Set;ceiling=new u.t;inFlight=0;pumpScheduled=!1;stopped=!1;held=new Map;heldBytes=0;persisting=!1;release(e){for(let t of e)this.heldBytes-=this.held.get(t)??0,this.held.delete(t)}evict(){let e=this.queue.shift();if(e)return this.open.delete(e),this.unconfirmed.delete(e.batch.id),this.release(e.batch.records),e.resolve(),this.onLoss(`buffer_full`,e.batch.records,[e.batch.id]),!0;for(let e of Object.values(this.streams)){let t=e.take();if(t.length)return this.release(t),this.onLoss(`buffer_full`,t),!0}return!1}admit(e){if(!this.policy)return!0;let{maxPendingRecords:t,maxPendingBytes:n,overflow:r}=this.policy.buffering,i;try{i=o.t(JSON.stringify(e))}catch{return this.onLoss(`unserializable`,[e]),!1}let a=()=>!!(t&&this.held.size>=t||n&&this.heldBytes+i>n),s=!n||i<=n;for(;s&&a()&&r===`drop-oldest`&&this.evict(););if(a()){if(r===`persist`&&!this.persisting){this.persisting=!0;let t=this.toBatch([e]);this.diagnostics.guardAsync(`storage.degraded`,`Could not persist an overflow record.`,async()=>{try{await this.storage.save(t),this.retry.nudge()}finally{this.persisting=!1}})}else this.onLoss(`buffer_full`,[e]);return!1}return this.held.set(e,i),this.heldBytes+=i,!0}constructor(e,t,n,r,i,a,o,s=()=>void 0,c=()=>void 0){this.transport=e,this.storage=t,this.retry=n,this.diagnostics=r,this.routingContextId=a,this.policy=o,this.onLoss=s,this.clockOffset=c;let l=e=>{this.claim(e)};this.streams={logs:new F(i.logs,l),metrics:new F(i.metrics,l),traces:new F(i.traces,l)}}push(e){if(this.stopped)return;e.observedTimeUnixNano=t.r();let n={...e};this.admit(n)&&this.route(n)}drainForExit(){let e=[...this.unconfirmed.values()].flatMap(e=>e.records);return this.unconfirmed.clear(),this.held.clear(),this.heldBytes=0,N.map(t=>this.toBatch([...e.filter(e=>P(e)===t),...this.streams[t].take()])).filter(e=>e!==null)}async flushPending(){if(!this.stopped)for(let e of N)this.claim(this.streams[e]);await Promise.all([...this.open].map(e=>e.done))}counts(){let e=e=>{let t=0;for(let n of e)t+=n.batch.records.length;return t},t=e(this.queue);return{pending:N.reduce((e,t)=>e+this.streams[t].size,0)+t,inFlight:e(this.open)-t}}destroy(){this.stopped=!0,this.held.clear(),this.heldBytes=0;for(let e of N)this.streams[e].stop();this.queue.length=0;for(let e of this.open)e.resolve();this.open.clear()}toBatch(e){return e.length===0?null:{id:s.i(this.diagnostics),records:e,createdAt:Date.now(),attempts:0,routingContextId:this.routingContextId?.(),persistenceNamespace:this.policy?.persistence.namespace}}route(t){try{let n=P(t),r=this.streams[n];if(n===`logs`&&!this.ceiling.allow(t,this.policy?.capturePolicy.errorCeiling,this.policy?.capturePolicy.windowMs,this.policy?.sampling.alwaysSampleFrom)){this.release([t]),this.diagnostics.count(`record.dropped_by_ceiling`);return}let i=this.clockOffset();i!==void 0&&n!==`metrics`&&(t.attributes={...t.attributes,[e.l]:i}),r.add(t)}catch(e){this.diagnostics.report(`pipeline.crashed`,`The pipeline dropped a record before it reached a stream.`,void 0,e)}}claim(e){this.enqueue(this.toBatch(e.take()))}enqueue(e){if(!e)return;let t,n={batch:e,done:new Promise(e=>{t=e}),resolve:t};this.unconfirmed.set(e.id,e),this.open.add(n),this.queue.push(n),!this.pumpScheduled&&(this.pumpScheduled=!0,queueMicrotask(()=>{this.pumpScheduled=!1,this.pump()}))}pump(){if(!this.stopped)for(;this.inFlight<(this.policy?.delivery.maxConcurrentRequests??2);){let e=this.queue.shift();if(!e)return;this.inFlight++,this.run(e)}}async run(e){let{batch:t}=e;try{await this.dispatch(t)}catch(e){this.diagnostics.report(`pipeline.crashed`,`A dispatch rejected its promise. This must not occur.`,{batchId:t.id},e)}finally{this.release(t.records),this.inFlight--,this.open.delete(e),e.resolve(),this.pump()}}async dispatch(e){try{let t=this.transport.throttledForMs(e);if(t>0){await this.store(e),this.diagnostics.report(`transport.throttled`,`The server throttles requests. The pipeline stored the batch and did not send it.`,{batchId:e.id,records:e.records.length,throttledMs:t});return}try{await this.transport.send(e,()=>{this.unconfirmed.delete(e.id)})}catch(t){if(this.stopped)return;await this.storeFailed({...e,attempts:e.attempts+1},t),this.diagnostics.report(`transport.http_error`,`The send failed. The pipeline stored the batch for a retry.`,{batchId:e.id,records:e.records.length},t)}}finally{this.unconfirmed.delete(e.id)}}async storeFailed(e,t){await this.diagnostics.guardAsync(`storage.degraded`,`The library could not store an undelivered batch.`,async()=>{await this.retry.storeFailed(e,t)})}async store(t){await this.diagnostics.guardAsync(`storage.degraded`,`The library could not store an undelivered batch.`,async()=>{await n.n(this.storage.save(t),e.Cn),this.retry.nudge()})}},L=class e{storage;retry;pipeline;exitFlush;diagnostics;transport;retired=!1;emergencyImport=Promise.resolve();constructor(e,t,n,r,i,a){this.storage=e,this.retry=t,this.pipeline=n,this.exitFlush=r,this.diagnostics=i,this.transport=a}static async create(t){let{config:n,diagnostics:r}=t,i=t.storage??await h.createStorage(n.storage,h.storageName(n.persistence.namespace),p.storageLimits(n.retention),r,t.onGap,n.persistence.namespace);t.onStorage?.(i),n.persistence.requestPersistent&&(i.name===`indexeddb`||i.name===`localstorage`)&&(t.onPersistence?.(`pending`),v(r).then(t.onPersistence));let a=new g.ContextStorage(i,n.securityContext,n.persistence.namespace),o=e=>{let i=f.n(e,r);i&&f.t(t.remote,n,i)},s,c=e=>{s=e},{onLoss:l}=t,u=!n.transport&&n.transportWorker?await r.guardAsync(`transport.http_error`,`The transport worker module did not load. The library uses HTTP.`,async()=>(await Promise.resolve().then(()=>require("./worker-transport-Dj2yCQN5.cjs"))).createWorkerTransport(n,r,o,l,c)):void 0,d=n.transport!==void 0||u!==void 0?void 0:new j(n,r,o,l,c),m=u?.transport??d??new w(n,r,o,l,c),_=new M(a,m,r,n,void 0,l),{batching:y}=n,b=new I(m,a,_,r,{logs:{flushIntervalMs:y.logFlushIntervalMs,batchSize:y.logBatchSize},metrics:{flushIntervalMs:y.metricFlushIntervalMs,batchSize:y.metricBatchSize},traces:{flushIntervalMs:y.logFlushIntervalMs,batchSize:y.logBatchSize}},()=>n.securityContext.id||void 0,n,l,()=>n.metadata.clockOffset?s:void 0),x=new T({config:n,diagnostics:r,drainForExit:()=>b.drainForExit(),flushAlive:()=>b.flushPending(),exitHeaders:()=>u?u.exitHeaders():d?.lastHeaders(),onLoss:l,beforeExit:t.beforeExit}),S=!1;try{x.install(),_.start(),S=!0}finally{S||(x.uninstall(),_.stop())}let C=new e(a,_,b,x,r,m);return C.emergencyImport=C.importEmergency(),C}push(e){this.pipeline.push(e)}async flush(){await this.pipeline.flushPending()}async clearPersisted(e,t){e===`namespace`?await this.storage.clearNamespace():await this.storage.clear(),m.clearEmergencyContext(t,this.diagnostics,this.storage.namespace,e===`namespace`)}async queueDepth(){return await this.diagnostics.guardAsync(`storage.degraded`,`The library could not count the batches in storage.`,()=>this.storage.count())??0}stats(){return{...this.pipeline.counts(),lastSendAt:this.transport.lastSendAt()}}async destroy(){await this.diagnostics.guardAsync(`pipeline.crashed`,`The flush before shutdown failed.`,()=>this.flush()),this.exitFlush.flush(`shutdown`),this.exitFlush.uninstall(),this.retry.stop(),this.transport.stop(),this.pipeline.destroy(),await this.storage.close()}async retire(e,t,r){if(this.retired=!0,this.exitFlush.uninstall(),this.retry.stop(),e===`flush`)try{await n.n(Promise.all([this.flush(),this.retry.flush()]),t)}catch(e){this.diagnostics.report(`transport.timeout`,`The flush of the old security context did not complete before its time limit.`,void 0,e)}this.retry.stop(),this.transport.stop();let i=this.pipeline.drainForExit(),a=i.flatMap(e=>e.records);this.pipeline.destroy(),await this.emergencyImport;let o=await this.storage.take(2**53-1);if(e===`retain`)for(let e of i)await this.storage.save({...e,routingContextId:r,persistenceNamespace:this.storage.namespace});let s=e===`discard`||e===`flush`;return await this.storage.retire(s),s&&m.clearEmergencyContext(r,this.diagnostics,this.storage.namespace),{buffered:a,stored:o}}async adopt(e,t){for(let n of e)await this.storage.save({...n,attempts:0,routingContextId:t,persistenceNamespace:this.storage.namespace});e.length>0&&this.retry.nudge()}async importEmergency(){let e=await this.diagnostics.guardAsync(`storage.degraded`,`The emergency import failed.`,()=>m.drainEmergencyQueue(this.storage,this.diagnostics,e=>this.storage.accepts(e),this.storage.namespace));!this.retired&&e!==void 0&&e>0&&this.retry.nudge()}};exports.Sender=L,exports.a=b,exports.i=O,exports.n=j,exports.r=k,exports.t=A;
|
|
2
|
-
//# sourceMappingURL=sender-
|
|
1
|
+
const e=require("./constants-DqKJH_MP.cjs"),t=require("./storage-BA9RqRO-.cjs"),n=require("./emergency-queue-CNTRui5t.cjs"),r=require("./factory-CJXVYp0R.cjs"),i=require("./context-storage-BjzeBSxH.cjs"),a=require("./deadline-XSnm95pg.cjs"),o=require("./library-request-1BX_UlaX.cjs"),s=require("./openfin-DtH2f7zX.cjs"),c=require("./sanitize-BAWzkZt0.cjs"),l=require("./library-console-D2GY9Or6.cjs"),u=require("./select-ZF4by-lF.cjs"),d=require("./platform-C2Ez5kDc.cjs"),f=require("./otlp-BDvFrLnc.cjs"),p=require("./batch-C8OcWR2L.cjs"),m=require("./log-record-i9zOTkpQ.cjs"),h=require("./identity-Cxgj6pZX.cjs"),g=require("./sampling-Ckh2yW9k.cjs"),_=require("./remote-rules-vzvk7aKf.cjs");async function v(e){let t=globalThis.navigator?.storage;return typeof t?.persist==`function`?await e.guardAsync(`storage.unavailable`,`The browser rejected the request for persistent storage.`,()=>t.persist())===!0?`granted`:`denied`:`unsupported`}function y(e){let t=typeof e==`string`?Date.parse(e):NaN;return Number.isNaN(t)?void 0:Math.round(t+500-Date.now())}var b=class{config;diagnostics;onSampling;onLoss;onClock;cancellation=new AbortController;stop(){this.cancellation.abort()}assertContext(e){if(this.cancellation.signal.aborted||this.config.securityContext.isolation&&this.config.securityContext.id&&e.routingContextId!==this.config.securityContext.id)throw this.diagnostics.count(`security.context_mismatch`),new u.s(`permanent`,`The delivery context is inactive or does not match the batch.`)}async untilCancelled(e){if(this.cancellation.signal.aborted)throw new u.s(`permanent`,`The delivery context retired.`);let t,n=new Promise((e,n)=>{t=()=>{n(new u.s(`permanent`,`The delivery context retired.`))},this.cancellation.signal.addEventListener(`abort`,t,{once:!0})});try{return await Promise.race([e,n])}finally{this.cancellation.signal.removeEventListener(`abort`,t)}}throttledUntil={logs:0,metrics:0,traces:0};acceptedAt=null;constructor(e,t,n=()=>void 0,r=()=>void 0,i=()=>void 0){this.config=e,this.diagnostics=t,this.onSampling=n,this.onLoss=r,this.onClock=i}throttledForMs(e){return Math.max(0,this.throttledUntil[u.t(e,this.config)]-Date.now())}lastSendAt(){return this.acceptedAt}serialize(e){let t=u.r(this.config,e,this.diagnostics,`The serializer threw an error. The library dropped the batch.`);return t||this.onLoss(`unserializable`,e.records,[e.id]),t}accept(e,t,n){this.throttledUntil[e]=0,this.acceptedAt=Date.now(),this.config.sampling.remote&&t!=null&&this.onSampling(t);let r=y(n);r!==void 0&&this.onClock(r)}reject(e,t,n,r){let i=String(e);if(e===401||e===403){let t=r.advice===void 0?``:` ${r.advice}`;return this.diagnostics.report(`transport.rejected_credentials`,`The server returned ${i}.${t}`,{status:e,endpoint:u.n(n,this.config)}),new u.s(`permanent`,`The server rejected the batch with ${i}.`,e)}if(e===413)return new u.s(`too_large`,`The payload is too large.`,e,void 0,r.maxBytes);if(e===429||e===503){let t=e===429,i=r.retryAfterMs===void 0?void 0:Math.min(r.retryAfterMs,this.config.delivery.retryMaxDelayMs);return this.throttledUntil[n]=Date.now()+(i??this.config.delivery.retryBaseDelayMs),t&&this.diagnostics.report(`transport.throttled`,`The server throttles the requests.`,{retryAfterMs:i}),new u.s(`throttled`,t?`The server throttles the requests.`:`The service is not available.`,e,i)}return e===408||e>=500?new u.s(`transient`,`The server returned the error ${i}.`,e):(this.diagnostics.report(`transport.dropped_permanent`,`The server rejected the batch with ${i}. The library dropped it.`,{batchId:t,status:e}),new u.s(`permanent`,`The server rejected the batch with ${i}.`,e))}};function x(e,t,n){return{kind:n,body:t.body,contentType:t.contentType,batchId:e.id,attempt:e.attempts,records:e.records,routingContextId:e.routingContextId}}function S(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`status`);return typeof t==`number`&&Number.isInteger(t)&&t>=100&&t<=599}function C(e){return typeof e==`number`&&Number.isFinite(e)?Math.max(0,e):void 0}var w=class extends b{async send(e){this.assertContext(e);let{transport:t}=this.config;if(!t||e.records.length===0)return;let n=this.serialize(e);if(!n)return;let r=u.t(e,this.config),i=x(e,n,r);i.signal=this.cancellation.signal;let s;try{s=await a.n(this.untilCancelled(o.i(()=>o.r(()=>l.n(()=>t(i))))),this.config.delivery.requestTimeoutMs)}catch(e){let t=e instanceof a.t?e:void 0,n=t?`timeout`:`transient`,r=t?.message??`The custom transport failed.`;throw new u.s(n,r,void 0,void 0,void 0,e)}if(this.assertContext(e),!S(s))throw this.diagnostics.report(`transport.http_error`,`The custom transport returned no valid status. The library sends the batch again later.`,{batchId:e.id}),new u.s(`transient`,`The custom transport returned no valid status.`);let{status:c}=s;if(c>=200&&c<300)this.accept(r,s.sampling,s.date);else throw this.reject(c,e.id,r,{retryAfterMs:C(s.retryAfterMs),maxBytes:C(s.maxBytes)})}},T=class{deps;installed=!1;keepaliveBytes=0;onVisibility=()=>{document.visibilityState===`hidden`&&this.flush(`hidden`)};onPageHide=()=>{this.flush(`pagehide`)};onFreeze=()=>{this.flush(`freeze`)};onOpenFinClose=()=>{this.flush(`openfin-close`)};constructor(e){this.deps=e}install(){if(this.installed||typeof addEventListener>`u`)return;this.installed=!0,typeof document<`u`&&(document.addEventListener(`visibilitychange`,this.onVisibility),document.addEventListener(`freeze`,this.onFreeze)),addEventListener(`pagehide`,this.onPageHide);let e=s.t()?.me;this.deps.diagnostics.guard(`openfin.unavailable`,`The library could not subscribe to close-requested.`,()=>{e?.on?.(`close-requested`,this.onOpenFinClose)})}uninstall(){if(!this.installed)return;this.installed=!1,typeof document<`u`&&(document.removeEventListener(`visibilitychange`,this.onVisibility),document.removeEventListener(`freeze`,this.onFreeze)),removeEventListener(`pagehide`,this.onPageHide);let e=s.t()?.me;this.deps.diagnostics.guard(`openfin.unavailable`,`The library could not unsubscribe from close-requested.`,()=>{e?.removeListener?.(`close-requested`,this.onOpenFinClose)})}flush(e){let{config:t,diagnostics:n}=this.deps;if(n.guard(`pipeline.crashed`,`The metric points before the exit flush failed.`,()=>{this.deps.beforeExit?.()}),e===`hidden`){this.flushAlive();return}if(t.transport){this.flushCustom(e,t.transportOnExit);return}let r=this.endpointUrl();if(r!==null){this.keepaliveBytes=0;for(let i of this.deps.drainForExit()){let a=u.t(i,t),o=a===`logs`?r.href:u.n(a,t);o?this.flushBatch(i,e,new URL(o)):n.count(`record.dropped_no_destination`)}}}flushBatch(t,n,r){let{config:i}=this.deps;if(t.records.length===0)return;let a=this.serialize(t,n);if(!a)return;if(c.t(a.body)>6e4){this.park(t);return}r.searchParams.set(e.Ht,t.id),r.searchParams.set(e.Ut,n);let o=r.toString(),s=this.deps.exitHeaders();if(s){this.keepaliveFetch(o,t,a.body,n,()=>{let n=new Headers(s);return n.set(e.lt,a.contentType),n.set(e.st,t.id),n});return}if(i.headers){this.park(t);return}let l=this.beacon(o,a.body);l!==`sent`&&(l===`refused`?this.park(t):this.keepaliveFetch(o,t,a.body,n,()=>new Headers({[e.lt]:e.B})))}flushAlive(){let{diagnostics:e}=this.deps,t=`The flush of the hidden document failed.`;e.guard(`pipeline.crashed`,t,()=>{Promise.resolve(this.deps.flushAlive()).catch(n=>{e.report(`pipeline.crashed`,t,void 0,n)})})}flushCustom(e,t){let{config:n,diagnostics:r}=this.deps;for(let i of this.deps.drainForExit()){let a=this.serialize(i,e);if(!a)continue;let s=x(i,a,u.t(i,n));(t===void 0||r.guard(`transport.http_error`,`The transportOnExit hook threw an error.`,()=>o.r(()=>t(s)))!==!0)&&this.park(i)}}park(e){let{config:t,diagnostics:r,onLoss:i}=this.deps;t.storage===`memory`||t.storage===`none`?i?.(`not_stored`,e.records,[e.id]):n.saveToEmergencyQueue(e,r,i)}serialize(e,t){let n=u.r(this.deps.config,e,this.deps.diagnostics,`The ${t} exit flush could not serialize its batch.`);return n||this.deps.onLoss?.(`unserializable`,e.records,[e.id]),n}endpointUrl(){let{endpoint:e}=this.deps.config;return e?this.deps.diagnostics.guard(`config.invalid`,`The exit flush cannot use the endpoint ${e}.`,()=>new URL(e))??null:null}beacon(e,t){return this.deps.diagnostics.guard(`transport.http_error`,`The sendBeacon call failed.`,()=>{let n=globalThis.navigator;return n?.sendBeacon?n.sendBeacon(e,new Blob([t],{type:`text/plain;charset=UTF-8`}))?`sent`:`refused`:`unavailable`})??`unavailable`}keepaliveFetch(e,t,n,r,i){let{config:a,diagnostics:o}=this.deps,s=()=>{this.park(t)},l=c.t(n);this.keepaliveBytes+l>6e4?s():(this.keepaliveBytes+=l,o.guard(`transport.http_error`,`The keepalive fetch failed.`,()=>(fetch(e,{method:`POST`,body:n,headers:i(),credentials:a.credentials,keepalive:!0}).catch(e=>{o.report(`transport.http_error`,`The exit flush failed.`,{reason:r},e),s()}),!0))!==!0&&s())}},E=new WeakMap;function D(e,t){let{headers:n}=t;if(!n)return;if(typeof n!=`function`)return n;let r=E.get(e);return r?.source===n&&r.endpoint===t.endpoint&&r.metricsEndpoint===t.metricsEndpoint&&r.tracesEndpoint===t.tracesEndpoint?r.headers:void 0}async function O(e,t,n){let{headers:r}=t;if(!r)return{};if(typeof r!=`function`)return r;let{endpoint:i,metricsEndpoint:a,tracesEndpoint:o}=t,s=await n.guardAsync(`transport.http_error`,`The headers() function threw an error.`,()=>Promise.resolve(r()));return s&&E.set(e,{source:r,endpoint:i,metricsEndpoint:a,tracesEndpoint:o,headers:s}),s??{}}function k(e){E.delete(e)}var A=`In a cross-origin iframe, the session cookie is a third-party cookie. The browser often blocks it. Forward the records to the platform document. As an alternative, issue the cookie with the Partitioned attribute.`,j=class extends b{async send(e,t){this.assertContext(e);let{config:n}=this,r=u.t(e,n),i=u.n(r,n);i?e.records.length!==0&&await this.post(e,r,i,t):this.diagnostics.count(`record.dropped_no_destination`)}lastHeaders(){return D(this,this.config)}async post(t,n,r,i){let a=this.serialize(t);if(!a)return;let o=await this.attempt(t,r,a,i);if(this.assertContext(t),this.rejectsCredentials(o.status)&&typeof this.config.headers==`function`&&(k(this),o=await this.attempt(t,r,a,i),this.assertContext(t)),o.ok){let{headers:t}=o;this.accept(n,t.get(e.ft),t.get(e.ut));return}let s=o.status,c=u.c(o.headers.get(e.dt)),l=s===413?await this.readMaxBytes(o):void 0;throw this.reject(s,t.id,n,{retryAfterMs:c,maxBytes:l,advice:A})}rejectsCredentials(e){return e===401||e===403}async attempt(t,n,r,i){let a=Date.now()+this.config.delivery.requestTimeoutMs,o=new Headers(await this.before(this.resolveHeaders(),a,n));o.set(e.lt,r.contentType),o.set(e.st,t.id),o.set(e.ot,String(t.attempts));let s=await this.before(this.encodeBody(r.body),a,n);this.assertContext(t),typeof s!=`string`&&o.set(e.ct,e.tt);let c=this.keepalive(s);return c&&i?.(),this.dispatch(n,o,s,a,c)}async before(e,t,n){try{return await a.n(this.untilCancelled(e),Math.max(0,t-Date.now()))}catch{throw this.cancellation.signal.aborted?new u.s(`permanent`,`The delivery context retired.`):this.timeout(n)}}timeout(e){let t=`The request took longer than ${String(this.config.delivery.requestTimeoutMs)} ms.`;return this.diagnostics.report(`transport.timeout`,t,{endpoint:e}),new u.s(`timeout`,t)}async encodeBody(e){let{config:t}=this;return t.compression!==`gzip`||c.t(e)<1024?e:await this.diagnostics.guardAsync(`transport.http_error`,`The library could not compress the payload.`,()=>f.a(e))??e}async dispatch(e,t,n,r,i){let{config:s}=this,c=new AbortController,l=()=>{c.abort()};this.cancellation.signal.addEventListener(`abort`,l,{once:!0}),this.cancellation.signal.aborted&&c.abort();let f=setTimeout(()=>{c.abort()},Math.max(0,r-Date.now()));a.r(f);try{return await o.r(()=>fetch(e,{method:`POST`,headers:t,body:n,credentials:s.credentials,signal:c.signal,cache:`no-store`,keepalive:i,priority:i?`auto`:s.delivery.priority}))}catch{throw this.cancellation.signal.aborted?new u.s(`permanent`,`The delivery context retired.`):c.signal.aborted?this.timeout(e):new u.s(d.r()?`transient`:`offline`,`A network error occurred.`)}finally{this.cancellation.signal.removeEventListener(`abort`,l),clearTimeout(f)}}keepalive(e){let t=globalThis.document?.visibilityState===`hidden`,n=typeof e==`string`?c.t(e):e.byteLength;return t&&n<=6e4}async readMaxBytes(e){return this.diagnostics.guardAsync(`transport.http_error`,`The library could not read the body of the 413 response.`,async()=>{let t=JSON.parse(await e.text());return typeof t.maxBytes==`number`?t.maxBytes:void 0})}async resolveHeaders(){return O(this,this.config,this.diagnostics)}},M=class{storage;transport;diagnostics;config;batchesPerDrain;onLoss;timer=null;attempt=0;draining=!1;stopped=!1;maxAttempts;onOnline=()=>{this.attempt=0,this.schedule(0)};constructor(e,n,r,i,a,o=()=>void 0){this.storage=e,this.transport=n,this.diagnostics=r,this.config=i,this.batchesPerDrain=a,this.onLoss=o,this.maxAttempts=t.storageLimits(i.retention).maxAttempts}start(){this.stopped=!1,typeof addEventListener<`u`&&addEventListener(`online`,this.onOnline),this.schedule(this.config.delivery.retryIdleDelayMs)}nudge(){this.draining||this.schedule(this.config.delivery.retryBaseDelayMs)}async storeFailed(e,t){let n=this.toStorable(e,t);for(let e of n)await this.bounded(this.storage.save(e));n.length>0&&this.nudge()}stop(){this.stopped=!0,typeof removeEventListener<`u`&&removeEventListener(`online`,this.onOnline),this.clearTimer()}async flush(){this.stopped=!1;try{await this.drain()}finally{this.stop()}}schedule(e){if(this.stopped)return;this.clearTimer();let t=setTimeout(()=>{this.drain()},e);this.timer=t,a.r(t)}bounded(t){return a.n(t,e.Cn)}clearTimer(){this.timer!==null&&(clearTimeout(this.timer),this.timer=null)}backoffMs(){let e=Math.min(this.config.delivery.retryBaseDelayMs*2**this.attempt,this.config.delivery.retryMaxDelayMs);return Math.random()*e}async drain(){if(!this.draining){this.draining=!0;try{let t=n.t(e.Y,this.config.persistence.namespace);await n.n(t,this.diagnostics,()=>this.drainLocked())!==!0&&this.schedule(this.config.delivery.retryIdleDelayMs)}finally{this.draining=!1}}}async drainLocked(){try{if(!d.r())return this.schedule(this.config.delivery.retryIdleDelayMs),!0;let e=await this.bounded(this.storage.take(this.batchesPerDrain??this.config.delivery.batchesPerDrain));if(e.length===0)return this.schedule(this.config.delivery.retryIdleDelayMs),!0;let t=new Set,n=0;for(let r of e){if(this.stopped)return!0;let e=u.t(r,this.config);if(t.has(e))continue;let i=await this.deliver(r);if(i===`stop`)return!0;i!==`next`&&(t.add(e),n=Math.max(n,i))}return t.size>0?this.schedule(n):this.schedule(e.length===(this.batchesPerDrain??this.config.delivery.batchesPerDrain)?0:this.config.delivery.retryIdleDelayMs),!0}catch(e){return this.diagnostics.report(`storage.degraded`,`The drain loop threw an error.`,void 0,e),this.attempt++,this.schedule(this.backoffMs()),!0}}async deliver(e){if(e.attempts>=this.maxAttempts)return this.diagnostics.report(`storage.dead_lettered`,`The library dropped a batch after ${e.attempts.toString()} attempts.`,{batchId:e.id,records:e.records.length}),this.onLoss(`max_attempts`,e.records,[e.id]),await this.bounded(this.storage.remove(e.id)),`next`;try{return await this.transport.send(e),await this.bounded(this.storage.remove(e.id)),this.attempt=0,`next`}catch(t){if(this.stopped)return`stop`;let n=t instanceof u.s?t:void 0;return n?.kind===`permanent`||n?.kind===`too_large`?(await this.replaceStored(e,t),`next`):n?.kind===`offline`?(this.schedule(this.config.delivery.retryIdleDelayMs),`stop`):n?.kind===`throttled`?(this.attempt++,n.retryAfterMs??this.backoffMs()):(await this.bounded(this.storage.bumpAttempts(e.id,e.attempts+1)),this.attempt++,n?.retryAfterMs??this.backoffMs())}}async replaceStored(e,t){let n=this.toStorable(e,t);await this.bounded(this.storage.remove(e.id));for(let e of n)await this.bounded(this.storage.save(e))}toStorable(e,t){let n=t instanceof u.s?t:void 0;if(n?.kind===`permanent`)return this.onLoss(`rejected`,e.records,[e.id]),[];if(n?.kind!==`too_large`)return[e];let r=p.a(e,this.diagnostics);return r?(this.diagnostics.report(`transport.batch_split`,`The server refused the batch because it is too large.`,{from:e.records.length,to:r[0].records.length,serverMaxBytes:n.maxBytes}),r):(this.diagnostics.report(`transport.dropped_permanent`,`One record is larger than the server limit. The library dropped it.`,{batchId:e.id,bodies:e.records.map(e=>e.body)}),this.onLoss(`rejected`,e.records,[e.id]),[])}},N=[`metrics`,`logs`,`traces`];function P(t){let n=t.attributes[e.g];return n===`metric`?`metrics`:n===`span`?`traces`:`logs`}var F=class{options;onFlush;pending=[];timer=null;constructor(e,t){this.options=e,this.onFlush=t}add(e){this.pending.push(e),this.pending.length>=this.options.batchSize?this.onFlush(this):this.arm()}take(){this.clearTimer();let e=this.pending;return this.pending=[],e}get size(){return this.pending.length}stop(){this.clearTimer()}arm(){if(this.timer!==null)return;let e=setTimeout(()=>{this.timer=null,this.onFlush(this)},this.options.flushIntervalMs);this.timer=e,a.r(e)}clearTimer(){this.timer!==null&&(clearTimeout(this.timer),this.timer=null)}},I=class{transport;storage;retry;diagnostics;routingContextId;policy;onLoss;clockOffset;streams;unconfirmed=new Map;queue=[];open=new Set;ceiling=new g.t;inFlight=0;pumpScheduled=!1;stopped=!1;held=new Map;heldBytes=0;persisting=!1;release(e){for(let t of e)this.heldBytes-=this.held.get(t)??0,this.held.delete(t)}evict(){let e=this.queue.shift();if(e)return this.open.delete(e),this.unconfirmed.delete(e.batch.id),this.release(e.batch.records),e.resolve(),this.onLoss(`buffer_full`,e.batch.records,[e.batch.id]),!0;for(let e of Object.values(this.streams)){let t=e.take();if(t.length)return this.release(t),this.onLoss(`buffer_full`,t),!0}return!1}admit(e){if(!this.policy)return!0;let{maxPendingRecords:t,maxPendingBytes:n,overflow:r}=this.policy.buffering,i;try{i=c.t(JSON.stringify(e))}catch{return this.onLoss(`unserializable`,[e]),!1}let a=()=>!!(t&&this.held.size>=t||n&&this.heldBytes+i>n),o=!n||i<=n;for(;o&&a()&&r===`drop-oldest`&&this.evict(););if(a()){if(r===`persist`&&!this.persisting){this.persisting=!0;let t=this.toBatch([e]);this.diagnostics.guardAsync(`storage.degraded`,`Could not persist an overflow record.`,async()=>{try{await this.storage.save(t),this.retry.nudge()}finally{this.persisting=!1}})}else this.onLoss(`buffer_full`,[e]);return!1}return this.held.set(e,i),this.heldBytes+=i,!0}constructor(e,t,n,r,i,a,o,s=()=>void 0,c=()=>void 0){this.transport=e,this.storage=t,this.retry=n,this.diagnostics=r,this.routingContextId=a,this.policy=o,this.onLoss=s,this.clockOffset=c;let l=e=>{this.claim(e)};this.streams={logs:new F(i.logs,l),metrics:new F(i.metrics,l),traces:new F(i.traces,l)}}push(e){if(this.stopped)return;e.observedTimeUnixNano=m.r();let t={...e};this.admit(t)&&this.route(t)}drainForExit(){let e=[...this.unconfirmed.values()].flatMap(e=>e.records);return this.unconfirmed.clear(),this.held.clear(),this.heldBytes=0,N.map(t=>this.toBatch([...e.filter(e=>P(e)===t),...this.streams[t].take()])).filter(e=>e!==null)}async flushPending(){if(!this.stopped)for(let e of N)this.claim(this.streams[e]);await Promise.all([...this.open].map(e=>e.done))}counts(){let e=e=>{let t=0;for(let n of e)t+=n.batch.records.length;return t},t=e(this.queue);return{pending:N.reduce((e,t)=>e+this.streams[t].size,0)+t,inFlight:e(this.open)-t}}destroy(){this.stopped=!0,this.held.clear(),this.heldBytes=0;for(let e of N)this.streams[e].stop();this.queue.length=0;for(let e of this.open)e.resolve();this.open.clear()}toBatch(e){return e.length===0?null:{id:h.i(this.diagnostics),records:e,createdAt:Date.now(),attempts:0,routingContextId:this.routingContextId?.(),persistenceNamespace:this.policy?.persistence.namespace}}route(t){try{let n=P(t),r=this.streams[n];if(n===`logs`&&!this.ceiling.allow(t,this.policy?.capturePolicy.errorCeiling,this.policy?.capturePolicy.windowMs,this.policy?.sampling.alwaysSampleFrom)){this.release([t]),this.diagnostics.count(`record.dropped_by_ceiling`);return}let i=this.clockOffset();i!==void 0&&n!==`metrics`&&(t.attributes={...t.attributes,[e.l]:i}),r.add(t)}catch(e){this.diagnostics.report(`pipeline.crashed`,`The pipeline dropped a record before it reached a stream.`,void 0,e)}}claim(e){this.enqueue(this.toBatch(e.take()))}enqueue(e){if(!e)return;let t,n={batch:e,done:new Promise(e=>{t=e}),resolve:t};this.unconfirmed.set(e.id,e),this.open.add(n),this.queue.push(n),this.pumpScheduled||(this.pumpScheduled=!0,queueMicrotask(()=>{this.pumpScheduled=!1,this.pump()}))}pump(){if(!this.stopped)for(;this.inFlight<(this.policy?.delivery.maxConcurrentRequests??2);){let e=this.queue.shift();if(!e)return;this.inFlight++,this.run(e)}}async run(e){let{batch:t}=e;try{await this.dispatch(t)}catch(e){this.diagnostics.report(`pipeline.crashed`,`A dispatch rejected its promise. This must not occur.`,{batchId:t.id},e)}finally{this.release(t.records),this.inFlight--,this.open.delete(e),e.resolve(),this.pump()}}async dispatch(e){try{let t=this.transport.throttledForMs(e);if(t>0){await this.store(e),this.diagnostics.report(`transport.throttled`,`The server throttles requests. The pipeline stored the batch and did not send it.`,{batchId:e.id,records:e.records.length,throttledMs:t});return}try{await this.transport.send(e,()=>{this.unconfirmed.delete(e.id)})}catch(t){if(this.stopped)return;await this.storeFailed({...e,attempts:e.attempts+1},t),this.diagnostics.report(`transport.http_error`,`The send failed. The pipeline stored the batch for a retry.`,{batchId:e.id,records:e.records.length},t)}}finally{this.unconfirmed.delete(e.id)}}async storeFailed(e,t){await this.diagnostics.guardAsync(`storage.degraded`,`The library could not store an undelivered batch.`,async()=>{await this.retry.storeFailed(e,t)})}async store(t){await this.diagnostics.guardAsync(`storage.degraded`,`The library could not store an undelivered batch.`,async()=>{await a.n(this.storage.save(t),e.Cn),this.retry.nudge()})}},L=class e{storage;retry;pipeline;exitFlush;diagnostics;transport;retired=!1;emergencyImport=Promise.resolve();constructor(e,t,n,r,i,a){this.storage=e,this.retry=t,this.pipeline=n,this.exitFlush=r,this.diagnostics=i,this.transport=a}static async create(n){let{config:a,diagnostics:o}=n,s=n.storage??await r.createStorage(a.storage,r.storageName(a.persistence.namespace),t.storageLimits(a.retention),o,n.onGap,a.persistence.namespace);n.onStorage?.(s),a.persistence.requestPersistent&&(s.name===`indexeddb`||s.name===`localstorage`)&&(n.onPersistence?.(`pending`),v(o).then(n.onPersistence));let c=new i.ContextStorage(s,a.securityContext,a.persistence.namespace),l=e=>{let t=_.n(e,o);t&&_.t(n.remote,a,t)},u,d=e=>{u=e},{onLoss:f}=n,p=!a.transport&&a.transportWorker?await o.guardAsync(`transport.http_error`,`The transport worker module did not load. The library uses HTTP.`,async()=>(await Promise.resolve().then(()=>require("./worker-transport-Bwej4N2e.cjs"))).createWorkerTransport(a,o,l,f,d)):void 0,m=a.transport!==void 0||p!==void 0?void 0:new j(a,o,l,f,d),h=p?.transport??m??new w(a,o,l,f,d),g=new M(c,h,o,a,void 0,f),{batching:y}=a,b=new I(h,c,g,o,{logs:{flushIntervalMs:y.logFlushIntervalMs,batchSize:y.logBatchSize},metrics:{flushIntervalMs:y.metricFlushIntervalMs,batchSize:y.metricBatchSize},traces:{flushIntervalMs:y.logFlushIntervalMs,batchSize:y.logBatchSize}},()=>a.securityContext.id||void 0,a,f,()=>a.metadata.clockOffset?u:void 0),x=new T({config:a,diagnostics:o,drainForExit:()=>b.drainForExit(),flushAlive:()=>b.flushPending(),exitHeaders:()=>p?p.exitHeaders():m?.lastHeaders(),onLoss:f,beforeExit:n.beforeExit}),S=!1;try{x.install(),g.start(),S=!0}finally{S||(x.uninstall(),g.stop())}let C=new e(c,g,b,x,o,h);return C.emergencyImport=C.importEmergency(),C}push(e){this.pipeline.push(e)}async flush(){await this.pipeline.flushPending()}async clearPersisted(e,t){e===`namespace`?await this.storage.clearNamespace():await this.storage.clear(),n.clearEmergencyContext(t,this.diagnostics,this.storage.namespace,e===`namespace`)}async queueDepth(){return await this.diagnostics.guardAsync(`storage.degraded`,`The library could not count the batches in storage.`,()=>this.storage.count())??0}stats(){return{...this.pipeline.counts(),lastSendAt:this.transport.lastSendAt()}}async destroy(){await this.diagnostics.guardAsync(`pipeline.crashed`,`The flush before shutdown failed.`,()=>this.flush()),this.exitFlush.flush(`shutdown`),this.exitFlush.uninstall(),this.retry.stop(),this.transport.stop(),this.pipeline.destroy(),await this.storage.close()}async retire(e,t,r){if(this.retired=!0,this.exitFlush.uninstall(),this.retry.stop(),e===`flush`)try{await a.n(Promise.all([this.flush(),this.retry.flush()]),t)}catch(e){this.diagnostics.report(`transport.timeout`,`The flush of the old security context did not complete before its time limit.`,void 0,e)}this.retry.stop(),this.transport.stop();let i=this.pipeline.drainForExit(),o=i.flatMap(e=>e.records);this.pipeline.destroy(),await this.emergencyImport;let s=await this.storage.take(2**53-1);if(e===`retain`)for(let e of i)await this.storage.save({...e,routingContextId:r,persistenceNamespace:this.storage.namespace});let c=e===`discard`||e===`flush`;return await this.storage.retire(c),c&&n.clearEmergencyContext(r,this.diagnostics,this.storage.namespace),{buffered:o,stored:s}}async adopt(e,t){for(let n of e)await this.storage.save({...n,attempts:0,routingContextId:t,persistenceNamespace:this.storage.namespace});e.length>0&&this.retry.nudge()}async importEmergency(){let e=await this.diagnostics.guardAsync(`storage.degraded`,`The emergency import failed.`,()=>n.drainEmergencyQueue(this.storage,this.diagnostics,e=>this.storage.accepts(e),this.storage.namespace));!this.retired&&e!==void 0&&e>0&&this.retry.nudge()}};exports.Sender=L,exports.a=b,exports.i=O,exports.n=j,exports.r=k,exports.t=A;
|
|
2
|
+
//# sourceMappingURL=sender-D5wBoXA8.cjs.map
|