hud-sdk 1.3.9 → 1.3.10
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/THIRD_PARTY_LICENSES.txt +49 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/init.js +1 -1
- package/dist/cjs/internal.js +1 -1
- package/dist/cjs/plugin.js +1 -1
- package/dist/cjs/postInstall.js +1 -0
- package/dist/cjs/worker.js +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/loader.mjs +1 -1
- package/dist/esm/register.mjs +1 -1
- package/dist/types/internal.d.ts +20 -2
- package/package.json +6 -2
package/THIRD_PARTY_LICENSES.txt
CHANGED
|
@@ -556,3 +556,52 @@ THE SOFTWARE.
|
|
|
556
556
|
|
|
557
557
|
--------------------------------------------------------------------------------
|
|
558
558
|
|
|
559
|
+
Package: gunzip-maybe
|
|
560
|
+
License: MIT
|
|
561
|
+
Repository: https://github.com/mafintosh/gunzip-maybe
|
|
562
|
+
|
|
563
|
+
The MIT License (MIT)
|
|
564
|
+
|
|
565
|
+
Copyright (c) 2016 Mathias Buus
|
|
566
|
+
|
|
567
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
568
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
569
|
+
in the Software without restriction, including without limitation the rights
|
|
570
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
571
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
572
|
+
furnished to do so, subject to the following conditions:
|
|
573
|
+
|
|
574
|
+
The above copyright notice and this permission notice shall be included in
|
|
575
|
+
all copies or substantial portions of the Software.
|
|
576
|
+
|
|
577
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
578
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
579
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
580
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
581
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
582
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
583
|
+
THE SOFTWARE.
|
|
584
|
+
|
|
585
|
+
--------------------------------------------------------------------------------
|
|
586
|
+
|
|
587
|
+
Package: tar
|
|
588
|
+
License: ISC
|
|
589
|
+
Repository: https://github.com/isaacs/node-tar
|
|
590
|
+
|
|
591
|
+
The ISC License
|
|
592
|
+
|
|
593
|
+
Copyright (c) Isaac Z. Schlueter and Contributors
|
|
594
|
+
|
|
595
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
596
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
597
|
+
copyright notice and this permission notice appear in all copies.
|
|
598
|
+
|
|
599
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
600
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
601
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
602
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
603
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
604
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
605
|
+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
606
|
+
|
|
607
|
+
--------------------------------------------------------------------------------
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(global,(()=>(()=>{var e={5009:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.SketchData=void 0,t.SketchData=class extends Array{indexShift=0;constructor(){super()}}},1582:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.SketchManager=void 0;const o=r(5009);t.SketchManager=class{binWidth;logBinWidth;constructor(e){this.binWidth=e,this.logBinWidth=Math.log(e)}binIndex(e){return Math.floor(Math.log(e)/this.logBinWidth)}indexToBinStart(e){return this.binWidth**e}newSketchDataWithValue(e){const t=this.binIndex(e),r=new o.SketchData;return r.indexShift=t,r[0]=1,r}add(e,t){const r=this.binIndex(t);let o=r-e.indexShift;o<0?(e.unshift(...new Array(-o).fill(0)),e.indexShift=r,o=r-e.indexShift):o>=e.length&&e.push(...new Array(o-e.length+1).fill(0)),e[o]+=1}zero(e){e.fill(0)}copy(e){const t=new o.SketchData;return t.indexShift=e.indexShift,t.push(...e),t}mergeIntoNoChecks(e,t){const r=t.indexShift-e.indexShift;for(let o=0;o<t.length;o++)e[o+r]+=t[o]}mergeInto(e,t){t.indexShift<e.indexShift&&(e.unshift(...new Array(e.indexShift-t.indexShift).fill(0)),e.indexShift=t.indexShift),t.indexShift+t.length>e.indexShift+e.length&&e.push(...new Array(t.indexShift+t.length-(e.indexShift+e.length)).fill(0)),this.mergeIntoNoChecks(e,t)}mergeMany(e){if(0===e.length)throw new Error("Cannot merge empty list of SketchData.");if(1===e.length)return this.copy(e[0]);let t=1/0,r=-1/0;for(const o of e)t=Math.min(t,o.indexShift),r=Math.max(r,o.indexShift+o.length-1);const n=new o.SketchData;n.indexShift=t,n.push(...new Array(r-t+1).fill(0));for(const t of e)this.mergeIntoNoChecks(n,t);return n}getQuantile(e,t){const r=e.reduce(((e,t)=>e+t),0);if(0===r)throw new Error("Cannot get quantile of empty SketchData.");const o=r*t;let n,i=0;for(n=0;n<e.length&&(i+=e[n],!(i>=o));n++);const s=this.indexToBinStart(n+e.indexShift),a=(i-o)/e[n];return s*this.binWidth**(1-a)}encode(e){return{binWidth:this.binWidth,indexShift:e.indexShift,data:Array.from(e)}}decode(e){if(e.binWidth!==this.binWidth)throw new Error(`Should not decode sketch data with bin width ${e.binWidth} using SketchManager with bin width ${this.binWidth}.`);const t=new o.SketchData;return t.indexShift=e.indexShift,t.push(...e.data),t}}},6601:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||o(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),n(r(5009),t),n(r(1582),t)},8878:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.init=t.safeLog=void 0;const s=r(713),a=r(1377),c=i(r(6495)),u=r(8167);t.safeLog=function(e){try{a.app_logger.info(e)}catch(e){return}},u.isMainThread&&(a.app_logger.info("HUD is required"),(0,s.initGlobals)(),c.onRequire()),t.init=c.default},1019:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||o(t,e,r)},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(r(5809));n(r(5809),t),t.default=s.default},3343:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.updateDynamicConfig=void 0;const o=r(1019);t.updateDynamicConfig=function(e,t,r){let n;const i=o.HudDynamicConfigSchema.partial().safeParse(e);return i.success?n={...t.dynamicConfig,...i.data}:(r.error("Dynamic configuration not updated - Invalid configuration override",{remoteConfigParseResult:i}),n=t.dynamicConfig),n}},9720:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.resetCallers=t.prepCalls=t._liftExceptions=void 0;const o=r(1377);function n(e){const t={};for(const r in e){const o=new Map;e[r].forEach((e=>{const t=JSON.stringify(e.caller);o.has(t)?o.get(t).count++:o.set(t,{caller:e.caller,count:1})})),t[r]=Array.from(o.values())}return t}t._liftExceptions=n,t.prepCalls=function(e,t){const r=(new Date).toISOString(),i=[];return Object.entries(hudCalls).map((([s,a])=>{Object.entries(a).forEach((([a,c])=>{Object.entries(c).forEach((([c,u])=>{try{if(0===u.sampledCount)return;const o=n(u.exceptions),l={function_id:s,wrapped_flow_id:c||void 0,wrapped_caller_id:a||void 0,timestamp:r,timeslice:e,exceptions:o,count:u.count-u.lastSentCounter,sampled_count:u.sampledCount,sum_duration:u.sum,sum_squared_duration:u.squareSum,sketch:u.sketch?t.encode(u.sketch):void 0,is_linked_function:u.isLinkedFunction};i.push(l),function(e){e.lastSentCounter=e.count,e.sampledCount=0,e.sum=0,e.squareSum=0,e.sketch=null,e.exceptions={}}(u)}catch(e){o.app_logger.error("Failed preparing invocation, skipping",{func:s,wrappedCaller:a,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}))}))})),i},t.resetCallers=function(){for(const t in globalThis.hudCalls)for(const r in globalThis.hudCalls[t])for(const o in globalThis.hudCalls[t][r])(e=globalThis.hudCalls[t][r][o]).lastSentCounter-=e.count,e.count=0;var e}},4268:function(e,t,r){"use strict";var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.MainThread=void 0;const n=r(8167),i=r(1377),s=o(r(7674)),a=o(r(1019)),c=r(2676),u=r(3343),l=r(9514);t.MainThread=class{apiKey;service;startTime;messenger;constructor(e,t,r){this.apiKey=e,this.service=t,this.startTime=r}async start(){if(n.isMainThread){try{this.messenger=await this._createMessenger(),await this._initDynamicConfig()}catch(e){const t=e instanceof Error?e.message:void 0;if(e instanceof l.HudSessionThrottle)throw e;throw i.app_logger.error("Failed to starting worker",{msg:t}),e}await this.messenger.start()}}async _createMessenger(){const e=c.myRequire.resolve(`${a.default.hudModuleName}/worker`),t=new n.Worker(e,{workerData:{apiKey:this.apiKey,service:this.service,startTime:this.startTime}});let r;try{r=new s.default(t),await r.checkWorker(a.default.workerTimeout)}catch(e){if(e instanceof l.HudSessionThrottle)throw i.app_logger.info("Worker started in idle mode - session throttled"),e;throw i.app_logger.error("Worker failed to start",{msg:e instanceof Error?e.message:void 0}),e}finally{t.unref()}return r}async _initDynamicConfig(){const e=await(this.messenger?.getRemoteConfig());e?(i.app_logger.info("Remote configuration exists"),a.default.dynamicConfig=(0,u.updateDynamicConfig)(e,a.default,i.app_logger),i.app_logger.info("Current dynamic configuration:",{currentDynamicConfig:a.default.dynamicConfig})):i.app_logger.info("No remote configuration - falling back to default dynamic configuration",{defaultDynamicConfig:a.default.dynamicConfig})}async terminateMessenger(){await(this.messenger?.terminateWorker()),this.messenger?.stop()}}},7674:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=i(r(1377)),c=i(r(6460)),u=s(r(1019)),l=r(765),d=r(1765),f=r(6601),p=r(9720),h=r(398),g=r(713),m=r(9514),_=r(6701),y=r(732),v=r(6538),b=r(331),w=r(6495),k=r(6257),S=r(6530),M=r(5202),C=r(1954),P=r(2676),E=a.app_logger,O=_.safeCall.bind(_.safeCall,E);function x(){const e=globalThis.hudProcessedFiles;return globalThis.hudProcessedFiles=[],e}t.default=class{worker;abortController;workerKeepaliveGuard;constructor(e){this.worker=e,this.abortController=new AbortController,this.worker.on("error",this.handleWorkerError).unref(),this.workerKeepaliveGuard=new y.WorkerKeepaliveGuard(e,u.default.communicationKeepaliveGrace)}handleWorkerError=e=>{try{E.error("Error from worker, stopping hud",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0}),(0,m.setFirstError)(e?.code),this.stop(),(0,w._detachHud)()}catch(e){E.error("Error stopping hud",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}};stop(){this.abortWorker(),u.default.communicationKeepalive&&this.workerKeepaliveGuard.stop(),this.abortController.abort(),this.abortController=new AbortController,(0,g.resetGlobals)()}abortWorker(){this._sendObject("Abort",{})}async restart(e){this.stop(),globalThis.hudRunningMode=e,await this.start()}_sendArray(e,t){t.length>0&&(this._sendObject(e,t),E.debug("sent data to worker",{msg:e,size:t.length}))}_sendObject(e,t){const r={msg:e,content:t};this.worker.postMessage(r)}async checkWorker(e){let t;try{t=await this.getMessageFromWorker("initialized",e,!0)}catch(r){if(!(r instanceof m.HudTimeoutError))throw r;t=await this.getMessageFromWorker("initialized",e/2,!1)}if("initialized"!==t?.msg||void 0===t?.content)throw new m.HudInitError("Worker not initialized");if(t?.content.status===l.HudSessionInitStatus.throttled)throw new m.HudSessionThrottle;if(t?.content.status!==l.HudSessionInitStatus.success)throw new m.HudInitError("Worker not initialized successfully")}async start(){switch(u.default.communicationKeepalive&&this.workerKeepaliveGuard.start(),globalThis.hudRunningMode){case l.HudRunningMode.enabled:E.info("Enabled mode"),O(this.getMode()),O(this.startPeriodicTasks()),O(this.pumpFunctions()),O(this.periodicSendEndpoints()),O(this.periodicSendFlowMetrics()),O(this.periodicSendGarphQL()),O(this.periodicSendKafkaJS()),O(this.resetCallerCounters()),O(this.sendLogsPeriodically(u.default.logsSendInterval)),O(this.sendRuntime()),O(this.sendPatchedModules()),O(this.sendPreloadedModules()),O(this.dumpModulesAfterWhile(6e4)),O((0,h.loopLogThreadPerformance)(E,u.default.logPerfInterval,this.abortController.signal));break;case l.HudRunningMode.disabled:E.info("Disabled mode"),O(this.getMode());break;case l.HudRunningMode.detached:E.info("Detached"),await this.terminateWorker(),this.stop();break;default:E.error("Running mode not handled")}}async getMessageFromWorker(e,t,r=!1,o){let n;const i=new AbortController,s=()=>{i.abort()};this.abortController.signal.addEventListener("abort",s);const a=c.setTimeout(t,void 0,{signal:i.signal,ref:r}),u=t=>{try{t.msg===e&&(n=t,i.abort(),E.info("Received message from worker (canceling timeout)",t))}catch(e){E.error("Failed handling message from worker",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}};this.worker.on("message",u).unref(),o&&this.worker.postMessage(o);try{throw await a,E.warn("Timeout waiting for message from worker"),new m.HudTimeoutError}catch(e){if(!(0,m.isAbortError)(e))throw(0,m.setFirstError)(e.code),e}finally{this.abortController.signal.removeEventListener("abort",s),this.worker.off("message",u)}return n}async getMode(){for await(const e of(0,d.unrefSetInterval)(u.default.modeInterval,void 0,{signal:this.abortController.signal}))try{const e={msg:"GetMode",content:{startTime:globalThis.hudStartTime,runningMode:globalThis.hudRunningMode}},t=await this.getMessageFromWorker(e.msg,u.default.workerMessageTimeout,!1,e);if(t?.msg!==e.msg||void 0===t?.content.mode){E.error("Unexpected message from worker",t);continue}t.content.mode!==globalThis.hudRunningMode&&await this.restart(t?.content.mode)}catch(e){E.error("Failed getting mode from worker",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}async getRemoteConfig(){const e="initDynamicConfig";try{const t=await this.getMessageFromWorker(e,u.default.workerMessageTimeout,!0);if(t?.msg!==e||void 0===t?.content)throw new Error(`Unexpected message from worker: ${t}`);return t?.content}catch(e){E.error("Failed getting remote configuration from worker",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}async resetCallerCounters(){const e=u.default.callerResetInterval;for await(const t of(0,d.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))try{E.info("Resetting caller",{interval:e}),(0,p.resetCallers)()}catch(e){E.error("Failed reseting caller counters",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}async pumpFunctions(){const e=u.default.dynamicConfig.aggregationInterval,t=new f.SketchManager(u.default.huddBinWidth);for await(const r of(0,d.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))try{const r=x(),o=(0,p.prepCalls)(e,t);this._sendArray("Invocations",o),this._sendArray("ProcessedFiles",r)}catch(e){E.error("Failed sending pumping functions to worker, skipping",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}await this.terminateWorker(),this.stop()}async periodicSendFlowMetrics(){const e=u.default.dynamicConfig.flowMetricInterval;for await(const t of(0,d.unrefSetInterval)(e,void 0,{signal:this.abortController.signal})){const t=(0,b.getFlowMetrics)().map((e=>e.toRaw())).filter((e=>e));t.length>0&&this._sendObject("FlowMetrics",{timeslice:e,rawMetrics:t})}}async periodicSendGarphQL(){const e=u.default.dynamicConfig.graphqlInterval;for await(const t of(0,d.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))this.sendGraphQLResolvers(),this.sendGraphQLDocuments()}async periodicSendKafkaJS(){const e=u.default.dynamicConfig.aggregationInterval;for await(const t of(0,d.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))try{const e=(0,M.getKafkaJSTopics)();this._sendArray("KafkaJSTopics",e)}catch(e){E.error("Failed sending KafkaJsTopics to worker, skipping",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}sendGraphQLResolvers(){try{const e=(0,k.getResolversDeclarations)().map((e=>({id:e.id,operation:e.operation,name:e.name})));this._sendArray("GraphQLResolvers",e)}catch(e){E.error("Failed sending resolvers to worker, skipping",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}sendGraphQLDocuments(){try{const e=(0,S.getDocumentsMetadata)().map((e=>({name:e.name,hash:e.hash,selection_names:e.selectionNames,time_took:e.timeTook})));this._sendArray("GraphQLDocuments",e)}catch(e){E.error("Failed sending documents to worker, skipping",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}async periodicSendEndpoints(){await(0,d.unrefSetTimeout)(u.default.endpointsFirstSendWaitTime,void 0,{signal:this.abortController.signal}),this.sendEndpoints();const e=u.default.endpointsInterval;for await(const t of(0,d.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))this.sendEndpoints()}sendEndpoints(){try{const e=(0,v.getEndpointDeclarations)().map((e=>({path:e.path,methods:e.methods,flow_id:e.flow_id,framework:e.framework,partial_path:e.partial_path})));this._sendArray("EndpointDeclaration",e)}catch(e){E.error("Failed sending endpoints to worker, skipping",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}async terminateWorker(){try{this.worker.off("error",this.handleWorkerError),await this.getMessageFromWorker("terminated",u.default.workerGrace,!1,{msg:"Terminate",content:u.default.workerGrace})}catch(e){if(!(e instanceof m.HudTimeoutError))throw E.error("Unexpected error, terminating worker"),await this.worker.terminate(),e;E.error("Grace period timeout, terminating worker"),await this.worker.terminate()}E.info("Worker terminated successfully.")}async sendRuntime(){const e={nodeVersion:process.version,nodeDependencyVersions:process.versions,platform:process.platform,architecture:process.arch,pid:process.pid,cwd:process.cwd(),execPath:process.execPath,execArgv:process.execArgv,argv:process.argv,uptime:process.uptime(),mainModulePath:r.c[r.s]?.filename};this._sendObject("Runtime",e)}async startPeriodicTasks(){this._sendObject("StartPeriodicTasks",{})}async sendPreloadedModules(){globalThis.hudLoadedModules?this._sendObject("PreInitLoadedModules",{modules:globalThis.hudLoadedModules}):E.warn("Didn't get module, weird....")}async dumpModulesAfterWhile(e){await(0,d.unrefSetTimeout)(e,void 0,{signal:this.abortController.signal});const t=Object.keys(P.myRequire.cache);this._sendObject("PostInitLoadedModules",{modules:t})}async sendPatchedModules(){if(!globalThis.hudPatched)return void E.error("Cant find patched modules");const e=Array.from(globalThis.hudPatched);this._sendObject("PatchedModules",{modules:e})}async sendLogsPeriodically(e){const t=(0,C.suppressTraces)(a.renewFileTransports);for await(const r of(0,d.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))try{const e=a.getSavedLogs();for(const t of e)try{this._sendObject("Logs",{logs:t})}catch(e){E.error("Failed send logs to worker",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}const r=t();r.size>0&&this._sendObject("LogFilename",{filenames:r})}catch(e){E.error("Failed send logs to worker",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}}},732:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.WorkerKeepaliveGuard=void 0;const s=i(r(1377)),a=r(765),c=s.app_logger;t.WorkerKeepaliveGuard=class{worker;keepaliveGrace;timeoutId=void 0;eventHandler=this.keepalive.bind(this);constructor(e,t){this.worker=e,this.keepaliveGrace=t}keepalive(e){try{if(e.msg!==a.KeepAliveMessage.msg)return;this._restartTimeout()}catch(e){c.error("Error in keepalive",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}_restartTimeout(){const e=setTimeout((()=>{}),this.keepaliveGrace);clearTimeout(this.timeoutId),this.timeoutId=e}start(){this.stop(),this.worker.on("message",this.eventHandler).unref()}stop(){void 0!==this.timeoutId&&clearTimeout(this.timeoutId),this.worker.off("message",this.eventHandler),this.timeoutId=void 0}}},7022:(e,t)=>{"use strict";var r;Object.defineProperty(t,"__esModule",{value:!0}),t.isSupportedFormat=t.Format=void 0,function(e){e.cjs="commonjs",e.esm="module"}(r||(t.Format=r={})),t.isSupportedFormat=function(e){return Object.values(r).includes(e)}},878:(e,t)=>{"use strict";var r;Object.defineProperty(t,"__esModule",{value:!0}),t.GraphQLSupportedOperations=void 0,function(e){e.query="query",e.mutation="mutation"}(r||(t.GraphQLSupportedOperations=r={}))},765:(e,t)=>{"use strict";var r,o;Object.defineProperty(t,"__esModule",{value:!0}),t.HudSessionInitStatus=t.HudRunningMode=t.KeepAliveMessage=void 0,t.KeepAliveMessage={msg:"keep-alive"},function(e){e[e.detached=0]="detached",e[e.disabled=1]="disabled",e[e.enabled=2]="enabled"}(r||(t.HudRunningMode=r={})),function(e){e[e.success=0]="success",e[e.throttled=1]="throttled"}(o||(t.HudSessionInitStatus=o={}))},9514:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.setFirstError=t.getFirstError=t.isAbortError=t.HudBadLoggerError=t.HudTimeoutError=t.HudWorkloadCollectorError=t.HudAssert=t.HudUnsupportedError=t.HudEditError=t.HudWorkerError=t.HudClientError=t.HudSessionThrottle=t.HudInitError=t.HudError=void 0;class r extends Error{code=1e3;name=this.constructor.name;constructor(e){super(e)}}t.HudError=r;class o extends r{code=1001}t.HudInitError=o,t.HudSessionThrottle=class extends o{},t.HudClientError=class extends r{code=1002},t.HudWorkerError=class extends r{code=1003};class n extends r{code=1004}t.HudEditError=n,t.HudUnsupportedError=class extends n{code=1005},t.HudAssert=class extends n{code=1006},t.HudWorkloadCollectorError=class extends r{code=1007},t.HudTimeoutError=class extends r{code=1008},t.HudBadLoggerError=class extends r{code=1101},t.isAbortError=function(e){return e instanceof Error&&"AbortError"===e.name};let i=9999;t.getFirstError=function(){return i},t.setFirstError=function(e){e&&9999===i&&(i=e)}},6538:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.storeEndpointDeclaration=t.getEndpointDeclarations=t.EndpointDeclaration=void 0;const s=i(r(1377)),a=r(7697),c=s.app_logger;function u(e,t){return t?t instanceof RegExp?e+t.toString():("/"===t[t.length-1]&&t.length>1&&(t=t.slice(0,-1)),(t=e+t).replace(/\/{2,}/g,"/")):t}t.EndpointDeclaration=class{flow_id;methods;framework;partial_path;path;constructor(e,t,r,o,n,i){this.flow_id=e,this.methods=t,this.framework=r,this.partial_path=i,o||(o=""),this.path=u(o,n),this.partial_path=u(o,i)}},t.getEndpointDeclarations=function(){let e=[];globalThis.hudExpressState.forEach((t=>{try{e=e.concat((0,a.extractEndpointsFromRouter)("",t))}catch(e){c.error("Failed to extract endpoints from express",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}})),e=e.concat(d());const t=new Set;return e.forEach((e=>{e.partial_path||t.add(e.flow_id)})),e.filter((e=>!e.partial_path||!t.has(e.flow_id)&&(c.info("Partial endpoint without full endpoint",{endpoint:e}),!0)))};let l=[];function d(){const e=l;return l=[],e}t.storeEndpointDeclaration=function(e){l.push(e)}},2847:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HttpEndpointMetric=void 0;const o=r(331);class n extends o.FlowMetric{statusCode;route;method;constructor(e){super(e)}_createUsableMetric(e){return this}setRequestAttributes(e){this.route=e.url?.split("?")[0],this.method=e.method}setResponseAttributes(e){this.statusCode=e.statusCode}toRaw(){if(this.statusCode&&this.route&&this.method)return{flow_id:this.flowId,type:"EndpointMetric",duration:this.duration,status_code:this.statusCode,route:this.route,method:this.method}}}t.HttpEndpointMetric=n},331:function(e,t,r){"use strict";var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFlowMetrics=t.FlowMetric=t.metricSymbol=void 0;const n=o(r(932)),i=o(r(1019)),s=r(765);t.metricSymbol=Symbol(i.default.hudMetricName),t.FlowMetric=class{_state;flowId;duration;_startTime;constructor(e){this.flowId=e,this.duration=0,this._state="usable"}static createUsableMetric(e){return new this(e)._createUsableMetric(e)}setFlowId(e){this.flowId=e}getFlowId(){return this.flowId}start(){this._startTime=n.default.hrtime.bigint()}end(){this._startTime&&(this.duration=Number(n.default.hrtime.bigint()-this._startTime)),this.#e(),this._state="unusable"}#e(){hudRunningMode===s.HudRunningMode.enabled&&a.push(this)}};let a=[];t.getFlowMetrics=function(){const e=a;return a=[],e}},938:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.GraphQLMetric=void 0;const o=r(331);class n extends o.FlowMetric{constructor(e){super(e)}_createUsableMetric(e){return this}toRaw(){return{flow_id:this.flowId,type:"GraphQLMetric",duration:this.duration}}}t.GraphQLMetric=n},6842:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.KafkaJSMetric=void 0;const o=r(331),n=r(1377);class i extends o.FlowMetric{partition;error;producedTimestamp;totalConsumeDuration;constructor(e){super(e)}_createUsableMetric(e){return this}end(){super.end(),this.producedTimestamp&&(this.totalConsumeDuration=Number(Date.now()-this.producedTimestamp)*Number(1e6))}addProducedTimestamp(e){void 0!==e&&(this.producedTimestamp=Number(e))}addPartition(e){this.partition=e}setError(e){"string"==typeof e?this.error=e:n.instrument_logger.warn("Error message is not a string",{flowId:this.flowId,errorMessage:e})}toRaw(){if(void 0!==this.partition)return{flow_id:this.flowId,type:"KafkaJSMetric",duration:this.duration,partition:this.partition,error:this.error,total_consume_duration:this.totalConsumeDuration};n.instrument_logger.warn("No partition found for message",{flowId:this.flowId})}}t.KafkaJSMetric=i},713:function(e,t,r){"use strict";var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.hookMessageChannel=t.resetGlobals=t.initGlobals=void 0,r(1999);const n=r(765),i=r(6601),s=o(r(1019)),a=r(2243),c=r(8167);function u(){globalThis.hudProcessedFiles=[],globalThis.hudManager=new i.SketchManager(s.default.huddBinWidth),globalThis.hudWrappedCaller=new Array(1e3).fill(""),globalThis.hudWrappedCallerIndex={value:0},globalThis.hudLoadedModules={},globalThis.hudPatched=new Set,globalThis.HudRetrieveFileCache=new Map,globalThis.hudExpressState=[]}t.initGlobals=function(){globalThis.hudGlobalInitGuard||(globalThis.hudGlobalInitGuard=!0,globalThis.hudRunMutex=!1,globalThis.hudRanOnRequire=!1,globalThis.hudRanOnImport=!1,globalThis.hudInitGuard=void 0,globalThis.hudStartTime=new Date,globalThis.hudCalls={},globalThis.hudRunningMode=n.HudRunningMode.enabled,globalThis.hudCurrentFlowId="",globalThis.hudShouldLinkFunction=!1,(0,a.initHudSampleTable)(),u())},t.resetGlobals=u,t.hookMessageChannel=function(){const{port1:e,port2:t}=new c.MessageChannel;return e.on("message",(e=>{"HudModulePatch"===e.key?(globalThis.hudPatched.add(e.hudPatched),globalThis.hudProcessedFiles.push(e.hudProcessedFiles)):"HudRetrieveFileCache"===e.key&&globalThis.HudRetrieveFileCache.set(e.filename,e.content)})),e.unref(),globalThis.hudHookPort=e,t}},1999:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},7729:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.safeLog=t.init=t.asyncIteratorWrapper=t.fixStack=t.wrapperFinally=t.wrapperCatch=t.wrapperInitial=void 0,r(1999);var o=r(8891);Object.defineProperty(t,"wrapperInitial",{enumerable:!0,get:function(){return o.wrapperInitial}}),Object.defineProperty(t,"wrapperCatch",{enumerable:!0,get:function(){return o.wrapperCatch}}),Object.defineProperty(t,"wrapperFinally",{enumerable:!0,get:function(){return o.wrapperFinally}}),Object.defineProperty(t,"fixStack",{enumerable:!0,get:function(){return o.fixStack}}),Object.defineProperty(t,"asyncIteratorWrapper",{enumerable:!0,get:function(){return o.asyncIteratorWrapper}});let n={};try{"true"===process.env.HUD_ENABLE&&(n=r(8878))}catch(e){}t.init=n.init||async function(e,t){},t.safeLog=n.safeLog||function(...e){}},6495:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.onRequire=t._detachHud=t.shouldRun=void 0;const o=r(9720),n=r(1377),i=r(4268),s=r(1019),a=r(3976),c=r(9514),u=r(765),l=r(6701),d=r(8167);let f;function p(e){return null!=e&&""!==e&&"string"==typeof e}function h(e){if(!function(e){return globalThis.hudRunningMode===u.HudRunningMode.detached?(e?.error("Not running, disabled by default"),!1):!s.hudConfig.defaultOff||(n.app_logger.info("hud is disabled by default"),"true"===process.env.HUD_ENABLE?(n.app_logger.info("override! hud is enabled by env string"),!0):(e?.error("Not running, disabled by default"),!1))}(e))return!1;const t=process.versions.node.split(".")[0];return!!s.hudConfig.supportedNodeVersions.includes(t)||(e?.error(`Not running. Reason: Node version ${t} is not supported. Your application remains unaffected.`),!1)}function g(e=!0,t=!1){n.app_logger.warn("Detaching hud"),(t||e&&hudRunningMode!==u.HudRunningMode.detached)&&n.customer_logger.error(`SDK has initiated a graceful shutdown (Code: ${(0,c.getFirstError)()}). Your application remains unaffected.`),globalThis.hudRunningMode=u.HudRunningMode.detached,f&&(0,l.safeCall)(n.app_logger,f.terminateMessenger()),(0,o.resetCallers)()}function m(){n.app_logger.warn("Init timeout disabling hud!"),n.customer_logger.error("SDK imported but not initialized. Please ensure to call 'hud.init()' to initialize the SDK."),g(!1)}t.default=async function(e,t){try{if(!d.isMainThread)return;if(globalThis.hudRunMutex)return void n.app_logger.warn("Already ran init!");if(globalThis.hudRunMutex=!0,clearTimeout(globalThis.hudInitGuard),!n.app_logger.isValid())return(0,c.setFirstError)((new c.HudBadLoggerError).code),void g(!0,!0);if(!h(n.customer_logger))return;if(!p(e)||void 0===e||"INVALID_API_KEY"===e)return n.app_logger.warn("Bad api-key provided"),s.hudConfig.disableOnBadApiKey&&g(!1),void n.customer_logger.error("Not running, bad api-key provided");if(!p(t)||void 0===t)return n.app_logger.warn("Invalid service provided"),s.hudConfig.disableOnBadServiceName&&g(!1),void n.customer_logger.error("Not running, bad service name provided");n.app_logger.info("Initializing hud",{service:t}),f=new i.MainThread(e,t,globalThis.hudStartTime);try{await f.start(),n.customer_logger.info("Initialized successfully")}catch(e){e instanceof c.HudSessionThrottle?(n.customer_logger.info("Initialized successfully in idle mode."),g(!1,!1)):(n.app_logger.error("Init failed disabling hud",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0}),(0,c.setFirstError)(e.code),g())}}catch(e){try{n.app_logger.error("Something went wrong in init",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}catch(e){n.app_logger.error("Something went wrong in init & e.stack raised an exception")}g()}},t.shouldRun=h,t._detachHud=g,t.onRequire=function(){try{if(!n.app_logger.isValid())return void g(!1);if(globalThis.hudRanOnRequire)return void n.app_logger.warn("Already ran onRequire!");if(globalThis.hudRanOnRequire=!0,!h())return;(0,a.patchCompile)(),(0,a.patchRequire)(),globalThis.hudInitGuard=setTimeout(m,s.hudConfig.timeoutOnInit),globalThis.hudInitGuard.unref()}catch(e){n.app_logger.error("Something went wrong in onRequire",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}},2243:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.edit=t.initHudSampleTable=void 0;const a=i(r(6346)),c=i(r(143)),u=i(r(9896)),l=r(3903),d=r(1377),f=s(r(1019)),p=r(7022),h=s(r(6928)),g=r(2676),m=/([0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12})/;function _(e,t){const r=`${e}_hudTemp`,o="BODY_PLACEHOLDER",n="FUNCTION_ID_PLACEHOLDER",i="AWAITABLE_PLACEHOLDER";let s;return s=t===p.Format.esm?[`import { createRequire as ${e}_createRequire } from "module";`,`const ${e}_require = ${e}_createRequire(import.meta.url);`,`const { wrapperInitial: ${e}_wrapperInitial, wrapperCatch: ${e}_wrapperCatch, wrapperFinally: ${e}_wrapperFinally, fixStack: ${e}_fixStack, safeLog: ${e}_logger, asyncIteratorWrapper: ${e}_asyncIteratorWrapper} = ${e}_require("${g.myRequire.resolve(f.default.hudModuleName)}");`,`${e}_logger('File loaded ' + import.meta.url);`]:[`const {wrapperInitial: ${e}_wrapperInitial, wrapperCatch: ${e}_wrapperCatch, wrapperFinally: ${e}_wrapperFinally, fixStack: ${e}_fixStack, safeLog: ${e}_logger, asyncIteratorWrapper: ${e}_asyncIteratorWrapper} = require("${g.myRequire.resolve(f.default.hudModuleName)}");`,`${e}_logger('File loaded ' + __filename);`],{functionWrapper:`{\n let ${r};\n const ${e}_functionId = ${n};\n const ${e}_callContext = {};\n ${e}_wrapperInitial(${e}_functionId, ${e}_callContext);\n try {\n ${o}\n } catch (e) {\n ${e}_wrapperCatch(${e}_functionId, ${e}_callContext, e);\n throw e;\n } finally {\n ${e}_wrapperFinally(${e}_functionId, ${e}_callContext);\n }\n }`,awaitWrapper:`(${r} = ${i}, hudWrappedCallerIndex.value--, hudCurrentFlowId = "", ${e}_callContext.fixFlag = true, ${r} = await ${r}, hudWrappedCaller[++hudWrappedCallerIndex.value] = ${e}_functionId, hudCurrentFlowId = ${e}_callContext.currentFlowId, ${e}_callContext.fixFlag= false, ${r})`,yieldWrapper:`\n function* ${e}_generatorWrapper() {\n return (${r} = ${i}, hudWrappedCallerIndex.value--, hudCurrentFlowId = "", ${e}_callContext.fixFlag = true, ${r} = yield ${r}, hudWrappedCaller[++hudWrappedCallerIndex.value] = ${e}_functionId, hudCurrentFlowId = ${e}_callContext.currentFlowId, ${e}_callContext.fixFlag= false, ${r})\n }`,yieldStarWrapper:`\n function* ${e}_generatorWrapper() {\n return (${r} = ${i}, hudWrappedCallerIndex.value--, hudCurrentFlowId = "", ${e}_callContext.fixFlag = true, ${r} = yield* ${r}, hudWrappedCaller[++hudWrappedCallerIndex.value] = ${e}_functionId, hudCurrentFlowId = ${e}_callContext.currentFlowId, ${e}_callContext.fixFlag= false, ${r})\n }`,initialStatements:s,bodyPlaceholder:o,functionIdPlaceholder:n,awaitablePlaceholder:i,fixStackFunction:`${e}_fixStack(${e}_functionId, ${e}_callContext);`,asyncIteratorWrapper:`${e}_asyncIteratorWrapper`,awaitableVariable:r}}function y(e,t){const r=e.trim().split("\n"),o=r[r.length-1].trim();if(/\/\/# sourceMappingURL=data:application\/json[^;]+;base64,.+$/.test(o))return!0;const n=/\/\/# sourceMappingURL=(.+\.map)$/.exec(o);if(n){const e=h.default.resolve(t,n[1]);return u.existsSync(e)}return!1}t.initHudSampleTable=function(){globalThis.hudSampleTable=[];const e=[[10,1],[30,2],[100,3],[500,11],[1e3,23],[5e3,53]];let t=0;for(const[r,o]of e){for(let e=t;e<r;e++)globalThis.hudSampleTable.push(e%o==0);t=r}},t.edit=function(e,t){const r=Error.prepareStackTrace;let o=!1,n=function(e){const t=e.match(`${f.default.bundlerBuildIdVarName}="${m.source}"`);if(t&&t.length>0)return t[1]}(e);n||(n=function(e){return(0,l.v5)(e,f.default.bundlerBuildUuidNamespace)}(e),o=!0);const i=(0,l.v5)(e,f.default.functionUuidNamespace);let s=null;if("babel"===f.default.codegenMode){const r=g.myRequire.resolve(`${f.default.hudModuleName}/plugin`);s=a.transformSync(e,{sourceMaps:!0,filename:t.filename,babelrc:!1,configFile:!1,plugins:[[r,{data:t,bundlerBuildId:n,prefix:f.default.wrapVarPrefix,..._(f.default.wrapVarPrefix,t.format)}]]})}else{if("swc"!==f.default.codegenMode)throw d.instrument_logger.error("Invalid codegenMode",f.default.codegenMode),new Error("Invalid codegenMode");{const r=g.myRequire.resolve(`${f.default.hudModuleName}/swc-plugin`);s=c.transformSync(e,{sourceMaps:!0,filename:t.filename,swcrc:!1,configFile:!1,caller:{name:"hud",meta:{}},jsc:{parser:{syntax:"ecmascript"},experimental:{plugins:[[r,{data:t,bundlerBuildId:n,prefix:f.default.wrapVarPrefix,..._(f.default.wrapVarPrefix,t.format),uuidNamespace:f.default.functionUuidNamespace,fileHash:i}]],disableBuiltinTransformsForInternalTesting:!0,cacheRoot:__dirname}}})}}if(Error.prepareStackTrace=r,!s||!s.code||!s.map)throw d.instrument_logger.error("Failed generating ast",t),new Error("Failed generating ast");return d.instrument_logger.info(`Successfully transformed ${t.filename}`),{code:s.code,map:s.map,filename:t.filename,hasInputMap:y(e,h.default.dirname(t.filename)),bundlerBuildId:n,bundlerBuildIdGenerated:o}}},6121:function(e,t,r){"use strict";var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.AsyncFunction=t.extractUuidFromFunction=void 0;const n=o(r(1019));t.extractUuidFromFunction=function(e){if("function"!=typeof e)return;const t=e.toString().match(`${n.default.wrapVarPrefix}_functionId = "([a-f0-9-]+)"`);return!t||t.length<2?void 0:t[1]},t.AsyncFunction=(async()=>{}).constructor},7697:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.extractEndpointsFromRouter=void 0;const a=r(1377),c=r(2119),u=r(2119),l=r(7668),d=s(r(1019)),f=i(r(6982)),p=r(6538),h=r(331),g=r(8054);class m extends l.FrameworkPatcher{static hudRoutes=Symbol.for(d.default.express.routeNamesVarName);static layerState=Symbol.for(d.default.express.layerStateVarName);static hudMarked=Symbol.for(d.default.express.markedVarName);_patch(e){return this._patchRoute(e.Route),this._patchUse(e.application),this._patchUse(e.Router),this._patchAll(e.application),a.instrument_logger.info("Patched express successfully"),e}_patchUse(e){const t=e.use;e.use=function(e){const r=t.apply(this,arguments);try{if((this._router||this.stack&&this.stack.length>0&&"query"===this.stack[0].name)&&((o=this._router?this._router:this)[m.hudMarked]||(globalThis.hudExpressState.push(o),o[m.hudMarked]=!0)),!this.stack)return r;const{path:t,offset:n}=function(e){let t=0,r="/";if("function"!=typeof e){let o=e;for(;Array.isArray(o)&&0!==o.length;)o=o[0];"function"!=typeof o&&(t=1,r=e)}return{path:r,offset:t}}(e),i=g(Array.prototype.slice.call(arguments,n));for(let e=0;e<i.length&&e<this.stack.length;e++){const r=this.stack[this.stack.length-e-1];"router"===r.name&&(r[m.hudRoutes]=t)}}catch(e){a.instrument_logger.error("Failed to patch express.use function",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}var o;return r},(0,c.copyPropertiesToTarget)(t,e.use)}_patchRoute(e){r(1214).concat("all").forEach((function(t){const r=e.prototype[t];e.prototype[t]=function(){let e;try{e=g(Array.prototype.slice.call(arguments));let r=function(e){const t=e[0][m.layerState];if(t)return t.flowId}(e);if(Array.isArray(this.path)&&!r){y(e,void 0);for(const e of this.path)r=f.randomUUID(),_(this,r,t,e)}else if(Array.isArray(this.path)&&Array.isArray(r)){y(e,void 0);for(let e=0;e<this.path.length;e++)_(this,r[e],t,this.path[e])}else r?Array.isArray(r)&&(r=r[0]):r=f.randomUUID(),y(e,r),_(this,r,t,this.path)}catch(e){a.instrument_logger.error("Failed to patch express.Route.route",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return r.apply(this,e||arguments)},(0,c.copyPropertiesToTarget)(r,e.prototype[t])}))}_patchAll(e){const t=e.all;e.all=function(){try{if(arguments.length<2)return t.apply(this,arguments);const e=Array.prototype.slice.call(arguments);if(e[1][m.layerState]={flowId:[]},Array.isArray(e[0]))for(const t of e[0]){const t=f.randomUUID();e[1][m.layerState].flowId.push(t)}else e[1][m.layerState].flowId.push(f.randomUUID());const r=t.apply(this,e);try{delete e[1][m.layerState]}catch(e){}return r}catch(e){a.instrument_logger.error("Failed to patch express.application.all",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t.apply(this,arguments)},(0,c.copyPropertiesToTarget)(t,e.all)}}function _(e,t,r,o){!function(e,t,r,o){e[m.layerState]||(e[m.layerState]={}),e[m.layerState][t]?e[m.layerState][t].methods.push(r):e[m.layerState][t]={layerPath:o,methods:[r]}}(e,t,r,o),function(e,t,r){const o=new p.EndpointDeclaration(e,[t],"express",void 0,void 0,r);(0,p.storeEndpointDeclaration)(o)}(t,r,o)}function y(e,t){if(e&&!(e.length<1)){if(d.default.express.wrapAllCallbacks)for(let r=0;r<e.length;r++){const o=(0,u.wrapFlow)(v(t),e[r],b);e[r]=o}else{const r=(0,u.wrapFlow)(v(t),e[e.length-1],b);e[e.length-1]=r}return t}}function v(e){return e?function(){return e}:function(e){const t=e[0]?.route[m.layerState],r=e[0]?.url;if(t)for(const[e,o]of Object.entries(t)){if(o.layerPath instanceof RegExp&&o.layerPath.test(r))return e;if(r.includes(o.layerPath))return e}a.instrument_logger.warn("No flowId found for path",{states:t,url:r.split("?")[0]})}}function b(e,t,r){let o=0;if(4===r.length)o=1;else if(3!==r.length)return void a.instrument_logger.error("Invalid number of arguments in express request",{length:r.length});if(!r[o])return void a.instrument_logger.error("No request object in express request");const n=r[o][h.metricSymbol];n?n.setFlowId(e):a.instrument_logger.error("No endpoint metric found in express request")}function w(e,t){const r=[];for(const[o,n]of Object.entries(e.route[m.layerState]))r.push(new p.EndpointDeclaration(o,n.methods,"express",t,n.layerPath));return Array.from(r.values())}t.default=m,t.extractEndpointsFromRouter=function e(t,r){let o=[];if(!r.stack)return a.instrument_logger.error("Router without stack - bad OTEL version",{router:r}),o;for(const n of r.stack)if("router"===n.name){if(!n[m.hudRoutes]){a.instrument_logger.error("Router layer without routes",{layer:n});continue}const r=t+n[m.hudRoutes];o=o.concat(e(r,n.handle))}else n.route&&n.route[m.layerState]&&(o=o.concat(w(n,t)));return o}},7668:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.FrameworkPatcher=void 0;const s=r(9896),a=i(r(6928)),c=r(1377),u=r(8064);t.FrameworkPatcher=class{patch(e,t,r){const o=function(e){try{const t=(0,s.readFileSync)(a.join(e,"package.json"),{encoding:"utf8"}),r=JSON.parse(t).version;return"string"==typeof r?r:""}catch(t){c.instrument_logger.info("Failed extracting version",{baseDir:e})}return""}(t);return function(e,t){return""===e||u.satisfies(u.coerce(e),t)}(o,r)?this._patch(e):(c.instrument_logger.warn("Unsupported version",{framework:this.constructor.name,version:o,supportedVersion:r,basedir:t}),e)}}},9788:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=i(r(6982)),c=r(1377),u=r(7668),l=s(r(1019)),d=r(2119),f=r(2119),p=r(878),h=r(6257),g=r(7868),m=r(6530),_=r(938);class y extends u.FrameworkPatcher{static graphQLPatchedSymbol=Symbol.for(l.default.hudPatchedName);_patch(e){return this.patchGraphql(e),c.instrument_logger.info("Patched GraphQL successfully"),e}patchGraphql(e){const t=e.execute;e.execute=function(e){!function(e){try{e&&!e[y.graphQLPatchedSymbol]&&(v(e._queryType),v(e._mutationType),e[y.graphQLPatchedSymbol]=!0,c.instrument_logger.info("Patched GraphQL schema successfully"))}catch(e){c.instrument_logger.error("Failed to patch GraphQL schema",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}(e.schema);const r=process.hrtime.bigint();return function(e,t,r){return"function"==typeof e.then?e.then((e=>((0,m.saveDocumentMetadata)(t,r),e))):((0,m.saveDocumentMetadata)(t,r),e)}(t.apply(this,arguments),e.document,r)},(0,d.copyPropertiesToTarget)(t,e.execute)}}function v(e){if(!e)return;const t=e._fields;Object.keys(t).forEach((r=>{const o=t[r];!function(e,t,r){if(e.resolve&&!e.resolve[y.graphQLPatchedSymbol]){const o=a.randomUUID();(0,h.storeResolverDeclaration)({id:o,operation:t,name:r});const n=e.resolve;e.resolve=(0,f.wrapFlow)(k,n,((e,t)=>{const r=_.GraphQLMetric.createUsableMetric();r.start(),r.setFlowId(e),t.flowMetric=r}),((e,t)=>{const r=t.flowMetric;r?r.end():c.instrument_logger.warn("No flowMetric found for resolver",{flowId:e})}),((e,t)=>{const r=t.flowMetric;r?r.end():c.instrument_logger.warn("No flowMetric found for resolver",{flowId:e})})),e.resolve[y.graphQLPatchedSymbol]=!0,(0,g.storeResolverIdBySelectionName)(o,r)}}(o,p.GraphQLSupportedOperations[e.name.toLowerCase()],r),o.type._fields&&w(o.type)}))}t.default=y;const b=new WeakSet;function w(e){e&&e._fields&&!b.has(e)&&(b.add(e),Object.keys(e._fields).forEach((t=>{const r=e._fields[t];if(!r||!r.type)return;!function(e){const t=e.resolve;t&&!e.resolve[y.graphQLPatchedSymbol]&&(e.resolve=(0,f.wrapFlow)(k,t),e.resolve[y.graphQLPatchedSymbol]=!0)}(r);let o=r.type;for(;o.ofType;)o=o.ofType;w(o)})))}function k(e){if(void 0===e[2]||void 0===e[3])return void c.instrument_logger.warn("GraphQL resolver arguments are unknown",{args:e});const t=e[3].path;if(t&&!t.prev){const r=t.key,o=(0,g.getResolverIdBySelectionName)(r);return e[2][y.graphQLPatchedSymbol]=o,o}if(e[2][y.graphQLPatchedSymbol])return e[2][y.graphQLPatchedSymbol];c.instrument_logger.warn("GraphQL No functionId found for resolver",{args:e})}},6530:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.saveDocumentMetadata=t.getDocumentsMetadata=void 0;const s=r(1377),a=i(r(6982));t.getDocumentsMetadata=function(){const e=c;return c=[],e},t.saveDocumentMetadata=function(e,t){try{new u(e,Number(process.hrtime.bigint()-t)).save()}catch(e){s.instrument_logger.error("Failed to save document metadata",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}};let c=[];class u{name;timeTook;hash;selectionNames;constructor(e,t){this.name=e.definitions[0]?.name?.value,this.hash=a.createHash("sha256").update(e.loc?.source?.body).digest("hex"),this.selectionNames=e.definitions.flatMap((e=>e.selectionSet.selections.map((e=>e.name.value)))),this.timeTook=t}save(){c.push(this)}}},6257:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.storeResolverDeclaration=t.getResolversDeclarations=void 0;let r=[];t.getResolversDeclarations=function(){const e=r;return r=[],e},t.storeResolverDeclaration=function(e){r.push(e)}},7868:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getResolverIdBySelectionName=t.storeResolverIdBySelectionName=void 0;const r=new Map;t.storeResolverIdBySelectionName=function(e,t){r.set(t,e)},t.getResolverIdBySelectionName=function(e){return r.get(e)}},405:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const o=r(1377),n=r(2119),i=r(7668),s=r(2847),a=r(331);class c extends i.FrameworkPatcher{_patch(e){return this._patchEmit(e),o.instrument_logger.info("Patched http successfully"),e}_patchEmit(e){const t=e.Server.prototype.emit;e.Server.prototype.emit=function(e,...r){if("request"!==e)return t.apply(this,[e,...r]);try{const e=r[0],t=r[1],n=s.HttpEndpointMetric.createUsableMetric();n.start(),n.setRequestAttributes(e),t.once("finish",(function(){try{n.setResponseAttributes(t),n.end()}catch(e){o.instrument_logger.error("Failed to set response attributes",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}})),e[a.metricSymbol]=n}catch(e){o.instrument_logger.error("Failed to patch http.Server.prototype.emit",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t.apply(this,[e,...r])},(0,n.copyPropertiesToTarget)(t,e.Server.prototype.emit)}}t.default=c},2680:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0});const s=r(1377),a=r(2119),c=r(2119),u=r(7668),l=r(5202),d=i(r(6982)),f=r(6842),p=r(331);class h extends u.FrameworkPatcher{_patch(e){return this._patchConsumer(e),s.instrument_logger.info("Patched KafkaJS successfully"),e}_patchConsumer(e){const t=e.Kafka.prototype.consumer;e.Kafka.prototype.consumer=function(...e){const r=t.apply(this,e);try{const t=new Map,o=[],n=[];!function(e,t){const r=e.subscribe;e.subscribe=async function(...e){const o=await r.apply(this,e);try{const r=e[0].topics;r?r.forEach((e=>{t.push(e)})):e[0].topic?t.push(e[0].topic):s.instrument_logger.warn("No topic found in KafkaJS.Consumer.subscribe",{args:e[0]})}catch(e){s.instrument_logger.error("Error in patching KafkaJS.Consumer.subscribe",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return o},(0,a.copyPropertiesToTarget)(r,e.subscribe)}(r,n),function(e,t,r,o,n){const i=e.run;function u(e,i){const a="eachBatch"===i;for(const e of n)y(e,o,t,r,i);const u=function(e,t,r){return o=>{const n=o[0],i=r?n.batch.topic:n.topic;return function(e,t,r,o){const n=e.get(_(r,o));if(n)return n;for(const e of t)if(e.isBatch===o&&e.pattern.test(r))return e.flowId;s.instrument_logger.warn("No flowId found for topic",{topicName:r,isBatch:o})}(e,t,i,r)}}(t,r,a),l=function(e){return(t,r,o)=>{const n=f.KafkaJSMetric.createUsableMetric();n.start(),n.setFlowId(t);const i=o[0];void 0!==i&&void 0!==i.message&&(i.message[p.metricSymbol]=n);const s=e?i.batch.partition:i.partition,a=e?i.batch.messages[0]?.timestamp:i.message?.timestamp;n.addPartition(s),n.addProducedTimestamp(a),r.flowMetric=n}}(a),d=(0,c.wrapFlow)(u,e[i],l,g,m);e[i]=d}e.run=async function(...e){try{const t=e[0];t.eachMessage&&u(t,"eachMessage"),t.eachBatch&&u(t,"eachBatch")}catch(e){s.instrument_logger.error("Error in patching KafkaJS.Consumer.run",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return await i.apply(this,e)},(0,a.copyPropertiesToTarget)(i,e.run)}(r,t,o,e[0].groupId,n)}catch(e){s.instrument_logger.error("Error in patching KafkaJS.Consumer",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return r},(0,a.copyPropertiesToTarget)(t,e.Kafka.prototype.consumer)}}function g(e,t){const r=t.flowMetric;r?r.end():s.instrument_logger.warn("No flowMetric found for message",{flowId:e})}function m(e,t,r){const o=t.flowMetric;if(!o)return void s.instrument_logger.warn("No flowMetric found for message",{flowId:e});const n=r instanceof Error?r.message:r;o.setError(n),o.end()}function _(e,t){return e+"|"+t}function y(e,t,r,o,n){const i=d.randomUUID(),s={flow_id:i,topic_name:e.toString(),group_id:t,pulling_type:n};(0,l.storeKafkaJSTopicDeclaration)(s),function(e,t,r,o,n){"string"==typeof r?e.set(_(r,o),n):t.push({pattern:r,isBatch:o,flowId:n})}(r,o,e,"eachBatch"===n,i)}t.default=h},5202:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.storeKafkaJSTopicDeclaration=t.getKafkaJSTopics=void 0;let r=[];t.getKafkaJSTopics=function(){const e=r;return r=[],e},t.storeKafkaJSTopicDeclaration=function(e){r.push(e)}},7436:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(1377),c=r(2119),u=r(2119),l=r(7668),d=r(6538),f=s(r(1019)),p=i(r(6982)),h=r(331);class g extends l.FrameworkPatcher{static koaModuleName="koa";static koaPatchedSymbol=Symbol.for(f.default.hudPatchedName);_patch(e){return this._patchAppUse(e),a.instrument_logger.info("Patched koa successfully"),e}_patchAppUse(e){const t=e.prototype.use;e.prototype.use=function(e){const r=t.apply(this,arguments);try{if(!arguments[0].router)return r;const e=arguments[0].router.stack;for(let t=0;t<e.length;t++)g._wrapRoute(e[t])}catch(e){a.instrument_logger.error("Failed to patch koa.use function",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return r},(0,c.copyPropertiesToTarget)(t,e.prototype.use)}static _wrapRoute(e){if(e.methods&&0===e.methods.length)return;const t=p.randomUUID();if(!e.stack[0][g.koaPatchedSymbol]){const t=(0,u.wrapFlow)(b,e.stack[0],m);e.stack[0]=t,e.stack[0][g.koaPatchedSymbol]=!0}(0,d.storeEndpointDeclaration)(new d.EndpointDeclaration(t,e.methods,"koa",void 0,e.path));for(const r of e.methods)v(t,e.path,r)}}function m(e,t,r){if(!r[0])return void a.instrument_logger.error("No ctx object found in koa");const o=r[0].req;if(!o)return void a.instrument_logger.error("No req found in koa ctx");const n=o[h.metricSymbol];n?n.setFlowId(e):a.instrument_logger.error("No endpoint metric found in koa req")}function _(e,t){return e+"|"+t}t.default=g;const y=new Map;function v(e,t,r){y.set(_(t,r),e)}function b(e){if(0===e.length)return;const t=e[0]._matchedRoute,r=e[0].req?.method;return function(e,t){return y.get(_(e,t))}(t,r)}},1973:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.generateKey=t.getRequestByCallback=void 0,r(1321);const o=r(1377),n=r(2119),i=r(7668),s=new Map;function a(e,t){const r=Reflect.getMetadata("path",t)??Reflect.getMetadata("microservices:pattern",t);if(!r)return void o.instrument_logger.error("No callback path found on callback",{callback:t});const n=e.constructor.CONTROLLER_ID;if(n)return`${n}.${r}`;o.instrument_logger.error("No controller id found on controller",{controller:e})}t.getRequestByCallback=function(e){const t=s.get(e);return t&&s.delete(e),t},t.generateKey=a;class c extends i.FrameworkPatcher{_patch(e){return this._patchIntercept(e),o.instrument_logger.info("Patched NestJS intercept successfully"),e}_patchIntercept(e){const t=e.InterceptorsConsumer.prototype.intercept;e.InterceptorsConsumer.prototype.intercept=async function(...e){return function(e){try{const t=e[2],r=e[3];if("function"==typeof t.constructor&&"function"==typeof r){let o;if("rpc"===e[5])o=e[1][1].args[0];else if(o=e[1][0],!o||o.raw)return;const n=a(t,r);if(!n)return;s.set(n,o)}else o.instrument_logger.error("Invalid args in NestJS InterceptorsConsumer.intercept",{args:e})}catch(e){o.instrument_logger.error("Error in NestJS intercept patcher",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}(e),await t.apply(this,e)},(0,n.copyPropertiesToTarget)(t,e.InterceptorsConsumer.prototype.intercept)}}t.default=c},436:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const o=r(1377),n=r(2119),i=r(2119),s=r(7668),a=r(331),c=r(1973);class u extends s.FrameworkPatcher{_patch(e){return this._patchCreate(e),o.instrument_logger.info("Patched NestJS RouterExecutionContext successfully"),e}_patchCreate(e){const t=e.RouterExecutionContext.prototype.create;e.RouterExecutionContext.prototype.create=function(...e){try{const t=e[0],r=e[1];if("function"==typeof t.constructor&&"function"==typeof r){const n=(0,c.generateKey)(t,r);n&&(e[1]=(0,i.wrapFlow)((()=>{try{const e=(0,c.getRequestByCallback)(n);if(!e)return void o.instrument_logger.error("No request object found for key",{key:n});const t=function(e){if(e&&!e.raw&&e.socket)return e[a.metricSymbol]?e[a.metricSymbol].getFlowId?e[a.metricSymbol].getFlowId():void o.instrument_logger.error("No getFlowId function found on metric object"):void o.instrument_logger.error("No metric found on nestjs request object")}(e);return t||o.instrument_logger.error("No flow id found for key",{key:n}),t}catch(e){o.instrument_logger.error("Error in NestJS getFlowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}),r))}else o.instrument_logger.error("Invalid args in NestJS RouterExecutionContext.create",{args:e})}catch(e){o.instrument_logger.error("Error in NestJS RouterExecutionContext patcher",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t.apply(this,e)},(0,n.copyPropertiesToTarget)(t,e.RouterExecutionContext.prototype.create)}}t.default=u},7636:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const o=r(1377),n=r(2119),i=r(2119),s=r(7668),a=r(331),c=r(1973);class u extends s.FrameworkPatcher{_patch(e){return this._patchCreate(e),o.instrument_logger.info("Patched NestJS RpcContextCreator successfully"),e}_patchCreate(e){const t=e.RpcContextCreator.prototype.create;e.RpcContextCreator.prototype.create=function(...e){try{const t=e[0],r=e[1];if("function"==typeof t.constructor&&"function"==typeof r){const n=(0,c.generateKey)(t,r);n&&(e[1]=(0,i.wrapFlow)((()=>{try{const e=(0,c.getRequestByCallback)(n);if(!e)return void o.instrument_logger.error("No msg object found for key",{key:n});const t=function(e){if(e)return e[a.metricSymbol]?e[a.metricSymbol].getFlowId?e[a.metricSymbol].getFlowId():void o.instrument_logger.error("No getFlowId function found on metric object"):void o.instrument_logger.error("No metric found on nestjs msg object")}(e);return t||o.instrument_logger.error("No flow id found for key",{key:n}),t}catch(e){o.instrument_logger.error("Error in NestJS getFlowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}),r))}else o.instrument_logger.error("Invalid args in NestJS RpcContextCreator.create",{args:e})}catch(e){o.instrument_logger.error("Error in NestJS RpcContextCreator patcher",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t.apply(this,e)},(0,n.copyPropertiesToTarget)(t,e.RpcContextCreator.prototype.create)}}t.default=u},3976:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.patchRequire=t.patchCompile=t.patch=t.shouldSupportSourceMap=t.supportSourceMapInstall=void 0;const s=i(r(9896)),a=i(r(6928)),c=r(1377),u=r(2243),l=r(7022),d=r(1019),f=r(9063),p=r(2676),h=r(9514),g=function(){const e=d.hudConfig.hudModuleName;try{return a.dirname(a.dirname(p.myRequire.resolve(e)))}catch(t){return c.instrument_logger.error("Failed to resolve own path",{moduleName:e,msg:t instanceof Error?t.message:void 0,stack:t instanceof Error?t.stack:void 0}),null}}();function m(e){return!!globalThis.HudRetrieveFileCache.has(e)&&globalThis.HudRetrieveFileCache.get(e)}function _(){r(6093).install({handleUncaughtExceptions:!1,hookRequire:!1,environment:"node",retrieveFile:m})}function y(){return!(!d.hudConfig.supportSourceMap.enable||d.hudConfig.supportSourceMap.skipOnNodeFlag&&process.execArgv.includes("--enable-source-maps")&&(c.instrument_logger.warn("Not enabling source-map-support since --enable-source-maps is set"),1))}function v(e,t,r,o){let n=e;try{if(r===l.Format.esm&&!o)throw new h.HudError("MessagePort is required for patching ESM modules");if(!function(e){return e.includes("node_modules")&&!function(e){for(const t of b)if(t(e))return!0;return!1}(e)||e.includes(".yarn")?(c.instrument_logger.debug("Skipping non-monitored imported module",{filename:e}),!0):!(g&&!e.includes(g))&&(c.instrument_logger.debug("Skipping hud internal module",{filename:e}),!0)}(t)&&e.length<=d.hudConfig.maxWrappedFileSize){const i=(0,u.edit)(e,{filename:t,format:r});c.instrument_logger.debug("Patched",{filename:t}),o?o.postMessage({key:"HudModulePatch",hudPatched:t,hudProcessedFiles:i}):(globalThis.hudPatched.add(t),globalThis.hudProcessedFiles.push(i)),n=function(e,t){let r;return void 0===t?e:(r="string"==typeof t||t instanceof String?Buffer.from(t.toString()).toString("base64"):Buffer.from(JSON.stringify(t)).toString("base64"),e+`\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${r}`)}(i.code,i.map),d.hudConfig.writePatched&&function(e,t){const r=a.parse(e);let o=`${r.dir}/patched.${r.base}`;r.dir.includes("dist")&&(o=a.join(`${r.dir.replace("dist","patched")}`,r.base)),s.existsSync(a.dirname(o))||s.mkdirSync(a.dirname(o),{recursive:!0}),s.writeFileSync(o,t,"utf8"),c.instrument_logger.debug("Dumped patched file",{filename:e,patchedPath:o})}(t,n)}}catch(e){c.instrument_logger.error("Failed to patch",{filename:t,format:r,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return n}t.supportSourceMapInstall=_,t.shouldSupportSourceMap=y,t.patch=v,t.patchCompile=function(){!function(){try{let e;try{const t=process.env.SWC_BINARY_PATH;t&&c.instrument_logger.info("Using SWC binary path",{swcBinaryPath:t}),e=(0,p.myRequire)("@swc/core/binding");const r=e.getTargetTriple();r?c.instrument_logger.info("swc/core/binding installed",{triple:r}):c.instrument_logger.info("swc/core/binding not installed well")}catch(e){c.instrument_logger.info("swc/core/binding not installed")}(0,p.myRequire)("@swc/wasm")===e&&c.instrument_logger.info("binding and wasm are the same"),c.instrument_logger.info("swc/wasm bindings installed")}catch(e){c.instrument_logger.info("swc/wasm bindings not installed")}}();const e=r(3339),t=y();if(0!==Object.keys(globalThis.hudLoadedModules).length)return void c.instrument_logger.warn("PatchCompile ran twice, weird...");globalThis.hudLoadedModules=Object.keys(p.myRequire.cache);const o=e.prototype._compile;e.prototype._compile=function(e,r){c.instrument_logger.verbose("Compiling requirement",{filename:r});const n=v(e,r,l.Format.cjs);return t&&globalThis.HudRetrieveFileCache.set(r,n),o.call(this,n,r)},c.instrument_logger.debug("Patched _compile"),t&&_()},t.patchRequire=function(){new f.Hook(Array.from(d.hudConfig.frameworksToPatch.keys()),{internals:!0},((e,t,o)=>{try{const n=d.hudConfig.frameworksToPatch.get(t);return n?(new(0,r(1306)(`./${n.patcher}`).default)).patch(e,o,n.version):e}catch(e){c.instrument_logger.error("Failed to patch framework",{name:t,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return e}))};const b=[];for(const e of d.hudConfig.monitorNodeModules)b.push((t=>!(!t.includes(`node_modules/${e}`)||t.includes(`node_modules/${e}/node_modules`))))},8891:(e,t)=>{"use strict";function r(e){return e instanceof Error?e.constructor?e.constructor.name:e.name?e.name:"Non-Deducible-Name-Exception":"Non-Error-Exception"}function o(e=0){const t=Error.stackTraceLimit,r=Error.prepareStackTrace;let o=[];try{Error.stackTraceLimit=4+e,Error.prepareStackTrace=(t,r)=>{const n=r.slice(1+e);return o=n,n},(new Error).stack}finally{Error.stackTraceLimit=t,Error.prepareStackTrace=r}const n="processTicksAndRejections"!==o[0].getFunctionName()?0:1;let i;o[n]&&(i={name:o[n].getFunctionName(),file:o[n].getFileName(),line:o[n].getLineNumber(),column:o[n].getColumnNumber(),enclosingLine:o[n].getEnclosingLineNumber()});const s=o[n+1]&&"processTicksAndRejections"!==o[n+1].getFunctionName()?n+1:n+2;let a;return o[s]&&(a={name:o[s].getFunctionName(),file:o[s].getFileName(),line:o[s].getLineNumber(),column:o[s].getColumnNumber(),enclosingLine:o[s].getEnclosingLineNumber()}),[i,a]}Object.defineProperty(t,"__esModule",{value:!0}),t.fixStack=t.wrapperFinally=t.wrapperCatch=t.wrapperInitial=t.asyncIteratorWrapper=t.getCallsites=t.extractName=void 0,t.extractName=r,t.getCallsites=o;class n{iterator;n;constructor(e){this.iterator=e,this.n=e.next}static AsyncFromSyncIteratorContinuation(e){if(Object(e)!==e)return Promise.reject(new TypeError(e+" is not an object."));const t=e.done;return Promise.resolve(e.value).then((function(e){return{value:e,done:t}}))}next(...e){return n.AsyncFromSyncIteratorContinuation(this.n.call(this.iterator,...e))}return(e){const t=this.iterator.return;return void 0===t?Promise.resolve({value:e,done:!0}):n.AsyncFromSyncIteratorContinuation(t.call(this.iterator,e))}throw(e){const t=this.iterator.throw;return void 0===t?Promise.reject(e):n.AsyncFromSyncIteratorContinuation(t.call(this.iterator,e))}[Symbol.asyncIterator](){return this}}t.asyncIteratorWrapper=function(e){if(e&&e[Symbol.asyncIterator])return e[Symbol.asyncIterator]();if(e&&e[Symbol.iterator])return new n(e[Symbol.iterator]());if(e&&e["@@asyncIterator"])return e["@@asyncIterator"]();if(e&&e["@@iterator"])return e["@@iterator"]();throw new TypeError("Object is not async iterable")},t.wrapperInitial=function(e,t){const r=t.wrappedCaller=hudWrappedCaller[hudWrappedCallerIndex.value],o=hudCalls[e]??={},n=o[r]??={},i=n[hudCurrentFlowId]??={count:0,lastSentCounter:0,sampledCount:0,sum:0,exceptions:{},squareSum:0,sketch:null,isLinkedFunction:!1},s=i.count++;(t.sample_flag=2===hudRunningMode&&(s>=5e3?s%103==0:hudSampleTable[s]))&&(t.start=process.hrtime.bigint()),hudShouldLinkFunction&&(hudShouldLinkFunction=!1,i.isLinkedFunction=!0),t.currentFlowId=hudCurrentFlowId,hudWrappedCaller[++hudWrappedCallerIndex.value]=e},t.wrapperCatch=function(e,t,n){const i=t.end=process.hrtime.bigint(),s=r(n),[a,c]=o(1),u=hudCalls[e][t.wrappedCaller][t.currentFlowId];(u.exceptions[s]??=[]).push({caller:c,duration:t.start?Number(i-t.start):void 0})},t.wrapperFinally=function(e,t){if(t.fixFlag||hudWrappedCallerIndex.value--,t.sample_flag){const r=process.hrtime.bigint(),o=Number(r-t.start);if(o>0){const r=hudCalls[e][t.wrappedCaller][t.currentFlowId];r.sampledCount++,r.sum+=o,r.squareSum+=o*o,null===r.sketch?r.sketch=hudManager.newSketchDataWithValue(o):hudManager.add(r.sketch,o)}}},t.fixStack=function(e,t){t.fixFlag&&(hudWrappedCaller[++hudWrappedCallerIndex.value]=e,hudCurrentFlowId=t.currentFlowId,t.fixFlag=!1)}},2119:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.copyPropertiesToTarget=t.wrapFlow=void 0;const o=r(765),n=r(6121),i=r(1377);function s(e,t){const r=Object.getOwnPropertyDescriptors(e),o=Reflect.ownKeys(r);Object.setPrototypeOf(t,e),o.forEach((e=>{try{Object.defineProperty(t,e,r[e])}catch(e){}}))}t.wrapFlow=function(e,t,r,a,c){let u;return u=t instanceof n.AsyncFunction?async function(...n){let s;try{s=e(n)}catch(e){i.instrument_logger.error("Failed to get flowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}if(!s||hudRunningMode!==o.HudRunningMode.enabled)return await t.apply(this,n);hudCurrentFlowId=s,hudShouldLinkFunction=!0;const u={};if(r)try{r(s,u,n)}catch(e){i.instrument_logger.error("Failed to execute beforeCallbackHook",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}try{const e=t.apply(this,n);hudCurrentFlowId="";const r=await e;if(a)try{a(s,u)}catch(e){i.instrument_logger.error("Failed to execute afterCallbackHook",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return r}catch(e){if(c)try{c(s,u,e)}catch(e){i.instrument_logger.error("Failed to execute catchCallbackHook",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}throw e}finally{hudCurrentFlowId="",hudShouldLinkFunction=!1}}:function(...n){let s;try{s=e(n)}catch(e){i.instrument_logger.error("Failed to get flowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}if(!s||hudRunningMode!==o.HudRunningMode.enabled)return t.apply(this,n);hudCurrentFlowId=s,hudShouldLinkFunction=!0;const u={};if(r)try{r(s,u,n)}catch(e){i.instrument_logger.error("Failed to execute beforeCallbackHook",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}try{const e=t.apply(this,n);if(a)if(e instanceof Promise)e.then((()=>{try{a(s,u)}catch(e){i.instrument_logger.error("Failed to execute afterCallbackHook",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}));else try{a(s,u)}catch(e){i.instrument_logger.error("Failed to execute afterCallbackHook",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return e}catch(e){if(c)try{c(s,u,e)}catch(e){i.instrument_logger.error("Failed to execute catchCallbackHook",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}throw e}finally{hudCurrentFlowId="",hudShouldLinkFunction=!1}},s(t,u),u},t.copyPropertiesToTarget=s},1377:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.worker_logger=t.instrument_logger=t.app_logger=t.customer_logger=t.SafeLogger=t.renewFileTransports=t.getSavedLogs=t.getLogPath=t.WorkerPortTransport=void 0;const a=i(r(857)),c=i(r(6928)),u=i(r(5124)),l=i(r(9896)),d=i(r(6982)),f=r(1019),p=s(r(1620)),h=process.env.HUD_DEBUG?f.hudConfig.logger.debug:process.env.HUD_VERBOSE?f.hudConfig.logger.verbose:f.hudConfig.logger.default;class g extends p.default{_messeagesToSend=[];messagesLimit=f.hudConfig.loggerWorkerPortSizeLimit;messageDropCount=0;getMessagesToSend(){if(!this._messeagesToSend.length)return!1;const e=this._messeagesToSend;this.clearMessagesToSend();const t=this.messageDropCount;return this.messageDropCount=0,{logsBuf:this.formatMessagesToSend(e),messageDropCount:t}}clearMessagesToSend(){this._messeagesToSend=[]}formatMessagesToSend(e){return e.map((e=>JSON.stringify(e))).join("\n")}log(e,t){this._messeagesToSend.length>=this.messagesLimit?this.messageDropCount++:this._messeagesToSend.push(e),t()}}t.WorkerPortTransport=g;const m=u.format.combine(u.format.timestamp({format:"HH:mm:ss.SSS"}),u.format.printf((({level:e,message:t,timestamp:r,label:o,...n})=>{try{const i=Object.keys(n).length;let s;if(i)if(1===i){const e=Object.keys(n)[0];s=`${t} ${e}: ${JSON.stringify(n[e],null,2)}`}else s=`${t}\n${JSON.stringify(n,null,2)}`;else s=t;const a=u.format.colorize().colorize(e,e.toUpperCase());return`[${r}]${(o?`(${o})`:"").padEnd(8," ")} ${a}: ${s}`}catch(e){return t}})));function _(){return u.format.combine(u.format.label({label:"app"}),u.format.timestamp({format:()=>(new Date).toISOString()}),u.format.json())}function y(e){return{filename:w(),level:h.levels[e],format:_(),lazy:!1}}function v(){if(f.hudConfig.logDirectory)return f.hudConfig.logDirectory;const e=a.homedir();switch(a.platform()){case"darwin":return c.join(e,"Library","Logs","hud");case"win32":return c.join(e,"AppData","hud","Logs");default:return c.join(e,".hud","logs")}}let b;function w(){return b??=c.join(v(),`${d.randomUUID()}.log`)}t.getLogPath=w,t.getSavedLogs=function(){const e=[];for(const[t,r]of Object.entries(k))for(const t of r.transports)try{if(t instanceof g){const o=t.getMessagesToSend();if(!o)continue;const{logsBuf:n,messageDropCount:i}=o;i&&r.info(`Dropped ${i} messages`),e.push(n)}}catch(e){r.error("Failed to get saved logs",e)}return e},t.renewFileTransports=function(){const e=new Date,t=new Set;for(const[r,o]of Object.entries(k)){const r=[],n=[];for(const i of o.transports)if(i instanceof u.transports.File){i.close&&i.close(),r.push(i),n.push(new u.transports.File({level:i.level,format:i.format,filename:c.join(i.dirname,i.filename),lazy:!1}));const o=c.join(v(),`${d.randomUUID()}-${e.toISOString().replaceAll(":","")}.log`);l.existsSync(c.join(i.dirname,i.filename))&&(l.renameSync(c.join(i.dirname,i.filename),o),t.add(o))}for(const e of r)o.remove(e);for(const e of n)o.add(e)}return t};const k={};class S{name;logger;constructor(e){this.name=e;try{this.logger=function(e){const t=[];h.console&&t.push(new u.transports.Console({format:u.format.combine(u.format.label({label:e}),m)}));let r=!1;try{const r=y(e),o=c.dirname(r.filename);l.mkdirSync(o,{recursive:!0}),l.writeFileSync(r.filename,"",{flag:"w"}),t.push(new u.transports.File(r))}catch{const e=_(),o=new g({format:e});t.push(o),r=!0}const o=u.createLogger({level:h.levels[e],transports:t});return k[e]=o,r&&o.info("Could not create file transport, fallback succesfully to worker port"),o}(e)}catch(e){this.logger=void 0}}isValid(){return!!this.logger}log(e,t,...r){this.logger&&this.logger.log(e,t,...r)}error(e,...t){this.log("error",e,...t)}warn(e,...t){this.log("warn",e,...t)}info(e,...t){this.log("info",e,...t)}http(e,...t){this.log("http",e,...t)}verbose(e,...t){this.log("verbose",e,...t)}debug(e,...t){this.log("debug",e,...t)}silly(e,...t){this.log("silly",e,...t)}}t.SafeLogger=S,t.customer_logger=u.createLogger({level:f.hudConfig.customerLoggerLevel,transports:[new u.transports.Console],format:u.format.printf((({message:e})=>{try{return`Hud: ${e}`}catch(t){return e}}))}),t.app_logger=new S("app"),t.instrument_logger=new S("instrument"),t.worker_logger=new S("worker")},398:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.loopLogProcessPerformance=t.getCpuLimit=t.getCpuLimitUnsafe=t.loopLogThreadPerformance=void 0;const a=r(2987),c=s(r(857)),u=i(r(1493)),l=r(1765),d=r(9896),f=r(1954);function p(e){e.info("Trying to detect CPU limit");try{const t=(0,d.readFileSync)("/sys/fs/cgroup/cpu/cpu.cfs_quota_us","utf8"),r=(0,d.readFileSync)("/sys/fs/cgroup/cpu/cpu.cfs_period_us","utf8");return e.info("CPU limit detected for cgroups v1",{cpuQuota:t,cpuPeriod:r}),parseInt(t.toString())/parseInt(r.toString())}catch(t){try{const t=(0,d.readFileSync)("/sys/fs/cgroup/cpu.max","utf8"),[r,o,n]=t.trim().split(" ");return e.info("CPU limit detected for cgroups v2",{max:r,period:o}),r&&o?"max"===r?"unlimited":parseInt(r)/parseInt(o):void e.info("cpu.max file is not in the expected format",t)}catch(r){return void e.info("Failed to detect CPU limit",{e:t,e2:r})}}}t.loopLogThreadPerformance=async function(e,t,r){let o=a.performance.eventLoopUtilization(),n=a.performance.nodeTiming.toJSON();for await(const i of(0,l.unrefSetInterval)(t,void 0,{signal:r}))try{const t=a.performance.eventLoopUtilization(),r=a.performance.eventLoopUtilization(t,o);o=t;const i=u.getHeapStatistics(),s=a.performance.nodeTiming.toJSON(),c=s.idleTime-n.idleTime,l=s.duration-n.duration,d=c/l;n=s,e.info("thread performance statistics",{thread_elu_percentage:100*r.utilization,memory:{thread_heap_utilization_percentage:i.total_heap_size/i.heap_size_limit*100},idleTime:c,totalTime:l,idleTimePercentage:d})}catch(t){e.error("Failed logging thread performance statistics",{msg:t instanceof Error?t.message:void 0,stack:t instanceof Error?t.stack:void 0})}},t.getCpuLimitUnsafe=p,t.getCpuLimit=(0,f.suppressTraces)(p),t.loopLogProcessPerformance=async function(e,r,o){const n=c.default.totalmem(),i=(0,t.getCpuLimit)(e);let s=process.cpuUsage();for await(const t of(0,l.unrefSetInterval)(r,void 0,{signal:o}))try{const t=process.memoryUsage(),o=process.uptime(),a=process.cpuUsage(s);s=process.cpuUsage();let c=(a.user+a.system)/(1e3*r);i&&"number"==typeof i&&(c/=i),e.info("process performance statistics",{memory:{process_memory_rss:t.rss,process_memory_utilization_percentage:t.rss/n*100},cpu:100*c,cpuStats:{limit:i,usagePercentage:100*c},uptime:o})}catch(t){e.error("Failed logging process performance statistics",{msg:t instanceof Error?t.message:void 0,stack:t instanceof Error?t.stack:void 0})}}},6701:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.safeCall=void 0;const o=r(9514);t.safeCall=function(e,t){return t.catch((t=>{(0,o.isAbortError)(t)||e.error("Unhandled exception on async task",{msg:t instanceof Error?t.message:void 0,stack:t instanceof Error?t.stack:void 0})}))}},1954:function(e,t,r){"use strict";var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.suppressTraces=void 0;const n=o(r(1019)),i=r(1377),s=r(2676);let a,c;try{const e=(0,s.myRequire)("@opentelemetry/api"),t=(0,s.myRequire)("@opentelemetry/core");a=e.context,c=t.suppressTracing,i.app_logger.info("OpenTelemetry exists",{suppressConfig:n.default.suppressTraces})}catch(e){i.app_logger.info("OpenTelemetry api/core does not exist")}t.suppressTraces=function(e){return function(...t){return n.default.suppressTraces&&a&&c?(i.app_logger.debug("Running with Suppressed traces"),a.with(c(a.active()),(()=>e(...t)))):e(...t)}}},1765:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.unrefSetInterval=t.unrefSetTimeout=t.unrefSetImmediate=void 0;const s=i(r(6460));t.unrefSetImmediate=function(e,t){return s.setImmediate(e,{...t,ref:!1})},t.unrefSetTimeout=function(e,t,r){return s.setTimeout(e,t,{...r,ref:!1})},t.unrefSetInterval=function(e,t,r){return s.setInterval(e,t,{...r,ref:!1})}},2676:(e,t)=>{"use strict";let r;Object.defineProperty(t,"__esModule",{value:!0}),t.myRequire=void 0;try{r=require}catch(e){r=void 0}t.myRequire=r},1306:(e,t,r)=>{var o={"./express":7697,"./express.ts":7697,"./frameworkPatcher":7668,"./frameworkPatcher.ts":7668,"./graphql":9788,"./graphql.ts":9788,"./graphql/metadata":6530,"./graphql/metadata.ts":6530,"./graphql/resolversDeclarations":6257,"./graphql/resolversDeclarations.ts":6257,"./graphql/resolversMapping":7868,"./graphql/resolversMapping.ts":7868,"./http":405,"./http.ts":405,"./kafkajs":2680,"./kafkajs.ts":2680,"./kafkajs/topicsDeclarations":5202,"./kafkajs/topicsDeclarations.ts":5202,"./koa":7436,"./koa.ts":7436,"./nestjsInterceptor":1973,"./nestjsInterceptor.ts":1973,"./nestjsRouterExecutionContext":436,"./nestjsRouterExecutionContext.ts":436,"./nestjsRpcContextCreator":7636,"./nestjsRpcContextCreator.ts":7636};function n(e){var t=i(e);return r(t)}function i(e){if(!r.o(o,e)){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}return o[e]}n.keys=function(){return Object.keys(o)},n.resolve=i,e.exports=n,n.id=1306},5809:e=>{"use strict";e.exports=require("./config")},6346:e=>{"use strict";e.exports=require("@babel/core")},6093:e=>{"use strict";e.exports=require("@cspotcode/source-map-support")},143:e=>{"use strict";e.exports=require("@swc/core")},8054:e=>{"use strict";e.exports=require("array-flatten")},1214:e=>{"use strict";e.exports=require("methods")},1321:e=>{"use strict";e.exports=require("reflect-metadata")},9063:e=>{"use strict";e.exports=require("require-in-the-middle")},8064:e=>{"use strict";e.exports=require("semver")},3903:e=>{"use strict";e.exports=require("uuid")},5124:e=>{"use strict";e.exports=require("winston")},1620:e=>{"use strict";e.exports=require("winston-transport")},6982:e=>{"use strict";e.exports=require("crypto")},9896:e=>{"use strict";e.exports=require("fs")},3339:e=>{"use strict";e.exports=require("module")},857:e=>{"use strict";e.exports=require("os")},6928:e=>{"use strict";e.exports=require("path")},2987:e=>{"use strict";e.exports=require("perf_hooks")},932:e=>{"use strict";e.exports=require("process")},6460:e=>{"use strict";e.exports=require("timers/promises")},1493:e=>{"use strict";e.exports=require("v8")},8167:e=>{"use strict";e.exports=require("worker_threads")}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,r),i.exports}return r.c=t,r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r(r.s=7729)})()));
|
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(global,(()=>(()=>{var e={5009:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.SketchData=void 0,t.SketchData=class extends Array{indexShift=0;constructor(){super()}}},1582:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.SketchManager=void 0;const o=r(5009);t.SketchManager=class{binWidth;logBinWidth;constructor(e){this.binWidth=e,this.logBinWidth=Math.log(e)}binIndex(e){return Math.floor(Math.log(e)/this.logBinWidth)}indexToBinStart(e){return this.binWidth**e}newSketchDataWithValue(e){const t=this.binIndex(e),r=new o.SketchData;return r.indexShift=t,r[0]=1,r}add(e,t){const r=this.binIndex(t);let o=r-e.indexShift;o<0?(e.unshift(...new Array(-o).fill(0)),e.indexShift=r,o=r-e.indexShift):o>=e.length&&e.push(...new Array(o-e.length+1).fill(0)),e[o]+=1}zero(e){e.fill(0)}copy(e){const t=new o.SketchData;return t.indexShift=e.indexShift,t.push(...e),t}mergeIntoNoChecks(e,t){const r=t.indexShift-e.indexShift;for(let o=0;o<t.length;o++)e[o+r]+=t[o]}mergeInto(e,t){t.indexShift<e.indexShift&&(e.unshift(...new Array(e.indexShift-t.indexShift).fill(0)),e.indexShift=t.indexShift),t.indexShift+t.length>e.indexShift+e.length&&e.push(...new Array(t.indexShift+t.length-(e.indexShift+e.length)).fill(0)),this.mergeIntoNoChecks(e,t)}mergeMany(e){if(0===e.length)throw new Error("Cannot merge empty list of SketchData.");if(1===e.length)return this.copy(e[0]);let t=1/0,r=-1/0;for(const o of e)t=Math.min(t,o.indexShift),r=Math.max(r,o.indexShift+o.length-1);const n=new o.SketchData;n.indexShift=t,n.push(...new Array(r-t+1).fill(0));for(const t of e)this.mergeIntoNoChecks(n,t);return n}getQuantile(e,t){const r=e.reduce(((e,t)=>e+t),0);if(0===r)throw new Error("Cannot get quantile of empty SketchData.");const o=r*t;let n,i=0;for(n=0;n<e.length&&(i+=e[n],!(i>=o));n++);const s=this.indexToBinStart(n+e.indexShift),a=(i-o)/e[n];return s*this.binWidth**(1-a)}encode(e){return{binWidth:this.binWidth,indexShift:e.indexShift,data:Array.from(e)}}decode(e){if(e.binWidth!==this.binWidth)throw new Error(`Should not decode sketch data with bin width ${e.binWidth} using SketchManager with bin width ${this.binWidth}.`);const t=new o.SketchData;return t.indexShift=e.indexShift,t.push(...e.data),t}}},6601:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||o(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),n(r(5009),t),n(r(1582),t)},8878:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.init=t.safeLog=void 0;const s=r(713),a=r(1377),c=i(r(6495)),u=r(8167),l=r(9514);t.safeLog=function(e){try{a.app_logger.info(e)}catch(e){return}},function(){if(u.isMainThread){if(a.app_logger.info("HUD is required"),(0,s.initGlobals)(),!c.isSupportedNodeVersion())return void a.customer_logger.log(l.UserLogs.UnsupportedNodeVersion());c.onRequire()}}(),t.init=c.default},1019:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||o(t,e,r)},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(r(5809));n(r(5809),t),t.default=s.default},3343:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.updateDynamicConfig=void 0;const o=r(1019);t.updateDynamicConfig=function(e,t,r){let n;const i=o.HudDynamicConfigSchema.partial().safeParse(e);return i.success?n={...t.dynamicConfig,...i.data}:(r.error("Dynamic configuration not updated - Invalid configuration override",{remoteConfigParseResult:i}),n=t.dynamicConfig),n}},9720:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.resetCallers=t.prepCalls=t._liftExceptions=void 0;const o=r(1377);function n(e){const t={};for(const r in e){const o=new Map;e[r].forEach((e=>{const t=JSON.stringify(e.caller);o.has(t)?o.get(t).count++:o.set(t,{caller:e.caller,count:1})})),t[r]=Array.from(o.values())}return t}t._liftExceptions=n,t.prepCalls=function(e,t){const r=(new Date).toISOString(),i=[];return Object.entries(hudCalls).map((([s,a])=>{Object.entries(a).forEach((([a,c])=>{Object.entries(c).forEach((([c,u])=>{try{if(0===u.sampledCount)return;const o=n(u.exceptions),l={function_id:s,wrapped_flow_id:c||void 0,wrapped_caller_id:a||void 0,timestamp:r,timeslice:e,exceptions:o,count:u.count-u.lastSentCounter,sampled_count:u.sampledCount,sum_duration:u.sum,sum_squared_duration:u.squareSum,sketch:u.sketch?t.encode(u.sketch):void 0,is_linked_function:u.isLinkedFunction};i.push(l),function(e){e.lastSentCounter=e.count,e.sampledCount=0,e.sum=0,e.squareSum=0,e.sketch=null,e.exceptions={}}(u)}catch(e){o.app_logger.error("Failed preparing invocation, skipping",{func:s,wrappedCaller:a,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}))}))})),i},t.resetCallers=function(){for(const t in globalThis.hudCalls)for(const r in globalThis.hudCalls[t])for(const o in globalThis.hudCalls[t][r])(e=globalThis.hudCalls[t][r][o]).lastSentCounter-=e.count,e.count=0;var e}},4268:function(e,t,r){"use strict";var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.MainThread=void 0;const n=r(8167),i=r(1377),s=o(r(7674)),a=o(r(1019)),c=r(2676),u=r(3343),l=r(9514);t.MainThread=class{apiKey;service;startTime;messenger;constructor(e,t,r){this.apiKey=e,this.service=t,this.startTime=r}async start(){if(n.isMainThread){try{this.messenger=await this._createMessenger(),await this._initDynamicConfig()}catch(e){const t=e instanceof Error?e.message:void 0;if(e instanceof l.HudSessionThrottle)throw e;throw i.app_logger.error("Failed to starting worker",{msg:t}),e}await this.messenger.start()}}async _createMessenger(){const e=c.myRequire.resolve(`${a.default.hudModuleName}/worker`),t=new n.Worker(e,{workerData:{apiKey:this.apiKey,service:this.service,startTime:this.startTime}});let r;try{r=new s.default(t),await r.checkWorker(a.default.workerTimeout)}catch(e){if(e instanceof l.HudSessionThrottle)throw i.app_logger.info("Worker started in idle mode - session throttled"),e;throw i.app_logger.error("Worker failed to start",{msg:e instanceof Error?e.message:void 0}),e}finally{t.unref()}return r}async _initDynamicConfig(){const e=await(this.messenger?.getRemoteConfig());e?(i.app_logger.info("Remote configuration exists"),a.default.dynamicConfig=(0,u.updateDynamicConfig)(e,a.default,i.app_logger),i.app_logger.info("Current dynamic configuration:",{currentDynamicConfig:a.default.dynamicConfig})):i.app_logger.info("No remote configuration - falling back to default dynamic configuration",{defaultDynamicConfig:a.default.dynamicConfig})}async terminateMessenger(){await(this.messenger?.terminateWorker()),this.messenger?.stop()}}},7674:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=i(r(1377)),c=i(r(6460)),u=s(r(1019)),l=r(765),d=r(1765),f=r(6601),p=r(9720),h=r(398),g=r(713),m=r(9514),v=r(6701),_=r(732),y=r(6538),b=r(331),w=r(6495),k=r(6257),S=r(6530),C=r(5202),E=r(1954),M=r(2676),P=a.app_logger,x=v.safeCall.bind(v.safeCall,P);function O(){const e=globalThis.hudProcessedFiles;return globalThis.hudProcessedFiles=[],e}t.default=class{worker;abortController;workerKeepaliveGuard;constructor(e){this.worker=e,this.abortController=new AbortController,this.worker.on("error",this.handleWorkerError).unref(),this.workerKeepaliveGuard=new _.WorkerKeepaliveGuard(e,u.default.communicationKeepaliveGrace)}handleWorkerError=e=>{try{e?.code===(new m.HudClientUnauthorizedError).code&&a.customer_logger.error(m.UserLogs.ApyKeyDenied()),P.error("Error from worker, stopping hud",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0}),(0,m.setFirstError)(e?.code),this.stop(),(0,w._detachHud)()}catch(e){P.error("Error stopping hud",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}};stop(){this.abortWorker(),u.default.communicationKeepalive&&this.workerKeepaliveGuard.stop(),this.abortController.abort(),this.abortController=new AbortController,(0,g.resetGlobals)()}abortWorker(){this._sendObject("Abort",{})}async restart(e){this.stop(),globalThis.hudRunningMode=e,await this.start()}_sendArray(e,t){t.length>0&&(this._sendObject(e,t),P.debug("sent data to worker",{msg:e,size:t.length}))}_sendObject(e,t){const r={msg:e,content:t};this.worker.postMessage(r)}async checkWorker(e){let t;try{t=await this.getMessageFromWorker("initialized",e,!0)}catch(r){if(!(r instanceof m.HudTimeoutError))throw r;t=await this.getMessageFromWorker("initialized",e/2,!1)}if("initialized"!==t?.msg||void 0===t?.content)throw new m.HudInitError("Worker not initialized");if(t?.content.status===l.HudSessionInitStatus.throttled)throw new m.HudSessionThrottle;if(t?.content.status!==l.HudSessionInitStatus.success)throw new m.HudInitError("Worker not initialized successfully")}async start(){switch(u.default.communicationKeepalive&&this.workerKeepaliveGuard.start(),globalThis.hudRunningMode){case l.HudRunningMode.enabled:P.info("Enabled mode"),x(this.getMode()),x(this.startPeriodicTasks()),x(this.pumpFunctions()),x(this.periodicSendEndpoints()),x(this.periodicSendFlowMetrics()),x(this.periodicSendGarphQL()),x(this.periodicSendKafkaJS()),x(this.resetCallerCounters()),x(this.sendLogsPeriodically(u.default.logsSendInterval)),x(this.sendRuntime()),x(this.sendPatchedModules()),x(this.sendPreloadedModules()),x(this.dumpModulesAfterWhile(6e4)),x((0,h.loopLogThreadPerformance)(P,u.default.logPerfInterval,this.abortController.signal));break;case l.HudRunningMode.disabled:P.info("Disabled mode"),x(this.getMode());break;case l.HudRunningMode.detached:P.info("Detached"),await this.terminateWorker(),this.stop();break;default:P.error("Running mode not handled")}}async getMessageFromWorker(e,t,r=!1,o){let n;const i=new AbortController,s=()=>{i.abort()};this.abortController.signal.addEventListener("abort",s);const a=c.setTimeout(t,void 0,{signal:i.signal,ref:r}),u=t=>{try{t.msg===e&&(n=t,i.abort(),P.info("Received message from worker (canceling timeout)",t))}catch(e){P.error("Failed handling message from worker",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}};this.worker.on("message",u).unref(),o&&this.worker.postMessage(o);try{throw await a,P.warn("Timeout waiting for message from worker"),new m.HudTimeoutError}catch(e){if(!(0,m.isAbortError)(e))throw(0,m.setFirstError)(e.code),e}finally{this.abortController.signal.removeEventListener("abort",s),this.worker.off("message",u)}return n}async getMode(){for await(const e of(0,d.unrefSetInterval)(u.default.modeInterval,void 0,{signal:this.abortController.signal}))try{const e={msg:"GetMode",content:{startTime:globalThis.hudStartTime,runningMode:globalThis.hudRunningMode}},t=await this.getMessageFromWorker(e.msg,u.default.workerMessageTimeout,!1,e);if(t?.msg!==e.msg||void 0===t?.content.mode){P.error("Unexpected message from worker",t);continue}t.content.mode!==globalThis.hudRunningMode&&await this.restart(t?.content.mode)}catch(e){P.error("Failed getting mode from worker",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}async getRemoteConfig(){const e="initDynamicConfig";try{const t=await this.getMessageFromWorker(e,u.default.workerMessageTimeout,!0);if(t?.msg!==e||void 0===t?.content)throw new Error(`Unexpected message from worker: ${t}`);return t?.content}catch(e){P.error("Failed getting remote configuration from worker",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}async resetCallerCounters(){const e=u.default.callerResetInterval;for await(const t of(0,d.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))try{P.info("Resetting caller",{interval:e}),(0,p.resetCallers)()}catch(e){P.error("Failed reseting caller counters",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}async pumpFunctions(){const e=u.default.dynamicConfig.aggregationInterval,t=new f.SketchManager(u.default.huddBinWidth);for await(const r of(0,d.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))try{const r=O(),o=(0,p.prepCalls)(e,t);this._sendArray("Invocations",o),this._sendArray("ProcessedFiles",r)}catch(e){P.error("Failed sending pumping functions to worker, skipping",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}await this.terminateWorker(),this.stop()}async periodicSendFlowMetrics(){const e=u.default.dynamicConfig.flowMetricInterval;for await(const t of(0,d.unrefSetInterval)(e,void 0,{signal:this.abortController.signal})){const t=(0,b.getFlowMetrics)().map((e=>e.toRaw())).filter((e=>e));t.length>0&&this._sendObject("FlowMetrics",{timeslice:e,rawMetrics:t})}}async periodicSendGarphQL(){const e=u.default.dynamicConfig.graphqlInterval;for await(const t of(0,d.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))this.sendGraphQLResolvers(),this.sendGraphQLDocuments()}async periodicSendKafkaJS(){const e=u.default.dynamicConfig.aggregationInterval;for await(const t of(0,d.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))try{const e=(0,C.getKafkaJSTopics)();this._sendArray("KafkaJSTopics",e)}catch(e){P.error("Failed sending KafkaJsTopics to worker, skipping",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}sendGraphQLResolvers(){try{const e=(0,k.getResolversDeclarations)().map((e=>({id:e.id,operation:e.operation,name:e.name})));this._sendArray("GraphQLResolvers",e)}catch(e){P.error("Failed sending resolvers to worker, skipping",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}sendGraphQLDocuments(){try{const e=(0,S.getDocumentsMetadata)().map((e=>({name:e.name,hash:e.hash,selection_names:e.selectionNames,time_took:e.timeTook})));this._sendArray("GraphQLDocuments",e)}catch(e){P.error("Failed sending documents to worker, skipping",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}async periodicSendEndpoints(){await(0,d.unrefSetTimeout)(u.default.endpointsFirstSendWaitTime,void 0,{signal:this.abortController.signal}),this.sendEndpoints();const e=u.default.endpointsInterval;for await(const t of(0,d.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))this.sendEndpoints()}sendEndpoints(){try{const e=(0,y.getEndpointDeclarations)().map((e=>({path:e.path,methods:e.methods,flow_id:e.flow_id,framework:e.framework,partial_path:e.partial_path})));this._sendArray("EndpointDeclaration",e)}catch(e){P.error("Failed sending endpoints to worker, skipping",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}async terminateWorker(){try{this.worker.off("error",this.handleWorkerError),await this.getMessageFromWorker("terminated",u.default.workerGrace,!1,{msg:"Terminate",content:u.default.workerGrace})}catch(e){if(!(e instanceof m.HudTimeoutError))throw P.error("Unexpected error, terminating worker"),await this.worker.terminate(),e;P.error("Grace period timeout, terminating worker"),await this.worker.terminate()}P.info("Worker terminated successfully.")}async sendRuntime(){const e={nodeVersion:process.version,nodeDependencyVersions:process.versions,platform:process.platform,architecture:process.arch,pid:process.pid,cwd:process.cwd(),execPath:process.execPath,execArgv:process.execArgv,argv:process.argv,uptime:process.uptime(),mainModulePath:r.c[r.s]?.filename};this._sendObject("Runtime",e)}async startPeriodicTasks(){this._sendObject("StartPeriodicTasks",{})}async sendPreloadedModules(){globalThis.hudLoadedModules?this._sendObject("PreInitLoadedModules",{modules:globalThis.hudLoadedModules}):P.warn("Didn't get module, weird....")}async dumpModulesAfterWhile(e){await(0,d.unrefSetTimeout)(e,void 0,{signal:this.abortController.signal});const t=Object.keys(M.myRequire.cache);this._sendObject("PostInitLoadedModules",{modules:t})}async sendPatchedModules(){if(!globalThis.hudPatched)return void P.error("Cant find patched modules");const e=Array.from(globalThis.hudPatched);this._sendObject("PatchedModules",{modules:e})}async sendLogsPeriodically(e){const t=(0,E.suppressTraces)(a.renewFileTransports);for await(const r of(0,d.unrefSetInterval)(e,void 0,{signal:this.abortController.signal}))try{const e=a.getSavedLogs();for(const t of e)try{this._sendObject("Logs",{logs:t})}catch(e){P.error("Failed send logs to worker",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}const r=t();r.size>0&&this._sendObject("LogFilename",{filenames:r})}catch(e){P.error("Failed send logs to worker",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}}},732:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.WorkerKeepaliveGuard=void 0;const s=i(r(1377)),a=r(765),c=s.app_logger;t.WorkerKeepaliveGuard=class{worker;keepaliveGrace;timeoutId=void 0;eventHandler=this.keepalive.bind(this);constructor(e,t){this.worker=e,this.keepaliveGrace=t}keepalive(e){try{if(e.msg!==a.KeepAliveMessage.msg)return;this._restartTimeout()}catch(e){c.error("Error in keepalive",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}_restartTimeout(){const e=setTimeout((()=>{}),this.keepaliveGrace);clearTimeout(this.timeoutId),this.timeoutId=e}start(){this.stop(),this.worker.on("message",this.eventHandler).unref()}stop(){void 0!==this.timeoutId&&clearTimeout(this.timeoutId),this.worker.off("message",this.eventHandler),this.timeoutId=void 0}}},7022:(e,t)=>{"use strict";var r;Object.defineProperty(t,"__esModule",{value:!0}),t.isSupportedFormat=t.Format=void 0,function(e){e.cjs="commonjs",e.esm="module"}(r||(t.Format=r={})),t.isSupportedFormat=function(e){return Object.values(r).includes(e)}},878:(e,t)=>{"use strict";var r;Object.defineProperty(t,"__esModule",{value:!0}),t.GraphQLSupportedOperations=void 0,function(e){e.query="query",e.mutation="mutation"}(r||(t.GraphQLSupportedOperations=r={}))},765:(e,t)=>{"use strict";var r,o;Object.defineProperty(t,"__esModule",{value:!0}),t.HudSessionInitStatus=t.HudRunningMode=t.KeepAliveMessage=void 0,t.KeepAliveMessage={msg:"keep-alive"},function(e){e[e.detached=0]="detached",e[e.disabled=1]="disabled",e[e.enabled=2]="enabled"}(r||(t.HudRunningMode=r={})),function(e){e[e.success=0]="success",e[e.throttled=1]="throttled"}(o||(t.HudSessionInitStatus=o={}))},9514:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.UserLogs=t.setFirstError=t.getFirstError=t.isAbortError=t.HudBadLoggerError=t.HudClientUnauthorizedError=t.HudTimeoutError=t.HudWorkloadCollectorError=t.HudAssert=t.HudUnsupportedError=t.HudEditError=t.HudWorkerError=t.HudClientError=t.HudSessionThrottle=t.HudInitError=t.HudError=void 0;class r extends Error{code=9e3;name=this.constructor.name;constructor(e){super(e)}}t.HudError=r;class o extends r{code=9001}t.HudInitError=o,t.HudSessionThrottle=class extends o{},t.HudClientError=class extends r{code=9002},t.HudWorkerError=class extends r{code=9003};class n extends r{code=9004}t.HudEditError=n,t.HudUnsupportedError=class extends n{code=9005},t.HudAssert=class extends n{code=9006},t.HudWorkloadCollectorError=class extends r{code=9007},t.HudTimeoutError=class extends r{code=9008},t.HudClientUnauthorizedError=class extends r{code=9009},t.HudBadLoggerError=class extends r{code=9101},t.isAbortError=function(e){return e instanceof Error&&"AbortError"===e.name};let i=9999;t.getFirstError=function(){return i},t.setFirstError=function(e){e&&9999===i&&(i=e)},t.UserLogs={HudEnableNotSet:e=>({level:"error",moreInfo:!0,message:`Did not load as HUD_ENABLE is ${void 0===e?"undefined":"set to a non-true value"}. Please set HUD_ENABLE=true to run Hud.`}),HudServiceNotSet:()=>({level:"error",errCode:"E1001",moreInfo:!0,message:"Can't load Hud, HUD_SERVICE was not set. Please set service name using the env var HUD_SERVICE."}),HudServiceInvalid:()=>({level:"error",errCode:"E1002",moreInfo:!0,message:"Can't load Hud, HUD_SERVICE value has invalid service name. Please set service name using the env var HUD_SERVICE."}),HudServiceInvalidInit:()=>({level:"error",errCode:"E1003",moreInfo:!0,message:"Can't load Hud, the provided service value is invalid. Please set a valid service name."}),HudApiKeyNotSet:()=>({level:"error",errCode:"E1004",moreInfo:!0,message:"Can't load Hud, HUD_KEY was not set. Please set API key using the env var HUD_KEY."}),HudApiKeyInvalid:()=>({level:"error",errCode:"E1005",moreInfo:!0,message:"Can't load Hud, HUD_KEY value has invalid API key. Please set a valid key in env var HUD_KEY."}),HudApiKeyInvalidInit:()=>({level:"error",errCode:"E1006",moreInfo:!0,message:"Can't load Hud, the provided key value is invalid. Please set a valid key."}),BothApiKeyAndServiceNotSet:()=>({level:"error",errCode:"E1007",moreInfo:!0,message:"Can't load Hud, HUD_KEY and HUD_SERVICE were not set. Please set API key using the env var HUD_KEY and service name using the env var HUD_SERVICE."}),InvalidTag:()=>({level:"warn",errCode:"E1008",moreInfo:!0,message:"HUD_TAGS should be of type Key-Value Object, defaulting to empty tags. Please set valid tags in env var HUD_TAGS."}),TagWithDots:()=>({level:"warn",errCode:"E1009",moreInfo:!0,message:"HUD_TAGS keys can't contain dots; they have been replaced with underscores."}),TagsInvalidJson:()=>({level:"warn",errCode:"E1010",moreInfo:!0,message:"Can't load Hud, HUD_TAGS is not a valid JSON, defaulting to empty tags. Please set valid tags in env var HUD_TAGS."}),ApyKeyDenied:()=>({level:"error",errCode:"E1011",moreInfo:!0,message:"Can't load Hud, the provided key is invalid. Please provide a valid key by either setting the HUD_KEY env var or passing it directly to the init function."}),ShutdownGracefully:e=>({level:"error",errCode:`E${e}`,message:"SDK has initiated a graceful shutdown. Your application remains unaffected"}),UnsupportedNodeVersion:()=>({level:"error",errCode:"E1012",moreInfo:!0,message:"Can't load Hud due to an unsupported node version."}),UnsupportedSyntax:()=>({level:"error",errCode:"E1014",moreInfo:!0,message:"Can't load Hud due to an unsupported syntax version."})}},6538:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.storeEndpointDeclaration=t.getEndpointDeclarations=t.EndpointDeclaration=void 0;const s=i(r(1377)),a=r(7697),c=s.app_logger;function u(e,t){return t?t instanceof RegExp?e+t.toString():("/"===t[t.length-1]&&t.length>1&&(t=t.slice(0,-1)),(t=e+t).replace(/\/{2,}/g,"/")):t}t.EndpointDeclaration=class{flow_id;methods;framework;partial_path;path;constructor(e,t,r,o,n,i){this.flow_id=e,this.methods=t,this.framework=r,this.partial_path=i,o||(o=""),this.path=u(o,n),this.partial_path=u(o,i)}},t.getEndpointDeclarations=function(){let e=[];globalThis.hudExpressState.forEach((t=>{try{e=e.concat((0,a.extractEndpointsFromRouter)("",t))}catch(e){c.error("Failed to extract endpoints from express",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}})),e=e.concat(d());const t=new Set;return e.forEach((e=>{e.partial_path||t.add(e.flow_id)})),e.filter((e=>!e.partial_path||!t.has(e.flow_id)&&(c.info("Partial endpoint without full endpoint",{endpoint:e}),!0)))};let l=[];function d(){const e=l;return l=[],e}t.storeEndpointDeclaration=function(e){l.push(e)}},2847:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HttpEndpointMetric=void 0;const o=r(331);class n extends o.FlowMetric{statusCode;route;method;constructor(e){super(e)}_createUsableMetric(e){return this}setRequestAttributes(e){this.route=e.url?.split("?")[0],this.method=e.method}setResponseAttributes(e){this.statusCode=e.statusCode}toRaw(){if(this.statusCode&&this.route&&this.method)return{flow_id:this.flowId,type:"EndpointMetric",duration:this.duration,status_code:this.statusCode,route:this.route,method:this.method}}}t.HttpEndpointMetric=n},331:function(e,t,r){"use strict";var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFlowMetrics=t.FlowMetric=t.metricSymbol=void 0;const n=o(r(932)),i=o(r(1019)),s=r(765);t.metricSymbol=Symbol(i.default.hudMetricName),t.FlowMetric=class{_state;flowId;duration;_startTime;constructor(e){this.flowId=e,this.duration=0,this._state="usable"}static createUsableMetric(e){return new this(e)._createUsableMetric(e)}setFlowId(e){this.flowId=e}getFlowId(){return this.flowId}start(){this._startTime=n.default.hrtime.bigint()}end(){this._startTime&&(this.duration=Number(n.default.hrtime.bigint()-this._startTime)),this.#e(),this._state="unusable"}#e(){hudRunningMode===s.HudRunningMode.enabled&&a.push(this)}};let a=[];t.getFlowMetrics=function(){const e=a;return a=[],e}},938:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.GraphQLMetric=void 0;const o=r(331);class n extends o.FlowMetric{constructor(e){super(e)}_createUsableMetric(e){return this}toRaw(){return{flow_id:this.flowId,type:"GraphQLMetric",duration:this.duration}}}t.GraphQLMetric=n},6842:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.KafkaJSMetric=void 0;const o=r(331),n=r(1377);class i extends o.FlowMetric{partition;error;producedTimestamp;totalConsumeDuration;constructor(e){super(e)}_createUsableMetric(e){return this}end(){super.end(),this.producedTimestamp&&(this.totalConsumeDuration=Number(Date.now()-this.producedTimestamp)*Number(1e6))}addProducedTimestamp(e){void 0!==e&&(this.producedTimestamp=Number(e))}addPartition(e){this.partition=e}setError(e){"string"==typeof e?this.error=e:n.instrument_logger.warn("Error message is not a string",{flowId:this.flowId,errorMessage:e})}toRaw(){if(void 0!==this.partition)return{flow_id:this.flowId,type:"KafkaJSMetric",duration:this.duration,partition:this.partition,error:this.error,total_consume_duration:this.totalConsumeDuration};n.instrument_logger.warn("No partition found for message",{flowId:this.flowId})}}t.KafkaJSMetric=i},713:function(e,t,r){"use strict";var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.hookMessageChannel=t.resetGlobals=t.initGlobals=void 0,r(1999);const n=r(765),i=r(6601),s=o(r(1019)),a=r(2243),c=r(8167);function u(){globalThis.hudProcessedFiles=[],globalThis.hudManager=new i.SketchManager(s.default.huddBinWidth),globalThis.hudWrappedCaller=new Array(1e3).fill(""),globalThis.hudWrappedCallerIndex={value:0},globalThis.hudLoadedModules={},globalThis.hudPatched=new Set,globalThis.HudRetrieveFileCache=new Map,globalThis.hudExpressState=[]}t.initGlobals=function(){globalThis.hudGlobalInitGuard||(globalThis.hudGlobalInitGuard=!0,globalThis.hudRunMutex=!1,globalThis.hudRanOnRequire=!1,globalThis.hudRanOnImport=!1,globalThis.hudInitGuard=void 0,globalThis.hudStartTime=new Date,globalThis.hudCalls={},globalThis.hudRunningMode=n.HudRunningMode.enabled,globalThis.hudCurrentFlowId="",globalThis.hudShouldLinkFunction=!1,(0,a.initHudSampleTable)(),u())},t.resetGlobals=u,t.hookMessageChannel=function(){const{port1:e,port2:t}=new c.MessageChannel;return e.on("message",(e=>{"HudModulePatch"===e.key?(globalThis.hudPatched.add(e.hudPatched),globalThis.hudProcessedFiles.push(e.hudProcessedFiles)):"HudRetrieveFileCache"===e.key&&globalThis.HudRetrieveFileCache.set(e.filename,e.content)})),e.unref(),globalThis.hudHookPort=e,t}},1999:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},7729:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.safeLog=t.init=t.asyncIteratorWrapper=t.fixStack=t.wrapperFinally=t.wrapperCatch=t.wrapperInitial=void 0;const o=r(9514),n=r(1377);r(1999);var i=r(8891);Object.defineProperty(t,"wrapperInitial",{enumerable:!0,get:function(){return i.wrapperInitial}}),Object.defineProperty(t,"wrapperCatch",{enumerable:!0,get:function(){return i.wrapperCatch}}),Object.defineProperty(t,"wrapperFinally",{enumerable:!0,get:function(){return i.wrapperFinally}}),Object.defineProperty(t,"fixStack",{enumerable:!0,get:function(){return i.fixStack}}),Object.defineProperty(t,"asyncIteratorWrapper",{enumerable:!0,get:function(){return i.asyncIteratorWrapper}});let s={};try{"true"===process.env.HUD_ENABLE?s=r(8878):n.customer_logger.log(o.UserLogs.HudEnableNotSet(process.env.HUD_ENABLE))}catch(e){}t.init=s.init||async function(e,t){},t.safeLog=s.safeLog||function(...e){}},6495:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.onRequire=t._detachHud=t.isHudEnabled=t.isSupportedNodeVersion=t.isValidParam=void 0;const o=r(9720),n=r(1377),i=r(4268),s=r(1019),a=r(3976),c=r(9514),u=r(765),l=r(6701),d=r(8167);let f;function p(e){return null!=e&&""!==e&&"string"==typeof e}function h(){const e=process.versions.node.split(".")[0];return!!s.hudConfig.supportedNodeVersions.includes(e)}function g(){return!(globalThis.hudRunningMode===u.HudRunningMode.detached||s.hudConfig.defaultOff&&(n.app_logger.info("hud is disabled by default"),"true"!==process.env.HUD_ENABLE||(n.app_logger.info("override! hud is enabled by env string"),0)))}function m(e=!0,t=!1){if(n.app_logger.warn("Detaching hud"),t||e&&hudRunningMode!==u.HudRunningMode.detached){const e=(0,c.getFirstError)();n.customer_logger.log(c.UserLogs.ShutdownGracefully(e))}globalThis.hudRunningMode=u.HudRunningMode.detached,f&&(0,l.safeCall)(n.app_logger,f.terminateMessenger()),(0,o.resetCallers)()}function v(){n.app_logger.warn("Init timeout disabling hud!"),n.customer_logger.error("SDK imported but not initialized. Please ensure to call 'hud.init()' to initialize the SDK."),m(!1)}t.default=async function(e,t){try{if(!d.isMainThread)return;if(globalThis.hudRunMutex)return void n.app_logger.warn("Already ran init!");if(globalThis.hudRunMutex=!0,clearTimeout(globalThis.hudInitGuard),!n.app_logger.isValid())return(0,c.setFirstError)((new c.HudBadLoggerError).code),void m(!0,!0);if(!g()||!h())return;if(!p(e)||void 0===e||"INVALID_API_KEY"===e)return n.app_logger.warn("Bad api-key provided"),s.hudConfig.disableOnBadApiKey&&m(!1),void n.customer_logger.log(c.UserLogs.HudApiKeyInvalidInit());if(!p(t)||void 0===t)return n.app_logger.warn("Invalid service provided"),s.hudConfig.disableOnBadServiceName&&m(!1),void n.customer_logger.log(c.UserLogs.HudServiceInvalidInit());n.app_logger.info("Initializing hud",{service:t}),f=new i.MainThread(e,t,globalThis.hudStartTime);try{await f.start(),n.customer_logger.info("Initialized successfully")}catch(e){e instanceof c.HudSessionThrottle?(n.customer_logger.info("Initialized successfully in idle mode."),m(!1,!1)):(n.app_logger.error("Init failed disabling hud",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0}),(0,c.setFirstError)(e.code),m())}}catch(e){try{n.app_logger.error("Something went wrong in init",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}catch(e){n.app_logger.error("Something went wrong in init & e.stack raised an exception")}m()}},t.isValidParam=p,t.isSupportedNodeVersion=h,t.isHudEnabled=g,t._detachHud=m,t.onRequire=function(){try{if(!n.app_logger.isValid())return void m(!1);if(globalThis.hudRanOnRequire)return void n.app_logger.warn("Already ran onRequire!");globalThis.hudRanOnRequire=!0;try{(0,a.patchCompile)()}catch(e){n.app_logger.error("Failed to patch compile",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}try{(0,a.patchRequire)()}catch(e){n.app_logger.error("Failed to patch require",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}globalThis.hudInitGuard=setTimeout(v,s.hudConfig.timeoutOnInit),globalThis.hudInitGuard.unref()}catch(e){n.app_logger.error("Something went wrong in onRequire",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}},2243:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.edit=t.initHudSampleTable=void 0;const a=i(r(6346)),c=i(r(9896)),u=r(3903),l=r(1377),d=s(r(1019)),f=r(7022),p=s(r(6928)),h=r(2676),g=/([0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12})/;function m(e,t){const r=`${e}_hudTemp`,o="BODY_PLACEHOLDER",n="FUNCTION_ID_PLACEHOLDER",i="AWAITABLE_PLACEHOLDER";let s;return s=t===f.Format.esm?[`import { createRequire as ${e}_createRequire } from "module";`,`const ${e}_require = ${e}_createRequire(import.meta.url);`,`const { wrapperInitial: ${e}_wrapperInitial, wrapperCatch: ${e}_wrapperCatch, wrapperFinally: ${e}_wrapperFinally, fixStack: ${e}_fixStack, safeLog: ${e}_logger, asyncIteratorWrapper: ${e}_asyncIteratorWrapper} = ${e}_require("${h.myRequire.resolve(d.default.hudModuleName)}");`,`${e}_logger('File loaded ' + import.meta.url);`]:[`const {wrapperInitial: ${e}_wrapperInitial, wrapperCatch: ${e}_wrapperCatch, wrapperFinally: ${e}_wrapperFinally, fixStack: ${e}_fixStack, safeLog: ${e}_logger, asyncIteratorWrapper: ${e}_asyncIteratorWrapper} = require("${h.myRequire.resolve(d.default.hudModuleName)}");`,`${e}_logger('File loaded ' + __filename);`],{functionWrapper:`{\n let ${r};\n const ${e}_functionId = ${n};\n const ${e}_callContext = {};\n ${e}_wrapperInitial(${e}_functionId, ${e}_callContext);\n try {\n ${o}\n } catch (e) {\n ${e}_wrapperCatch(${e}_functionId, ${e}_callContext, e);\n throw e;\n } finally {\n ${e}_wrapperFinally(${e}_functionId, ${e}_callContext);\n }\n }`,awaitWrapper:`(${r} = ${i}, hudWrappedCallerIndex.value--, hudCurrentFlowId = "", ${e}_callContext.fixFlag = true, ${r} = await ${r}, hudWrappedCaller[++hudWrappedCallerIndex.value] = ${e}_functionId, hudCurrentFlowId = ${e}_callContext.currentFlowId, ${e}_callContext.fixFlag= false, ${r})`,yieldWrapper:`\n function* ${e}_generatorWrapper() {\n return (${r} = ${i}, hudWrappedCallerIndex.value--, hudCurrentFlowId = "", ${e}_callContext.fixFlag = true, ${r} = yield ${r}, hudWrappedCaller[++hudWrappedCallerIndex.value] = ${e}_functionId, hudCurrentFlowId = ${e}_callContext.currentFlowId, ${e}_callContext.fixFlag= false, ${r})\n }`,yieldStarWrapper:`\n function* ${e}_generatorWrapper() {\n return (${r} = ${i}, hudWrappedCallerIndex.value--, hudCurrentFlowId = "", ${e}_callContext.fixFlag = true, ${r} = yield* ${r}, hudWrappedCaller[++hudWrappedCallerIndex.value] = ${e}_functionId, hudCurrentFlowId = ${e}_callContext.currentFlowId, ${e}_callContext.fixFlag= false, ${r})\n }`,initialStatements:s,bodyPlaceholder:o,functionIdPlaceholder:n,awaitablePlaceholder:i,fixStackFunction:`${e}_fixStack(${e}_functionId, ${e}_callContext);`,asyncIteratorWrapper:`${e}_asyncIteratorWrapper`,awaitableVariable:r}}function v(e,t){const r=e.trim().split("\n"),o=r[r.length-1].trim();if(/\/\/# sourceMappingURL=data:application\/json[^;]+;base64,.+$/.test(o))return!0;const n=/\/\/# sourceMappingURL=(.+\.map)$/.exec(o);if(n){const e=p.default.resolve(t,n[1]);return c.existsSync(e)}return!1}t.initHudSampleTable=function(){globalThis.hudSampleTable=[];const e=[[10,1],[30,2],[100,3],[500,11],[1e3,23],[5e3,53]];let t=0;for(const[r,o]of e){for(let e=t;e<r;e++)globalThis.hudSampleTable.push(e%o==0);t=r}},t.edit=function(e,t,r){const o=Error.prepareStackTrace;let n=!1,i=function(e){const t=e.match(`${d.default.bundlerBuildIdVarName}="${g.source}"`);if(t&&t.length>0)return t[1]}(e);i||(i=function(e){return(0,u.v5)(e,d.default.bundlerBuildUuidNamespace)}(e),n=!0);const s=(0,u.v5)(e,d.default.functionUuidNamespace);let c=null;if("babel"===d.default.codegenMode){const r=h.myRequire.resolve(`${d.default.hudModuleName}/plugin`);c=a.transformSync(e,{sourceMaps:!0,filename:t.filename,babelrc:!1,configFile:!1,plugins:[[r,{data:t,bundlerBuildId:i,prefix:d.default.wrapVarPrefix,...m(d.default.wrapVarPrefix,t.format)}]]})}else{if("swc"!==d.default.codegenMode)throw l.instrument_logger.error("Invalid codegenMode",d.default.codegenMode),new Error("Invalid codegenMode");{const o=h.myRequire.resolve(`${d.default.hudModuleName}/swc-plugin`);c=r(e,{sourceMaps:!0,filename:t.filename,swcrc:!1,configFile:!1,caller:{name:"hud",meta:{}},jsc:{parser:{syntax:"ecmascript"},experimental:{plugins:[[o,{data:t,bundlerBuildId:i,prefix:d.default.wrapVarPrefix,...m(d.default.wrapVarPrefix,t.format),uuidNamespace:d.default.functionUuidNamespace,fileHash:s}]],disableBuiltinTransformsForInternalTesting:!0,cacheRoot:__dirname}}})}}if(Error.prepareStackTrace=o,!c||!c.code||!c.map)throw l.instrument_logger.error("Failed generating ast",t),new Error("Failed generating ast");return l.instrument_logger.info(`Successfully transformed ${t.filename}`),{code:c.code,map:c.map,filename:t.filename,hasInputMap:v(e,p.default.dirname(t.filename)),bundlerBuildId:i,bundlerBuildIdGenerated:n}}},8466:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.getSWC=t.getNativeSignature=void 0;const s=i(r(6928)),a=i(r(9896)),c=r(2676),u=r(143);function l(){let e=!1;return"linux"===process.platform&&(e=function(){try{return a.readFileSync("/usr/bin/ldd","utf-8").includes("musl")}catch{return!1}}(),null===e&&(e=function(){const e="function"==typeof process.report?.getReport?JSON.parse(process.report?.getReport()||"null"):null;return!!e&&((!e.header||!e.header.glibcVersionRuntime)&&!(!Array.isArray(e.sharedObjects)||!e.sharedObjects.some(d)))}()),null===e&&(e=function(){try{return r(5317).execSync("ldd --version",{encoding:"utf8"}).includes("musl")}catch(e){return!1}}())),e??!1}function d(e){return e.includes("libc.musl-")||e.includes("ld-musl-")}function f(e){return"android"===process.platform?"arm64"===process.arch?"android-arm64":"arm"===process.arch?"android-arm-eabi":void e.error(`Unknown architecture on Android: ${process.arch}`):"win32"===process.platform?"x64"===process.arch?"win32-x64-msvc":"ia32"===process.arch?"win32-ia32-msvc":"arm64"===process.arch?"win32-arm64-msvc":void e.error(`Unknown architecture on Windows: ${process.arch}`):"darwin"===process.platform?"x64"===process.arch?"darwin-x64":"arm64"===process.arch?"darwin-arm64":void e.error(`Unknown architecture on macOS: ${process.arch}`):"freebsd"===process.platform?"x64"===process.arch?"freebsd-x64":"arm64"===process.arch?"freebsd-arm64":void e.error(`Unknown architecture on FreeBSD: ${process.arch}`):"linux"===process.platform?"x64"===process.arch?l()?"linux-x64-musl":"linux-x64-gnu":"arm64"===process.arch?l()?"linux-arm64-musl":"linux-arm64-gnu":"arm"===process.arch?"linux-arm-gnueabihf":"riscv64"===process.arch?l()?"linux-riscv64-musl":"linux-riscv64-gnu":"s390x"===process.arch?"linux-s390x-gnu":void e.error(`Unknown architecture on Linux: ${process.arch}`):void e.error(`Unknown OS: ${process.platform}, architecture: ${process.arch}`)}t.getNativeSignature=f,t.getSWC=function(e){try{const t=(0,c.myRequire)("@swc/core");return t.transformSync("console.log('hello')"),e.info("Using swc/core from node_modules"),t.transformSync}catch(t){e.warn("swc/core bindings not installed");const r=c.myRequire.resolve("@swc/core");if(!r)return void e.error("Couldn't get swc path");const o=f(e);if(!o)return void e.error("Couldn't get machine signature");const n=s.join(__dirname,`../swc_bindings_${o}_${u.version}/package/swc.${o}.node`);if(!a.existsSync(n))return void e.error("Couldn't find swc bindings",{bindingPath:n});if(process.env.SWC_BINARY_PATH)return void e.info("SWC_BINARY_PATH already set, not overriding");e.info("Setting SWC_BINARY_PATH",{bindingPath:n}),process.env.SWC_BINARY_PATH=n,delete c.myRequire.cache[r];let i=(0,c.myRequire)("@swc/core");try{i.transformSync("console.log('hello')")}catch(t){e.error("Couldn't require swc/core after setting SWC_BINARY_PATH",{msg:t instanceof Error?t.message:void 0,stack:t instanceof Error?t.stack:void 0}),i=void 0}return delete process.env.SWC_BINARY_PATH,i?.transformSync}}},6121:function(e,t,r){"use strict";var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.AsyncFunction=t.extractUuidFromFunction=void 0;const n=o(r(1019));t.extractUuidFromFunction=function(e){if("function"!=typeof e)return;const t=e.toString().match(`${n.default.wrapVarPrefix}_functionId = "([a-f0-9-]+)"`);return!t||t.length<2?void 0:t[1]},t.AsyncFunction=(async()=>{}).constructor},7697:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.extractEndpointsFromRouter=void 0;const a=r(1377),c=r(2119),u=r(2119),l=r(7668),d=s(r(1019)),f=i(r(6982)),p=r(6538),h=r(331),g=r(8054);class m extends l.FrameworkPatcher{static hudRoutes=Symbol.for(d.default.express.routeNamesVarName);static layerState=Symbol.for(d.default.express.layerStateVarName);static hudMarked=Symbol.for(d.default.express.markedVarName);_patch(e){return this._patchRoute(e.Route),this._patchUse(e.application),this._patchUse(e.Router),this._patchAll(e.application),a.instrument_logger.info("Patched express successfully"),e}_patchUse(e){const t=e.use;e.use=function(e){const r=t.apply(this,arguments);try{if((this._router||this.stack&&this.stack.length>0&&"query"===this.stack[0].name)&&((o=this._router?this._router:this)[m.hudMarked]||(globalThis.hudExpressState.push(o),o[m.hudMarked]=!0)),!this.stack)return r;const{path:t,offset:n}=function(e){let t=0,r="/";if("function"!=typeof e){let o=e;for(;Array.isArray(o)&&0!==o.length;)o=o[0];"function"!=typeof o&&(t=1,r=e)}return{path:r,offset:t}}(e),i=g(Array.prototype.slice.call(arguments,n));for(let e=0;e<i.length&&e<this.stack.length;e++){const r=this.stack[this.stack.length-e-1];"router"===r.name&&(r[m.hudRoutes]=t)}}catch(e){a.instrument_logger.error("Failed to patch express.use function",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}var o;return r},(0,c.copyPropertiesToTarget)(t,e.use)}_patchRoute(e){r(1214).concat("all").forEach((function(t){const r=e.prototype[t];e.prototype[t]=function(){let e;try{e=g(Array.prototype.slice.call(arguments));let r=function(e){const t=e[0][m.layerState];if(t)return t.flowId}(e);if(Array.isArray(this.path)&&!r){_(e,void 0);for(const e of this.path)r=f.randomUUID(),v(this,r,t,e)}else if(Array.isArray(this.path)&&Array.isArray(r)){_(e,void 0);for(let e=0;e<this.path.length;e++)v(this,r[e],t,this.path[e])}else r?Array.isArray(r)&&(r=r[0]):r=f.randomUUID(),_(e,r),v(this,r,t,this.path)}catch(e){a.instrument_logger.error("Failed to patch express.Route.route",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return r.apply(this,e||arguments)},(0,c.copyPropertiesToTarget)(r,e.prototype[t])}))}_patchAll(e){const t=e.all;e.all=function(){try{if(arguments.length<2)return t.apply(this,arguments);const e=Array.prototype.slice.call(arguments);if(e[1][m.layerState]={flowId:[]},Array.isArray(e[0]))for(const t of e[0]){const t=f.randomUUID();e[1][m.layerState].flowId.push(t)}else e[1][m.layerState].flowId.push(f.randomUUID());const r=t.apply(this,e);try{delete e[1][m.layerState]}catch(e){}return r}catch(e){a.instrument_logger.error("Failed to patch express.application.all",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t.apply(this,arguments)},(0,c.copyPropertiesToTarget)(t,e.all)}}function v(e,t,r,o){!function(e,t,r,o){e[m.layerState]||(e[m.layerState]={}),e[m.layerState][t]?e[m.layerState][t].methods.push(r):e[m.layerState][t]={layerPath:o,methods:[r]}}(e,t,r,o),function(e,t,r){const o=new p.EndpointDeclaration(e,[t],"express",void 0,void 0,r);(0,p.storeEndpointDeclaration)(o)}(t,r,o)}function _(e,t){if(e&&!(e.length<1)){if(d.default.express.wrapAllCallbacks)for(let r=0;r<e.length;r++){const o=(0,u.wrapFlow)(y(t),e[r],b);e[r]=o}else{const r=(0,u.wrapFlow)(y(t),e[e.length-1],b);e[e.length-1]=r}return t}}function y(e){return e?function(){return e}:function(e){const t=e[0]?.route[m.layerState],r=e[0]?.url;if(t)for(const[e,o]of Object.entries(t)){if(o.layerPath instanceof RegExp&&o.layerPath.test(r))return e;if(r.includes(o.layerPath))return e}a.instrument_logger.warn("No flowId found for path",{states:t,url:r.split("?")[0]})}}function b(e,t,r){let o=0;if(4===r.length)o=1;else if(3!==r.length)return void a.instrument_logger.error("Invalid number of arguments in express request",{length:r.length});if(!r[o])return void a.instrument_logger.error("No request object in express request");const n=r[o][h.metricSymbol];n?n.setFlowId(e):a.instrument_logger.error("No endpoint metric found in express request")}function w(e,t){const r=[];for(const[o,n]of Object.entries(e.route[m.layerState]))r.push(new p.EndpointDeclaration(o,n.methods,"express",t,n.layerPath));return Array.from(r.values())}t.default=m,t.extractEndpointsFromRouter=function e(t,r){let o=[];if(!r.stack)return a.instrument_logger.error("Router without stack - bad OTEL version",{router:r}),o;for(const n of r.stack)if("router"===n.name){if(!n[m.hudRoutes]){a.instrument_logger.error("Router layer without routes",{layer:n});continue}const r=t+n[m.hudRoutes];o=o.concat(e(r,n.handle))}else n.route&&n.route[m.layerState]&&(o=o.concat(w(n,t)));return o}},7668:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.FrameworkPatcher=void 0;const s=r(9896),a=i(r(6928)),c=r(1377),u=r(8064);t.FrameworkPatcher=class{patch(e,t,r){const o=function(e){try{const t=(0,s.readFileSync)(a.join(e,"package.json"),{encoding:"utf8"}),r=JSON.parse(t).version;return"string"==typeof r?r:""}catch(t){c.instrument_logger.info("Failed extracting version",{baseDir:e})}return""}(t);return function(e,t){return""===e||u.satisfies(u.coerce(e),t)}(o,r)?this._patch(e):(c.instrument_logger.warn("Unsupported version",{framework:this.constructor.name,version:o,supportedVersion:r,basedir:t}),e)}}},9788:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=i(r(6982)),c=r(1377),u=r(7668),l=s(r(1019)),d=r(2119),f=r(2119),p=r(878),h=r(6257),g=r(7868),m=r(6530),v=r(938);class _ extends u.FrameworkPatcher{static graphQLPatchedSymbol=Symbol.for(l.default.hudPatchedName);_patch(e){return this.patchGraphql(e),c.instrument_logger.info("Patched GraphQL successfully"),e}patchGraphql(e){const t=e.execute;e.execute=function(e){!function(e){try{e&&!e[_.graphQLPatchedSymbol]&&(y(e._queryType),y(e._mutationType),e[_.graphQLPatchedSymbol]=!0,c.instrument_logger.info("Patched GraphQL schema successfully"))}catch(e){c.instrument_logger.error("Failed to patch GraphQL schema",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}(e.schema);const r=process.hrtime.bigint();return function(e,t,r){return"function"==typeof e.then?e.then((e=>((0,m.saveDocumentMetadata)(t,r),e))):((0,m.saveDocumentMetadata)(t,r),e)}(t.apply(this,arguments),e.document,r)},(0,d.copyPropertiesToTarget)(t,e.execute)}}function y(e){if(!e)return;const t=e._fields;Object.keys(t).forEach((r=>{const o=t[r];!function(e,t,r){if(e.resolve&&!e.resolve[_.graphQLPatchedSymbol]){const o=a.randomUUID();(0,h.storeResolverDeclaration)({id:o,operation:t,name:r});const n=e.resolve;e.resolve=(0,f.wrapFlow)(k,n,((e,t)=>{const r=v.GraphQLMetric.createUsableMetric();r.start(),r.setFlowId(e),t.flowMetric=r}),((e,t)=>{const r=t.flowMetric;r?r.end():c.instrument_logger.warn("No flowMetric found for resolver",{flowId:e})}),((e,t)=>{const r=t.flowMetric;r?r.end():c.instrument_logger.warn("No flowMetric found for resolver",{flowId:e})})),e.resolve[_.graphQLPatchedSymbol]=!0,(0,g.storeResolverIdBySelectionName)(o,r)}}(o,p.GraphQLSupportedOperations[e.name.toLowerCase()],r),o.type._fields&&w(o.type)}))}t.default=_;const b=new WeakSet;function w(e){e&&e._fields&&!b.has(e)&&(b.add(e),Object.keys(e._fields).forEach((t=>{const r=e._fields[t];if(!r||!r.type)return;!function(e){const t=e.resolve;t&&!e.resolve[_.graphQLPatchedSymbol]&&(e.resolve=(0,f.wrapFlow)(k,t),e.resolve[_.graphQLPatchedSymbol]=!0)}(r);let o=r.type;for(;o.ofType;)o=o.ofType;w(o)})))}function k(e){if(void 0===e[2]||void 0===e[3])return void c.instrument_logger.warn("GraphQL resolver arguments are unknown",{args:e});const t=e[3].path;if(t&&!t.prev){const r=t.key,o=(0,g.getResolverIdBySelectionName)(r);return e[2][_.graphQLPatchedSymbol]=o,o}if(e[2][_.graphQLPatchedSymbol])return e[2][_.graphQLPatchedSymbol];c.instrument_logger.warn("GraphQL No functionId found for resolver",{args:e})}},6530:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.saveDocumentMetadata=t.getDocumentsMetadata=void 0;const s=r(1377),a=i(r(6982));t.getDocumentsMetadata=function(){const e=c;return c=[],e},t.saveDocumentMetadata=function(e,t){try{new u(e,Number(process.hrtime.bigint()-t)).save()}catch(e){s.instrument_logger.error("Failed to save document metadata",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}};let c=[];class u{name;timeTook;hash;selectionNames;constructor(e,t){this.name=e.definitions[0]?.name?.value,this.hash=a.createHash("sha256").update(e.loc?.source?.body).digest("hex"),this.selectionNames=e.definitions.flatMap((e=>e.selectionSet.selections.map((e=>e.name.value)))),this.timeTook=t}save(){c.push(this)}}},6257:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.storeResolverDeclaration=t.getResolversDeclarations=void 0;let r=[];t.getResolversDeclarations=function(){const e=r;return r=[],e},t.storeResolverDeclaration=function(e){r.push(e)}},7868:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getResolverIdBySelectionName=t.storeResolverIdBySelectionName=void 0;const r=new Map;t.storeResolverIdBySelectionName=function(e,t){r.set(t,e)},t.getResolverIdBySelectionName=function(e){return r.get(e)}},405:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const o=r(1377),n=r(2119),i=r(7668),s=r(2847),a=r(331);class c extends i.FrameworkPatcher{_patch(e){return this._patchEmit(e),o.instrument_logger.info("Patched http successfully"),e}_patchEmit(e){const t=e.Server.prototype.emit;e.Server.prototype.emit=function(e,...r){if("request"!==e)return t.apply(this,[e,...r]);try{const e=r[0],t=r[1],n=s.HttpEndpointMetric.createUsableMetric();n.start(),n.setRequestAttributes(e),t.once("finish",(function(){try{n.setResponseAttributes(t),n.end()}catch(e){o.instrument_logger.error("Failed to set response attributes",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}})),e[a.metricSymbol]=n}catch(e){o.instrument_logger.error("Failed to patch http.Server.prototype.emit",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t.apply(this,[e,...r])},(0,n.copyPropertiesToTarget)(t,e.Server.prototype.emit)}}t.default=c},2680:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0});const s=r(1377),a=r(2119),c=r(2119),u=r(7668),l=r(5202),d=i(r(6982)),f=r(6842),p=r(331);class h extends u.FrameworkPatcher{_patch(e){return this._patchConsumer(e),s.instrument_logger.info("Patched KafkaJS successfully"),e}_patchConsumer(e){const t=e.Kafka.prototype.consumer;e.Kafka.prototype.consumer=function(...e){const r=t.apply(this,e);try{const t=new Map,o=[],n=[];!function(e,t){const r=e.subscribe;e.subscribe=async function(...e){const o=await r.apply(this,e);try{const r=e[0].topics;r?r.forEach((e=>{t.push(e)})):e[0].topic?t.push(e[0].topic):s.instrument_logger.warn("No topic found in KafkaJS.Consumer.subscribe",{args:e[0]})}catch(e){s.instrument_logger.error("Error in patching KafkaJS.Consumer.subscribe",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return o},(0,a.copyPropertiesToTarget)(r,e.subscribe)}(r,n),function(e,t,r,o,n){const i=e.run;function u(e,i){const a="eachBatch"===i;for(const e of n)_(e,o,t,r,i);const u=function(e,t,r){return o=>{const n=o[0],i=r?n.batch.topic:n.topic;return function(e,t,r,o){const n=e.get(v(r,o));if(n)return n;for(const e of t)if(e.isBatch===o&&e.pattern.test(r))return e.flowId;s.instrument_logger.warn("No flowId found for topic",{topicName:r,isBatch:o})}(e,t,i,r)}}(t,r,a),l=function(e){return(t,r,o)=>{const n=f.KafkaJSMetric.createUsableMetric();n.start(),n.setFlowId(t);const i=o[0];void 0!==i&&void 0!==i.message&&(i.message[p.metricSymbol]=n);const s=e?i.batch.partition:i.partition,a=e?i.batch.messages[0]?.timestamp:i.message?.timestamp;n.addPartition(s),n.addProducedTimestamp(a),r.flowMetric=n}}(a),d=(0,c.wrapFlow)(u,e[i],l,g,m);e[i]=d}e.run=async function(...e){try{const t=e[0];t.eachMessage&&u(t,"eachMessage"),t.eachBatch&&u(t,"eachBatch")}catch(e){s.instrument_logger.error("Error in patching KafkaJS.Consumer.run",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return await i.apply(this,e)},(0,a.copyPropertiesToTarget)(i,e.run)}(r,t,o,e[0].groupId,n)}catch(e){s.instrument_logger.error("Error in patching KafkaJS.Consumer",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return r},(0,a.copyPropertiesToTarget)(t,e.Kafka.prototype.consumer)}}function g(e,t){const r=t.flowMetric;r?r.end():s.instrument_logger.warn("No flowMetric found for message",{flowId:e})}function m(e,t,r){const o=t.flowMetric;if(!o)return void s.instrument_logger.warn("No flowMetric found for message",{flowId:e});const n=r instanceof Error?r.message:r;o.setError(n),o.end()}function v(e,t){return e+"|"+t}function _(e,t,r,o,n){const i=d.randomUUID(),s={flow_id:i,topic_name:e.toString(),group_id:t,pulling_type:n};(0,l.storeKafkaJSTopicDeclaration)(s),function(e,t,r,o,n){"string"==typeof r?e.set(v(r,o),n):t.push({pattern:r,isBatch:o,flowId:n})}(r,o,e,"eachBatch"===n,i)}t.default=h},5202:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.storeKafkaJSTopicDeclaration=t.getKafkaJSTopics=void 0;let r=[];t.getKafkaJSTopics=function(){const e=r;return r=[],e},t.storeKafkaJSTopicDeclaration=function(e){r.push(e)}},7436:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(1377),c=r(2119),u=r(2119),l=r(7668),d=r(6538),f=s(r(1019)),p=i(r(6982)),h=r(331);class g extends l.FrameworkPatcher{static koaModuleName="koa";static koaPatchedSymbol=Symbol.for(f.default.hudPatchedName);_patch(e){return this._patchAppUse(e),a.instrument_logger.info("Patched koa successfully"),e}_patchAppUse(e){const t=e.prototype.use;e.prototype.use=function(e){const r=t.apply(this,arguments);try{if(!arguments[0].router)return r;const e=arguments[0].router.stack;for(let t=0;t<e.length;t++)g._wrapRoute(e[t])}catch(e){a.instrument_logger.error("Failed to patch koa.use function",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return r},(0,c.copyPropertiesToTarget)(t,e.prototype.use)}static _wrapRoute(e){if(e.methods&&0===e.methods.length)return;const t=p.randomUUID();if(!e.stack[0][g.koaPatchedSymbol]){const t=(0,u.wrapFlow)(b,e.stack[0],m);e.stack[0]=t,e.stack[0][g.koaPatchedSymbol]=!0}(0,d.storeEndpointDeclaration)(new d.EndpointDeclaration(t,e.methods,"koa",void 0,e.path));for(const r of e.methods)y(t,e.path,r)}}function m(e,t,r){if(!r[0])return void a.instrument_logger.error("No ctx object found in koa");const o=r[0].req;if(!o)return void a.instrument_logger.error("No req found in koa ctx");const n=o[h.metricSymbol];n?n.setFlowId(e):a.instrument_logger.error("No endpoint metric found in koa req")}function v(e,t){return e+"|"+t}t.default=g;const _=new Map;function y(e,t,r){_.set(v(t,r),e)}function b(e){if(0===e.length)return;const t=e[0]._matchedRoute,r=e[0].req?.method;return function(e,t){return _.get(v(e,t))}(t,r)}},1973:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.generateKey=t.getRequestByCallback=void 0,r(1321);const o=r(1377),n=r(2119),i=r(7668),s=new Map;function a(e,t){const r=Reflect.getMetadata("path",t)??Reflect.getMetadata("microservices:pattern",t);if(!r)return void o.instrument_logger.error("No callback path found on callback",{callback:t});const n=e.constructor.CONTROLLER_ID;if(n)return`${n}.${r}`;o.instrument_logger.error("No controller id found on controller",{controller:e})}t.getRequestByCallback=function(e){const t=s.get(e);return t&&s.delete(e),t},t.generateKey=a;class c extends i.FrameworkPatcher{_patch(e){return this._patchIntercept(e),o.instrument_logger.info("Patched NestJS intercept successfully"),e}_patchIntercept(e){const t=e.InterceptorsConsumer.prototype.intercept;e.InterceptorsConsumer.prototype.intercept=async function(...e){return function(e){try{const t=e[2],r=e[3];if("function"==typeof t.constructor&&"function"==typeof r){let o;if("rpc"===e[5])o=e[1][1].args[0];else if(o=e[1][0],!o||o.raw)return;const n=a(t,r);if(!n)return;s.set(n,o)}else o.instrument_logger.error("Invalid args in NestJS InterceptorsConsumer.intercept",{args:e})}catch(e){o.instrument_logger.error("Error in NestJS intercept patcher",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}(e),await t.apply(this,e)},(0,n.copyPropertiesToTarget)(t,e.InterceptorsConsumer.prototype.intercept)}}t.default=c},436:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const o=r(1377),n=r(2119),i=r(2119),s=r(7668),a=r(331),c=r(1973);class u extends s.FrameworkPatcher{_patch(e){return this._patchCreate(e),o.instrument_logger.info("Patched NestJS RouterExecutionContext successfully"),e}_patchCreate(e){const t=e.RouterExecutionContext.prototype.create;e.RouterExecutionContext.prototype.create=function(...e){try{const t=e[0],r=e[1];if("function"==typeof t.constructor&&"function"==typeof r){const n=(0,c.generateKey)(t,r);n&&(e[1]=(0,i.wrapFlow)((()=>{try{const e=(0,c.getRequestByCallback)(n);if(!e)return void o.instrument_logger.error("No request object found for key",{key:n});const t=function(e){if(e&&!e.raw&&e.socket)return e[a.metricSymbol]?e[a.metricSymbol].getFlowId?e[a.metricSymbol].getFlowId():void o.instrument_logger.error("No getFlowId function found on metric object"):void o.instrument_logger.error("No metric found on nestjs request object")}(e);return t||o.instrument_logger.error("No flow id found for key",{key:n}),t}catch(e){o.instrument_logger.error("Error in NestJS getFlowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}),r))}else o.instrument_logger.error("Invalid args in NestJS RouterExecutionContext.create",{args:e})}catch(e){o.instrument_logger.error("Error in NestJS RouterExecutionContext patcher",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t.apply(this,e)},(0,n.copyPropertiesToTarget)(t,e.RouterExecutionContext.prototype.create)}}t.default=u},7636:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const o=r(1377),n=r(2119),i=r(2119),s=r(7668),a=r(331),c=r(1973);class u extends s.FrameworkPatcher{_patch(e){return this._patchCreate(e),o.instrument_logger.info("Patched NestJS RpcContextCreator successfully"),e}_patchCreate(e){const t=e.RpcContextCreator.prototype.create;e.RpcContextCreator.prototype.create=function(...e){try{const t=e[0],r=e[1];if("function"==typeof t.constructor&&"function"==typeof r){const n=(0,c.generateKey)(t,r);n&&(e[1]=(0,i.wrapFlow)((()=>{try{const e=(0,c.getRequestByCallback)(n);if(!e)return void o.instrument_logger.error("No msg object found for key",{key:n});const t=function(e){if(e)return e[a.metricSymbol]?e[a.metricSymbol].getFlowId?e[a.metricSymbol].getFlowId():void o.instrument_logger.error("No getFlowId function found on metric object"):void o.instrument_logger.error("No metric found on nestjs msg object")}(e);return t||o.instrument_logger.error("No flow id found for key",{key:n}),t}catch(e){o.instrument_logger.error("Error in NestJS getFlowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}),r))}else o.instrument_logger.error("Invalid args in NestJS RpcContextCreator.create",{args:e})}catch(e){o.instrument_logger.error("Error in NestJS RpcContextCreator patcher",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t.apply(this,e)},(0,n.copyPropertiesToTarget)(t,e.RpcContextCreator.prototype.create)}}t.default=u},3976:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.patchRequire=t.patchCompile=t.patch=t.shouldSupportSourceMap=t.supportSourceMapInstall=void 0;const s=i(r(9896)),a=i(r(6928)),c=r(1377),u=r(2243),l=r(7022),d=r(1019),f=r(9063),p=r(2676),h=r(9514),g=r(8466),m=function(){const e=d.hudConfig.hudModuleName;try{return a.dirname(a.dirname(p.myRequire.resolve(e)))}catch(t){return c.instrument_logger.error("Failed to resolve own path",{moduleName:e,msg:t instanceof Error?t.message:void 0,stack:t instanceof Error?t.stack:void 0}),null}}();function v(e){return!!globalThis.HudRetrieveFileCache.has(e)&&globalThis.HudRetrieveFileCache.get(e)}function _(){r(6093).install({handleUncaughtExceptions:!1,hookRequire:!1,environment:"node",retrieveFile:v})}function y(){return!(!d.hudConfig.supportSourceMap.enable||d.hudConfig.supportSourceMap.skipOnNodeFlag&&process.execArgv.includes("--enable-source-maps")&&(c.instrument_logger.warn("Not enabling source-map-support since --enable-source-maps is set"),1))}function b(e,t,r,o,n){let i=e;try{if(r===l.Format.esm&&!n)throw new h.HudError("MessagePort is required for patching ESM modules");if(!function(e){return e.includes("node_modules")&&!function(e){for(const t of w)if(t(e))return!0;return!1}(e)||e.includes(".yarn")?(c.instrument_logger.debug("Skipping non-monitored imported module",{filename:e}),!0):!(m&&!e.includes(m))&&(c.instrument_logger.debug("Skipping hud internal module",{filename:e}),!0)}(t)&&e.length<=d.hudConfig.maxWrappedFileSize){const l=(0,u.edit)(e,{filename:t,format:r},o);c.instrument_logger.debug("Patched",{filename:t}),n?n.postMessage({key:"HudModulePatch",hudPatched:t,hudProcessedFiles:l}):(globalThis.hudPatched.add(t),globalThis.hudProcessedFiles.push(l)),i=function(e,t){let r;return void 0===t?e:(r="string"==typeof t||t instanceof String?Buffer.from(t.toString()).toString("base64"):Buffer.from(JSON.stringify(t)).toString("base64"),e+`\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${r}`)}(l.code,l.map),d.hudConfig.writePatched&&function(e,t){const r=a.parse(e);let o=`${r.dir}/patched.${r.base}`;r.dir.includes("dist")&&(o=a.join(`${r.dir.replace("dist","patched")}`,r.base)),s.existsSync(a.dirname(o))||s.mkdirSync(a.dirname(o),{recursive:!0}),s.writeFileSync(o,t,"utf8"),c.instrument_logger.debug("Dumped patched file",{filename:e,patchedPath:o})}(t,i)}}catch(e){c.instrument_logger.error("Failed to patch",{filename:t,format:r,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return i}t.supportSourceMapInstall=_,t.shouldSupportSourceMap=y,t.patch=b,t.patchCompile=function(){const e=(0,g.getSWC)(c.instrument_logger);if(void 0===e)return void c.instrument_logger.error("Failed to load SWC, not patching compile");const t=r(3339),o=y();if(0!==Object.keys(globalThis.hudLoadedModules).length)return void c.instrument_logger.warn("PatchCompile ran twice, weird...");globalThis.hudLoadedModules=Object.keys(p.myRequire.cache);const n=t.prototype._compile;t.prototype._compile=function(t,r){c.instrument_logger.verbose("Compiling requirement",{filename:r});const i=b(t,r,l.Format.cjs,e);return o&&globalThis.HudRetrieveFileCache.set(r,i),n.call(this,i,r)},c.instrument_logger.debug("Patched _compile"),o&&_()},t.patchRequire=function(){new f.Hook(Array.from(d.hudConfig.frameworksToPatch.keys()),{internals:!0},((e,t,o)=>{try{const n=d.hudConfig.frameworksToPatch.get(t);return n?(new(0,r(1306)(`./${n.patcher}`).default)).patch(e,o,n.version):e}catch(e){c.instrument_logger.error("Failed to patch framework",{name:t,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return e}))};const w=[];for(const e of d.hudConfig.monitorNodeModules)w.push((t=>!(!t.includes(`node_modules/${e}`)||t.includes(`node_modules/${e}/node_modules`))))},8891:(e,t)=>{"use strict";function r(e){return e instanceof Error?e.constructor?e.constructor.name:e.name?e.name:"Non-Deducible-Name-Exception":"Non-Error-Exception"}function o(e=0){const t=Error.stackTraceLimit,r=Error.prepareStackTrace;let o=[];try{Error.stackTraceLimit=4+e,Error.prepareStackTrace=(t,r)=>{const n=r.slice(1+e);return o=n,n},(new Error).stack}finally{Error.stackTraceLimit=t,Error.prepareStackTrace=r}const n="processTicksAndRejections"!==o[0].getFunctionName()?0:1;let i;o[n]&&(i={name:o[n].getFunctionName(),file:o[n].getFileName(),line:o[n].getLineNumber(),column:o[n].getColumnNumber(),enclosingLine:o[n].getEnclosingLineNumber()});const s=o[n+1]&&"processTicksAndRejections"!==o[n+1].getFunctionName()?n+1:n+2;let a;return o[s]&&(a={name:o[s].getFunctionName(),file:o[s].getFileName(),line:o[s].getLineNumber(),column:o[s].getColumnNumber(),enclosingLine:o[s].getEnclosingLineNumber()}),[i,a]}Object.defineProperty(t,"__esModule",{value:!0}),t.fixStack=t.wrapperFinally=t.wrapperCatch=t.wrapperInitial=t.asyncIteratorWrapper=t.getCallsites=t.extractName=void 0,t.extractName=r,t.getCallsites=o;class n{iterator;n;constructor(e){this.iterator=e,this.n=e.next}static AsyncFromSyncIteratorContinuation(e){if(Object(e)!==e)return Promise.reject(new TypeError(e+" is not an object."));const t=e.done;return Promise.resolve(e.value).then((function(e){return{value:e,done:t}}))}next(...e){return n.AsyncFromSyncIteratorContinuation(this.n.call(this.iterator,...e))}return(e){const t=this.iterator.return;return void 0===t?Promise.resolve({value:e,done:!0}):n.AsyncFromSyncIteratorContinuation(t.call(this.iterator,e))}throw(e){const t=this.iterator.throw;return void 0===t?Promise.reject(e):n.AsyncFromSyncIteratorContinuation(t.call(this.iterator,e))}[Symbol.asyncIterator](){return this}}t.asyncIteratorWrapper=function(e){if(e&&e[Symbol.asyncIterator])return e[Symbol.asyncIterator]();if(e&&e[Symbol.iterator])return new n(e[Symbol.iterator]());if(e&&e["@@asyncIterator"])return e["@@asyncIterator"]();if(e&&e["@@iterator"])return e["@@iterator"]();throw new TypeError("Object is not async iterable")},t.wrapperInitial=function(e,t){const r=t.wrappedCaller=hudWrappedCaller[hudWrappedCallerIndex.value],o=hudCalls[e]??={},n=o[r]??={},i=n[hudCurrentFlowId]??={count:0,lastSentCounter:0,sampledCount:0,sum:0,exceptions:{},squareSum:0,sketch:null,isLinkedFunction:!1},s=i.count++;(t.sample_flag=2===hudRunningMode&&(s>=5e3?s%103==0:hudSampleTable[s]))&&(t.start=process.hrtime.bigint()),hudShouldLinkFunction&&(hudShouldLinkFunction=!1,i.isLinkedFunction=!0),t.currentFlowId=hudCurrentFlowId,hudWrappedCaller[++hudWrappedCallerIndex.value]=e},t.wrapperCatch=function(e,t,n){const i=t.end=process.hrtime.bigint(),s=r(n),[a,c]=o(1),u=hudCalls[e][t.wrappedCaller][t.currentFlowId];(u.exceptions[s]??=[]).push({caller:c,duration:t.start?Number(i-t.start):void 0})},t.wrapperFinally=function(e,t){if(t.fixFlag||hudWrappedCallerIndex.value--,t.sample_flag){const r=process.hrtime.bigint(),o=Number(r-t.start);if(o>0){const r=hudCalls[e][t.wrappedCaller][t.currentFlowId];r.sampledCount++,r.sum+=o,r.squareSum+=o*o,null===r.sketch?r.sketch=hudManager.newSketchDataWithValue(o):hudManager.add(r.sketch,o)}}},t.fixStack=function(e,t){t.fixFlag&&(hudWrappedCaller[++hudWrappedCallerIndex.value]=e,hudCurrentFlowId=t.currentFlowId,t.fixFlag=!1)}},2119:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.copyPropertiesToTarget=t.wrapFlow=void 0;const o=r(765),n=r(6121),i=r(1377);function s(e,t){const r=Object.getOwnPropertyDescriptors(e),o=Reflect.ownKeys(r);Object.setPrototypeOf(t,e),o.forEach((e=>{try{Object.defineProperty(t,e,r[e])}catch(e){}}))}t.wrapFlow=function(e,t,r,a,c){let u;return u=t instanceof n.AsyncFunction?async function(...n){let s;try{s=e(n)}catch(e){i.instrument_logger.error("Failed to get flowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}if(!s||hudRunningMode!==o.HudRunningMode.enabled)return await t.apply(this,n);hudCurrentFlowId=s,hudShouldLinkFunction=!0;const u={};if(r)try{r(s,u,n)}catch(e){i.instrument_logger.error("Failed to execute beforeCallbackHook",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}try{const e=t.apply(this,n);hudCurrentFlowId="";const r=await e;if(a)try{a(s,u)}catch(e){i.instrument_logger.error("Failed to execute afterCallbackHook",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return r}catch(e){if(c)try{c(s,u,e)}catch(e){i.instrument_logger.error("Failed to execute catchCallbackHook",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}throw e}finally{hudCurrentFlowId="",hudShouldLinkFunction=!1}}:function(...n){let s;try{s=e(n)}catch(e){i.instrument_logger.error("Failed to get flowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}if(!s||hudRunningMode!==o.HudRunningMode.enabled)return t.apply(this,n);hudCurrentFlowId=s,hudShouldLinkFunction=!0;const u={};if(r)try{r(s,u,n)}catch(e){i.instrument_logger.error("Failed to execute beforeCallbackHook",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}try{const e=t.apply(this,n);if(a)if(e instanceof Promise)e.then((()=>{try{a(s,u)}catch(e){i.instrument_logger.error("Failed to execute afterCallbackHook",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}));else try{a(s,u)}catch(e){i.instrument_logger.error("Failed to execute afterCallbackHook",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return e}catch(e){if(c)try{c(s,u,e)}catch(e){i.instrument_logger.error("Failed to execute catchCallbackHook",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}throw e}finally{hudCurrentFlowId="",hudShouldLinkFunction=!1}},s(t,u),u},t.copyPropertiesToTarget=s},1377:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.worker_logger=t.instrument_logger=t.app_logger=t.customer_logger=t.SafeLogger=t.renewFileTransports=t.getSavedLogs=t.getLogPath=t.WorkerPortTransport=void 0;const a=i(r(857)),c=i(r(6928)),u=i(r(5124)),l=i(r(9896)),d=i(r(6982)),f=r(1019),p=s(r(1620)),h=process.env.HUD_DEBUG?f.hudConfig.logger.debug:process.env.HUD_VERBOSE?f.hudConfig.logger.verbose:f.hudConfig.logger.default;class g extends p.default{_messeagesToSend=[];messagesLimit=f.hudConfig.loggerWorkerPortSizeLimit;messageDropCount=0;getMessagesToSend(){if(!this._messeagesToSend.length)return!1;const e=this._messeagesToSend;this.clearMessagesToSend();const t=this.messageDropCount;return this.messageDropCount=0,{logsBuf:this.formatMessagesToSend(e),messageDropCount:t}}clearMessagesToSend(){this._messeagesToSend=[]}formatMessagesToSend(e){return e.map((e=>JSON.stringify(e))).join("\n")}log(e,t){this._messeagesToSend.length>=this.messagesLimit?this.messageDropCount++:this._messeagesToSend.push(e),t()}}t.WorkerPortTransport=g;const m=u.format.combine(u.format.timestamp({format:"HH:mm:ss.SSS"}),u.format.printf((({level:e,message:t,timestamp:r,label:o,...n})=>{try{const i=Object.keys(n).length;let s;if(i)if(1===i){const e=Object.keys(n)[0];s=`${t} ${e}: ${JSON.stringify(n[e],null,2)}`}else s=`${t}\n${JSON.stringify(n,null,2)}`;else s=t;const a=u.format.colorize().colorize(e,e.toUpperCase());return`[${r}]${(o?`(${o})`:"").padEnd(8," ")} ${a}: ${s}`}catch(e){return t}})));function v(){return u.format.combine(u.format.label({label:"app"}),u.format.timestamp({format:()=>(new Date).toISOString()}),u.format.json())}function _(e){return{filename:w(),level:h.levels[e],format:v(),lazy:!1}}function y(){if(f.hudConfig.logDirectory)return f.hudConfig.logDirectory;const e=a.homedir();switch(a.platform()){case"darwin":return c.join(e,"Library","Logs","hud");case"win32":return c.join(e,"AppData","hud","Logs");default:return c.join(e,".hud","logs")}}let b;function w(){return b??=c.join(y(),`${d.randomUUID()}.log`)}t.getLogPath=w,t.getSavedLogs=function(){const e=[];for(const[t,r]of Object.entries(k))for(const t of r.transports)try{if(t instanceof g){const o=t.getMessagesToSend();if(!o)continue;const{logsBuf:n,messageDropCount:i}=o;i&&r.info(`Dropped ${i} messages`),e.push(n)}}catch(e){r.error("Failed to get saved logs",e)}return e},t.renewFileTransports=function(){const e=new Date,t=new Set;for(const[r,o]of Object.entries(k)){const r=[],n=[];for(const i of o.transports)if(i instanceof u.transports.File){i.close&&i.close(),r.push(i),n.push(new u.transports.File({level:i.level,format:i.format,filename:c.join(i.dirname,i.filename),lazy:!1}));const o=c.join(y(),`${d.randomUUID()}-${e.toISOString().replaceAll(":","")}.log`);l.existsSync(c.join(i.dirname,i.filename))&&(l.renameSync(c.join(i.dirname,i.filename),o),t.add(o))}for(const e of r)o.remove(e);for(const e of n)o.add(e)}return t};const k={};class S{name;logger;constructor(e){this.name=e;try{this.logger=function(e){const t=[];h.console&&t.push(new u.transports.Console({format:u.format.combine(u.format.label({label:e}),m)}));let r=!1;try{const r=_(e),o=c.dirname(r.filename);l.mkdirSync(o,{recursive:!0}),l.writeFileSync(r.filename,"",{flag:"w"}),t.push(new u.transports.File(r))}catch{const e=v(),o=new g({format:e});t.push(o),r=!0}const o=u.createLogger({level:h.levels[e],transports:t});return k[e]=o,r&&o.info("Could not create file transport, fallback succesfully to worker port"),o}(e)}catch(e){this.logger=void 0}}isValid(){return!!this.logger}log(e,t,...r){this.logger&&this.logger.log(e,t,...r)}error(e,...t){this.log("error",e,...t)}warn(e,...t){this.log("warn",e,...t)}info(e,...t){this.log("info",e,...t)}http(e,...t){this.log("http",e,...t)}verbose(e,...t){this.log("verbose",e,...t)}debug(e,...t){this.log("debug",e,...t)}silly(e,...t){this.log("silly",e,...t)}}t.SafeLogger=S,t.customer_logger=u.createLogger({level:f.hudConfig.customerLoggerLevel,transports:[new u.transports.Console({})],format:u.format.printf((({message:e,errCode:t,moreInfo:r})=>{try{let o=`Hud: ${e}`;return r&&(o+=" For more information visit https://docs.hud.io/docs/py-sdk-ie."),void 0!==t&&(o+=` ${t}`),o}catch(t){return e}}))}),t.app_logger=new S("app"),t.instrument_logger=new S("instrument"),t.worker_logger=new S("worker")},398:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.loopLogProcessPerformance=t.getCpuLimit=t.getCpuLimitUnsafe=t.loopLogThreadPerformance=void 0;const a=r(2987),c=s(r(857)),u=i(r(1493)),l=r(1765),d=r(9896),f=r(1954);function p(e){e.info("Trying to detect CPU limit");try{const t=(0,d.readFileSync)("/sys/fs/cgroup/cpu/cpu.cfs_quota_us","utf8"),r=(0,d.readFileSync)("/sys/fs/cgroup/cpu/cpu.cfs_period_us","utf8");return e.info("CPU limit detected for cgroups v1",{cpuQuota:t,cpuPeriod:r}),parseInt(t.toString())/parseInt(r.toString())}catch(t){try{const t=(0,d.readFileSync)("/sys/fs/cgroup/cpu.max","utf8"),[r,o,n]=t.trim().split(" ");return e.info("CPU limit detected for cgroups v2",{max:r,period:o}),r&&o?"max"===r?"unlimited":parseInt(r)/parseInt(o):void e.info("cpu.max file is not in the expected format",t)}catch(r){return void e.info("Failed to detect CPU limit",{e:t,e2:r})}}}t.loopLogThreadPerformance=async function(e,t,r){let o=a.performance.eventLoopUtilization(),n=a.performance.nodeTiming.toJSON();for await(const i of(0,l.unrefSetInterval)(t,void 0,{signal:r}))try{const t=a.performance.eventLoopUtilization(),r=a.performance.eventLoopUtilization(t,o);o=t;const i=u.getHeapStatistics(),s=a.performance.nodeTiming.toJSON(),c=s.idleTime-n.idleTime,l=s.duration-n.duration,d=c/l;n=s,e.info("thread performance statistics",{thread_elu_percentage:100*r.utilization,memory:{thread_heap_utilization_percentage:i.total_heap_size/i.heap_size_limit*100},idleTime:c,totalTime:l,idleTimePercentage:d})}catch(t){e.error("Failed logging thread performance statistics",{msg:t instanceof Error?t.message:void 0,stack:t instanceof Error?t.stack:void 0})}},t.getCpuLimitUnsafe=p,t.getCpuLimit=(0,f.suppressTraces)(p),t.loopLogProcessPerformance=async function(e,r,o){const n=c.default.totalmem(),i=(0,t.getCpuLimit)(e);let s=process.cpuUsage();for await(const t of(0,l.unrefSetInterval)(r,void 0,{signal:o}))try{const t=process.memoryUsage(),o=process.uptime(),a=process.cpuUsage(s);s=process.cpuUsage();let c=(a.user+a.system)/(1e3*r);i&&"number"==typeof i&&(c/=i),e.info("process performance statistics",{memory:{process_memory_rss:t.rss,process_memory_utilization_percentage:t.rss/n*100},cpu:100*c,cpuStats:{limit:i,usagePercentage:100*c},uptime:o})}catch(t){e.error("Failed logging process performance statistics",{msg:t instanceof Error?t.message:void 0,stack:t instanceof Error?t.stack:void 0})}}},6701:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.safeCall=void 0;const o=r(9514);t.safeCall=function(e,t){return t.catch((t=>{(0,o.isAbortError)(t)||e.error("Unhandled exception on async task",{msg:t instanceof Error?t.message:void 0,stack:t instanceof Error?t.stack:void 0})}))}},1954:function(e,t,r){"use strict";var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.suppressTraces=void 0;const n=o(r(1019)),i=r(1377),s=r(2676);let a,c;try{const e=(0,s.myRequire)("@opentelemetry/api"),t=(0,s.myRequire)("@opentelemetry/core");a=e.context,c=t.suppressTracing,i.app_logger.info("OpenTelemetry exists",{suppressConfig:n.default.suppressTraces})}catch(e){i.app_logger.info("OpenTelemetry api/core does not exist")}t.suppressTraces=function(e){return function(...t){return n.default.suppressTraces&&a&&c?(i.app_logger.debug("Running with Suppressed traces"),a.with(c(a.active()),(()=>e(...t)))):e(...t)}}},1765:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.unrefSetInterval=t.unrefSetTimeout=t.unrefSetImmediate=void 0;const s=i(r(6460));t.unrefSetImmediate=function(e,t){return s.setImmediate(e,{...t,ref:!1})},t.unrefSetTimeout=function(e,t,r){return s.setTimeout(e,t,{...r,ref:!1})},t.unrefSetInterval=function(e,t,r){return s.setInterval(e,t,{...r,ref:!1})}},2676:(e,t)=>{"use strict";let r;Object.defineProperty(t,"__esModule",{value:!0}),t.myRequire=void 0;try{r=require}catch(e){r=void 0}t.myRequire=r},1306:(e,t,r)=>{var o={"./express":7697,"./express.ts":7697,"./frameworkPatcher":7668,"./frameworkPatcher.ts":7668,"./graphql":9788,"./graphql.ts":9788,"./graphql/metadata":6530,"./graphql/metadata.ts":6530,"./graphql/resolversDeclarations":6257,"./graphql/resolversDeclarations.ts":6257,"./graphql/resolversMapping":7868,"./graphql/resolversMapping.ts":7868,"./http":405,"./http.ts":405,"./kafkajs":2680,"./kafkajs.ts":2680,"./kafkajs/topicsDeclarations":5202,"./kafkajs/topicsDeclarations.ts":5202,"./koa":7436,"./koa.ts":7436,"./nestjsInterceptor":1973,"./nestjsInterceptor.ts":1973,"./nestjsRouterExecutionContext":436,"./nestjsRouterExecutionContext.ts":436,"./nestjsRpcContextCreator":7636,"./nestjsRpcContextCreator.ts":7636};function n(e){var t=i(e);return r(t)}function i(e){if(!r.o(o,e)){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}return o[e]}n.keys=function(){return Object.keys(o)},n.resolve=i,e.exports=n,n.id=1306},5809:e=>{"use strict";e.exports=require("./config")},6346:e=>{"use strict";e.exports=require("@babel/core")},6093:e=>{"use strict";e.exports=require("@cspotcode/source-map-support")},143:e=>{"use strict";e.exports=require("@swc/core")},8054:e=>{"use strict";e.exports=require("array-flatten")},1214:e=>{"use strict";e.exports=require("methods")},1321:e=>{"use strict";e.exports=require("reflect-metadata")},9063:e=>{"use strict";e.exports=require("require-in-the-middle")},8064:e=>{"use strict";e.exports=require("semver")},3903:e=>{"use strict";e.exports=require("uuid")},5124:e=>{"use strict";e.exports=require("winston")},1620:e=>{"use strict";e.exports=require("winston-transport")},5317:e=>{"use strict";e.exports=require("child_process")},6982:e=>{"use strict";e.exports=require("crypto")},9896:e=>{"use strict";e.exports=require("fs")},3339:e=>{"use strict";e.exports=require("module")},857:e=>{"use strict";e.exports=require("os")},6928:e=>{"use strict";e.exports=require("path")},2987:e=>{"use strict";e.exports=require("perf_hooks")},932:e=>{"use strict";e.exports=require("process")},6460:e=>{"use strict";e.exports=require("timers/promises")},1493:e=>{"use strict";e.exports=require("v8")},8167:e=>{"use strict";e.exports=require("worker_threads")}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,r),i.exports}return r.c=t,r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r(r.s=7729)})()));
|