hud-sdk 1.6.16 → 1.6.18

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.
@@ -2579,4 +2579,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
2579
2579
 
2580
2580
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
2581
2581
 
2582
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2582
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/dist/cjs/cli.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- !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 n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(global,()=>(()=>{var e={336:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2546),o=r(2822),s=r(8949),i=r(8901),a=r(714);class c extends a.FrameworkPatcher{_patch(e){return this._patchSendRequest(e),n.instrument_logger.info("Patched @codegenie/serverless-express/src/frameworks/express.js successfully"),e}_patchSendRequest(e){const t=e.sendRequest;e.sendRequest=function(e){let r,s;const a=i.HttpEndpointMetric.createUsableMetric();try{if(r=e.request,s=e.response,!r||!s)return t.call(this,e);a.start(),a.setRequestAttributes(r),r[n.hudConfig.metricSymbol]=a}catch(e){n.instrument_logger.error("Failed to start flowMetric during sendRequest patching",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}const c=(0,o.runWithInvestigation)(()=>t.call(this,e));try{s.once("finish",function(){try{(0,o.finishHttpInvestigation)(r,s,a),a.setResponseAttributes(s),a.end()}catch(e){n.instrument_logger.error("Failed to end flowMetric during sendRequest patching",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}})}catch(e){n.instrument_logger.error("Failed to end flowMetric during sendRequest patching",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return c},(0,s.copyPropertiesToTarget)(t,e.sendRequest)}}t.default=c},486:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(8269),o=r(2546),s=r(8949),i=r(828),a=r(714);class c extends a.FrameworkPatcher{_patch(e){return this._patchConsumer(e),o.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,n=[],a=[];!function(e,t){const r=e.subscribe;e.subscribe=async function(...e){const n=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):o.instrument_logger.warn("No topic found in KafkaJS.Consumer.subscribe",{args:e[0]})}catch(e){o.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 n},(0,s.copyPropertiesToTarget)(r,e.subscribe)}(r,a),function(e,t,r,n,a){const c=e.run;function p(e,c){const p="eachBatch"===c;for(const e of a)f(e,n,t,r,c);const g=function(e,t,r){return n=>{const s=n[0],i=r?s.batch.topic:s.topic;return function(e,t,r,n){const s=e.get(d(r,n));if(s)return s;for(const e of t)if(e.isBatch===n&&e.pattern.test(r))return e.flowId;o.instrument_logger.warn("No flowId found for topic",{topicName:r,isBatch:n})}(e,t,i,r)}}(t,r,p),m=function(e){return(t,r,n)=>{const s=i.KafkaJSMetric.createUsableMetric();s.start(),s.setFlowId(t);const a=n[0];void 0!==a&&void 0!==a.message&&(a.message[o.hudConfig.metricSymbol]=s);const c=e?a.batch.partition:a.partition,u=e?a.batch.messages[0]?.timestamp:a.message?.timestamp;s.addPartition(c),s.addProducedTimestamp(u),r.flowMetric=s}}(p),h=(0,s.wrapFlow)(g,e[c],!0,m,u,l);e[c]=h}e.run=async function(...e){try{const t=e[0];t.eachMessage&&p(t,"eachMessage"),t.eachBatch&&p(t,"eachBatch")}catch(e){o.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 c.apply(this,e)},(0,s.copyPropertiesToTarget)(c,e.run)}(r,t,n,e[0].groupId,a)}catch(e){o.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,s.copyPropertiesToTarget)(t,e.Kafka.prototype.consumer)}}function u(e,t){const r=t.flowMetric;r?r.end():o.instrument_logger.warn("No flowMetric found for message",{flowId:e})}function l(e,t,r){const n=t.flowMetric;n?(n.setError(r),n.end()):o.instrument_logger.warn("No flowMetric found for message",{flowId:e})}function d(e,t){return e+"|"+t}function f(e,t,r,s,i){const a=(0,o.generateKafkaFlowId)(e,t,i),c={flow_id:a,topic_name:e.toString(),group_id:t,pulling_type:i};(0,n.storeKafkaJSTopicDeclaration)(c),function(e,t,r,n,o){"string"==typeof r?e.set(d(r,n),o):t.push({pattern:r,isBatch:n,flowId:o})}(r,s,e,"eachBatch"===i,a)}t.default=c},646:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2546),o=r(8949),s=r(714),i=r(3531);class a extends s.FrameworkPatcher{_patch(e){return this._patchCreate(e),n.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 s=(0,i.generateKey)(t,r);s&&(e[1]=(0,o.wrapFlow)(()=>{try{const e=(0,i.getRequestByCallback)(s);if(!e)return void n.instrument_logger.error("No request object found for key",{key:s});const t=function(e){if(e&&!e.raw&&e.socket)return e[n.hudConfig.metricSymbol]?e[n.hudConfig.metricSymbol].getFlowId?e[n.hudConfig.metricSymbol].getFlowId():void n.instrument_logger.error("No getFlowId function found on metric object"):void n.instrument_logger.error("No metric found on nestjs request object")}(e);return t||n.instrument_logger.error("No flow id found for key",{key:s}),t}catch(e){n.instrument_logger.error("Error in NestJS getFlowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}},r,!0))}else n.instrument_logger.error("Invalid args in NestJS RouterExecutionContext.create",{args:e})}catch(e){n.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,o.copyPropertiesToTarget)(t,e.RouterExecutionContext.prototype.create)}}t.default=a},714:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.FrameworkPatcher=void 0,t.isSupportedVersion=d,t.extractModuleVersion=f,t.getFrameworkPatcher=function(e){return new(r(2828)(`./${e}`).default)};const a=r(2546),c=r(9896),u=i(r(6928)),l=r(8064);function d(e,t){return""===e||l.satisfies(l.coerce(e),t)}function f(e){try{const t=(0,c.readFileSync)(u.join(e,"package.json"),{encoding:"utf8"}),r=JSON.parse(t).version;return"string"==typeof r?r:""}catch(t){a.instrument_logger.info("Failed extracting version",{baseDir:e})}return""}t.FrameworkPatcher=class{patch(e,t,r,n,o=this.constructor.name){try{if(this.isSupported(t,o,r,n))return this._patch(e)}catch(e){a.instrument_logger.error("Unhandeled error during patching framework",{framework:o,error:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return e}isSupported(e,t,r,n){const o=f(e);return!!d(o,r)||(a.instrument_logger.warn("Unsupported version",{framework:t,version:o,supportedVersion:r,basedir:e}),a.customer_logger.log(a.UserErrorLogs.UnsupportedFrameworkVersion(t)),!1)}}},828:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.KafkaJSMetric=void 0;const n=r(2546),o=r(7131),s=r(9873);class i extends s.FlowMetric{partition;error;producedTimestamp;totalConsumeDuration;constructor(e){super(e)}_createUsableMetric(e){return this}end(){this.producedTimestamp&&(this.totalConsumeDuration=Number(Date.now()-this.producedTimestamp)*Number(1e6)),super.end()}addProducedTimestamp(e){void 0!==e&&(this.producedTimestamp=Number(e))}addPartition(e){this.partition=e}setError(e){this.error=(0,o.extractName)(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},857:e=>{"use strict";e.exports=require("os")},932:e=>{"use strict";e.exports=require("process")},1321:e=>{"use strict";e.exports=require("reflect-metadata")},1326:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=r(2546),s=r(8949),i=r(714),a=n(r(9589));class c extends i.FrameworkPatcher{static nextJSHudMarked=Symbol.for("hudNextJSMarked");_patch(e){return(0,o.setIsNextJsApp)(!0),this._pathLoad(e),o.instrument_logger.info("Patched Next.js successfully"),e}_pathLoad(e){try{const t=e.RouteModuleLoader;if(t[c.nextJSHudMarked])return e;const r=t.load;t.load=async function(...e){const t=await r.apply(this,e);try{if(t){const e=t.definition?.pathname;e&&!t[c.nextJSHudMarked]&&(a.default._detectAndPatchSupportedMethods(t,e),t[c.nextJSHudMarked]=!0)}}catch(e){o.instrument_logger.error("Failed to patch Next.js route module",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t},t[c.nextJSHudMarked]=!0,(0,s.copyPropertiesToTarget)(r,t.load)}catch(e){o.instrument_logger.error("Failed to patch Next.js base server",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return e}}t.default=c},1427:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getSystemInfo=function(){return{pod_name:u(),node_name:l()}};const o=n(r(9896)),s=n(r(857)),i=Symbol("not found");let a,c;function u(){if(a!==i){if(a)return a;try{return a=s.default.hostname(),a}catch(e){return void(a=i)}}}function l(){if(c!==i){if(c)return c;try{const e=o.default.readFileSync("/etc/machine-id","utf8").trim();return c=e,c}catch(e){return void(c=i)}}}},1502:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(8528),o=r(8269),s=r(2546),i=r(8949),a=r(714);class c extends a.FrameworkPatcher{static koaModuleName="koa";static koaPatchedSymbol=Symbol.for(s.hudConfig.hudPatchedName);_patch(e){return this._patchAppUse(e),s.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++)c._wrapRoute(e[t])}catch(e){s.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,i.copyPropertiesToTarget)(t,e.prototype.use)}static _wrapRoute(e){if(e.methods&&0===e.methods.length)return;if(!e.stack[0][c.koaPatchedSymbol]){const t=(0,i.wrapFlow)(p,e.stack[0],!0,u);e.stack[0]=t,e.stack[0][c.koaPatchedSymbol]=!0}const t=(0,s.generateEndpointFlowId)(e.path,e.methods);(0,o.storeEndpointDeclaration)(new n.EndpointDeclaration(t,e.methods,"koa",void 0,e.path));for(const r of e.methods)f(t,e.path,r)}}function u(e,t,r){if(!r[0])return void s.instrument_logger.error("No ctx object found in koa");const n=r[0].req;if(!n)return void s.instrument_logger.error("No req found in koa ctx");const o=n[s.hudConfig.metricSymbol];o?o.setFlowId(e):s.instrument_logger.error("No endpoint metric found in koa req")}function l(e,t){return e+"|"+t}t.default=c;const d=new Map;function f(e,t,r){d.set(l(t,r),e)}function p(e){if(0===e.length)return;const t=e[0]._matchedRoute,r=e[0].req?.method;return function(e,t){return d.get(l(e,t))}(t,r)}},1943:e=>{"use strict";e.exports=require("fs/promises")},1952:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.createDirectoryExcludeCheckers=c,t.shouldExcludeDirectory=u,t.getAllFilesInDirectory=d,t.getNodeModulesFiles=f,t.getFiles=async function(e,t,r,n){const o=[],s=c(n||[]);for(const t of e){const e=await d(t,s);o.push(...e)}if(r){const e=await f(r,t);o.push(...e)}return o};const o=r(1943),s=n(r(6928)),i=r(2197);function a(e){return e.endsWith(".js")}function c(e){const t=[];for(const r of e){let e;if(r.includes("*")){const t=r.split("*").join(".*?"),n=new RegExp(`^${t}$`);e=e=>n.test(e)}else e=e=>e===r;t.push(e)}return t}function u(e,t){for(const r of t)if(r(e))return!0;return!1}async function l(e,t,r){const n=[];let i;try{i=await(0,o.readdir)(e,{withFileTypes:!0})}catch{return n}for(const o of i){const i=s.default.join(e,o.name);if(o.isFile())a(i)&&!t(i)&&n.push(o);else if(o.isDirectory()&&!r(i)){const e=await l(i,t,r);n.push(...e)}}return n}async function d(e,t){const r=t||[];return l(e,()=>!1,e=>{const t=s.default.basename(e);return"node_modules"===t||u(t,r)})}async function f(e,t){return l(e.endsWith(s.default.sep)?e:e+s.default.sep,e=>(0,i.skip)(e,t),()=>!1)}},2030:e=>{"use strict";e.exports=require("./instrument")},2080:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.SqsMetric=void 0;const n=r(9873);class o extends n.FlowMetric{errors;msgCount;e2eEpocStartTimeMS;e2eDurationNS;_finishedMessageCount;constructor(e){super(e),this._finishedMessageCount=0,this.errors=new Map}addError(e,t=1){this.errors.set(e,(this.errors.get(e)??0)+t)}increaseAndShouldEnd(e=1){return this._finishedMessageCount+=e,!(this.msgCount&&this._finishedMessageCount<this.msgCount)}end(){this.e2eEpocStartTimeMS&&(this.e2eDurationNS=Number(Date.now()-this.e2eEpocStartTimeMS)*Number(1e6)),super.end()}_createUsableMetric(e){return this}toRaw(){return{flow_id:this.flowId,type:"SqsMetric",duration:this.duration,e2e_duration:this.e2eDurationNS,msg_count:this.msgCount,errors:this.errors}}}t.SqsMetric=o},2197:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||o(t,e,r)},a=this&&this.__importStar||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.koa=t.express=t.safeLog=t.registerHook=t.hudRITM=void 0;var c=r(5688);Object.defineProperty(t,"hudRITM",{enumerable:!0,get:function(){return c.hudRITM}}),Object.defineProperty(t,"registerHook",{enumerable:!0,get:function(){return c.registerHook}}),Object.defineProperty(t,"safeLog",{enumerable:!0,get:function(){return c.safeLog}}),i(r(3901),t),t.express=a(r(7127)),i(r(714),t),t.koa=a(r(1502)),i(r(7166),t)},2546:e=>{"use strict";e.exports=require("./lib")},2698:e=>{"use strict";e.exports=require("p-limit")},2729:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2546),o=r(2822),s=r(8949),i=r(8901),a=r(714);class c extends a.FrameworkPatcher{_patch(e){const t=this._patchGetFramework(e);return n.instrument_logger.info("Patched serverless-http/lib/framework/get-framework.js successfully"),t}_patchGetFramework(e){const t=e;return e=function(...e){const r=t.apply(t.this,e);async function a(e,...t){const s=i.HttpEndpointMetric.createUsableMetric();try{s.start(),s.setRequestAttributes(e),e[n.hudConfig.metricSymbol]=s}catch(e){n.instrument_logger.error("Failed to start flowMetric during framework serverless request handler patching",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}const a=await(0,o.runWithInvestigation)(()=>r.apply(r.this,[e,...t]));return a.once("finish",function(){try{(0,o.finishHttpInvestigation)(e,a,s),s.setResponseAttributes(a),s.end()}catch(e){n.instrument_logger.error("Failed to end flowMetric during framework serverless request handler patching",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}),a}return(0,s.copyPropertiesToTarget)(r,a),a},(0,s.copyPropertiesToTarget)(t,e),e}}t.default=c},2741:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2546),o=r(6730),s=r(4815),i=r(7225),a=r(714);class c extends a.FrameworkPatcher{_patch(e){return i.isVerboseLoggingEnabled?((0,o.patchMethods)(e,"application_export"),(0,s.patchUse)(e,"application",!1),(0,i.logLazyRouter)(e),n.instrument_logger.info("Patched express.Application successfully"),e):(n.instrument_logger.info("Skipping express.Application patching, verbose logging is not enabled"),e)}}t.default=c},2784:e=>{"use strict";e.exports=require("../native/_index")},2822:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getStackTrace=l,t.serializableInvestigation=p,t.getBaseInvestigationStorage=g,t.createNewInvestigation=function(){globalThis.hudEnableInvestigation&&(0,i.getStorage)().enterWith(g())},t.runWithInvestigation=function(e){return globalThis.hudEnableInvestigation?(0,i.getStorage)().run(g(),e):e()},t.closeInvestigation=m,t.storeInvestigation=h,t.getStacktraceUniqString=v,t.finishHttpInvestigation=function(e,t,r){if(t.statusCode<500)return;const n=w(r);if(void 0===n)return void f("finishHttpInvestigation: base investigation return undefined");const o=r.getFlowId(),s=r.getMsStartTime();void 0!==o&&void 0!==r.route&&void 0!==r.method&&void 0!==s?h(n,{type:"http",endpoint_uuid:o,route:r.route,method:r.method,timestamp:s,params:e.params,query:e.query,request_body:b(e.body),status_code:t.statusCode,machine_metrics:(0,a.getMachineMetrics)(),observability_identifiers:(0,c.getObservabilityIdentifiers)(e),system_info:(0,u.getSystemInfo)()}):f("route, method, or reqTimestamp is undefined even though they shouldn't",{flowId:o,route:r.route,method:r.method,reqTimestamp:s})},t.finishSqsInvestigation=function(e,t){if(0===t.errors.size)return;const r=w(t);if(void 0===r)return void f("finishSqsInvestigation: investigation is undefined");const n=t.getFlowId(),o=t.getMsStartTime();void 0!==o&&void 0!==n?h(r,{type:"sqs",timestamp:o,flow_id:n,messages:b(e),machine_metrics:(0,a.getMachineMetrics)(),system_info:(0,u.getSystemInfo)()}):f("reqTimestamp is undefined even though it shouldn't",{flowId:n})};const n=r(8528),o=r(8269),s=r(2546),i=r(7131),a=r(7808),c=r(7603),u=r(1427);function l(e,t){if(void 0===t)return;const r=function(e){let t=0;for(let r=0;r<e.length;r++)"\n"===e[r]&&t++;return t}(e)+1;let n=-1;for(let e=0;e<r;e++)if(n=t.indexOf("\n",n+1)??-1,-1===n)return;return-1!==n?t.slice(n+1):void 0}const d={};function f(e,...t){let r="debug";(void 0===d[e]||d[e]<s.hudConfig.dynamicConfig.investigationRateLimits.maxUniqLogs)&&(r="warn",d[e]=d[e]+1||1),s.app_logger.logLevel(r,e,...t)}function p(e){return{status:e.status,context:e.context,exceptions:Array.from(Array.from(e.exceptions?.values()??[]).map(({exception:e,executionFlow:t})=>({name:(0,i.extractNameOptional)(e),message:(0,i.extractMessage)(e),stackTrace:l(e.message,e.stack),executionFlow:t}))??[])}}function g(){return{status:n.InvestigationStatus.Open}}function m(){if(!globalThis.hudEnableInvestigation)return;const e=(0,i.getStorage)().getStore();return void 0!==e&&e.status===n.InvestigationStatus.Open?(e.status=n.InvestigationStatus.Closed,e):void 0}function h(e,t){e.context=t,(0,o.storeClosedInvestigation)(p(e))}const y=/.*\((.*):(\d+):(\d+)\)/,_=/.*?(\S*):(\d+):(\d+)/;function v(e){const t=Error.prepareStackTrace;if(void 0===t||"function"!=typeof t)return void f("getStacktraceUniqString: prepareStackTrace is undefined or not a function");let r,n;try{Error.prepareStackTrace=(e,t)=>{r=t[0],n=t};const o=e.stack;if(void 0!==o&&void 0===r){const t=function(e,t){const r=l(t,e);if(void 0===r)return;const n=r.indexOf("\n");return r.slice(0,-1===n?void 0:n)}(o,e.message);if(!t)return void f("getStacktraceUniqString: firstStackTraceLine is undefined",{stack:o,message:e.message});const r=t.match(y);if(r&&r[1]&&r[2]&&r[3])return`${e.name}@${r[1]}:${r[2]}:${r[3]}`;const n=t.match(_);return n&&n[1]&&n[2]&&n[3]?`${e.name}@${n[1]}:${n[2]}:${n[3]}`:void f("getStacktraceUniqString: no match found in regex",{stack:o,message:e.message})}if(void 0===r||void 0===n)return void f("getStacktraceUniqString: result or globCallSites is undefined",{result:void 0===r,globCallSites:void 0===n});Object.defineProperty(e,"stack",{configurable:!0,enumerable:!1,get:()=>t(e,n)})}finally{Error.prepareStackTrace=t}try{return`${e.name}@${r.getFileName()}:${r.getLineNumber()}:${r.getColumnNumber()}`}catch{}}function b(e,t=s.hudConfig.investigation.maxObjectDepth){try{if("string"==typeof e)return e.length>s.hudConfig.investigation.maxStringLength?e.slice(0,s.hudConfig.investigation.maxStringLength)+"...":e;if(Array.isArray(e))return e.slice(0,s.hudConfig.investigation.maxArrayLength).map(e=>b(e,t-1));if(null===e||["number","boolean"].includes(typeof e))return e;if("bigint"==typeof e)return e.toString();if("object"==typeof e){const r={...e};for(const n in e)r[n]=b(e[n],t-1);return r}}catch{}}function w(e){const t=m();if(void 0===t)return void f("finishBaseInvestigation: investigation is undefined");if(void 0===t.firstException)return void f("finishBaseInvestigation: firstException is undefined");if(o.globalInvestigationTracking>=s.hudConfig.dynamicConfig.investigationRateLimits.maxTotalInvestigations)return void f("finishBaseInvestigation: globalInvestigationTracking is greater than maxTotalInvestigations",{globalInvestigationTracking:o.globalInvestigationTracking,maxTotalInvestigations:s.hudConfig.dynamicConfig.investigationRateLimits.maxTotalInvestigations});const r=e.getFlowId();if(void 0===r)return void f("finishBaseInvestigation: flowId is undefined");const n=v(t.firstException);if(void 0===n)return void f("finishBaseInvestigation: exceptionUniqString is undefined");const i=((0,o.getInvestigationDedupingCache)(r).get(n)??0)+1;if(!(i>s.hudConfig.dynamicConfig.investigationRateLimits.maxSameInvestigations))return(0,o.increaseGlobalInvestigationTracking)(),(0,o.increaseInvestigationDedupingCache)(r,n),t;f("finishBaseInvestigation: investigationCount is greater than maxSameInvestigations",{investigationCount:i,maxSameInvestigations:s.hudConfig.dynamicConfig.investigationRateLimits.maxSameInvestigations})}},2828:(e,t,r)=>{var n={"./codeGenieServerlessExpress":336,"./codeGenieServerlessExpress.ts":336,"./express":7127,"./express.ts":7127,"./express/methods":6730,"./express/methods.ts":6730,"./express/route":2977,"./express/route.ts":2977,"./express/router":4815,"./express/router.ts":4815,"./express/verbosity":7225,"./express/verbosity.ts":7225,"./expressApplication":2741,"./expressApplication.ts":2741,"./flows/endpoints/metrics":8901,"./flows/endpoints/metrics.ts":8901,"./flows/flow":9873,"./flows/flow.ts":9873,"./flows/graphql":6504,"./flows/graphql.ts":6504,"./flows/kafkajs":828,"./flows/kafkajs.ts":828,"./flows/sqs":2080,"./flows/sqs.ts":2080,"./frameworkPatcher":714,"./frameworkPatcher.ts":714,"./graphql":7214,"./graphql.ts":7214,"./http":5459,"./http.ts":5459,"./kafkajs":486,"./kafkajs.ts":486,"./koa":1502,"./koa.ts":1502,"./nestjsInterceptor":3531,"./nestjsInterceptor.ts":3531,"./nestjsRouterExecutionContext":646,"./nestjsRouterExecutionContext.ts":646,"./nestjsRpcContextCreator":4290,"./nestjsRpcContextCreator.ts":4290,"./nextJsConfig":9723,"./nextJsConfig.ts":9723,"./nextJsModuleLoader":1326,"./nextJsModuleLoader.ts":1326,"./nextRequestAdapter":7246,"./nextRequestAdapter.ts":7246,"./nextjs":9589,"./nextjs.ts":9589,"./router":5946,"./router.ts":5946,"./serverlessHttp":2729,"./serverlessHttp.ts":2729,"./sqsConsumer":5150,"./sqsConsumer.ts":5150};function o(e){var t=s(e);return r(t)}function s(e){if(!r.o(n,e)){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}return n[e]}o.keys=function(){return Object.keys(n)},o.resolve=s,e.exports=o,o.id=2828},2977:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.patchRoute=function(e){const t=(0,f.getMethods)();t.concat("all").forEach(function(r){const n=e.prototype[r];e.prototype[r]=function(){let e;try{e=p(Array.prototype.slice.call(arguments));let n=function(e){const t=e[0][u.hudConfig.express.layerStateSymbol];if(t)return t.flowId}(e);const o=function(e){const t=e[0][u.hudConfig.express.layerStateSymbol];if(t)return t.kind}(e),s=function(e){const t=e[0][u.hudConfig.express.layerStateSymbol];return!!t&&t.allMethod}(e);if(n||(n=[l.randomUUID()]),"application"===o)if(Array.isArray(this.path)){h(e,void 0);for(let e=0;e<this.path.length;e++)m(n[e],s?t:[r],this.path[e])}else h(e,n[0]),m(n[0],s?t:[r],this.path);else if("router"===o)if(Array.isArray(this.path)){h(e,void 0);for(let e=0;e<this.path.length;e++)g(this,n[e],r,this.path[e])}else h(e,n[0]),g(this,n[0],r,this.path);else h(e,n[0]),g(this,n[0],r,this.path)}catch(e){u.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 n.apply(this,e||arguments)}})};const a=r(8528),c=r(8269),u=r(2546),l=i(r(6982)),d=r(8949),f=r(6730),p=r(8054);function g(e,t,r,n){!function(e,t,r,n){e[u.hudConfig.express.layerStateSymbol]||(e[u.hudConfig.express.layerStateSymbol]={}),e[u.hudConfig.express.layerStateSymbol][t]?e[u.hudConfig.express.layerStateSymbol][t].methods.push(r):e[u.hudConfig.express.layerStateSymbol][t]={layerPath:n,methods:[r]}}(e,t,r,n),function(e,t,r){const n=new a.EndpointDeclaration(e,[t],"express",void 0,void 0,r);(0,c.storePartialEndpointDeclaration)(n),(0,c.storeExpressEndpointDeclaration)(n)}(t,r,n)}function m(e,t,r){const n=new a.EndpointDeclaration(e,t,"express",void 0,r,void 0);(0,c.storeExpressEndpointDeclaration)(n)}function h(e,t){if(e&&!(e.length<1)){if(u.hudConfig.express.wrapAllCallbacks)for(let r=0;r<e.length;r++){const n=(0,d.wrapFlow)(_(t),e[r],!0,v);e[r]=n}else{const r=(0,d.wrapFlow)(_(t),e[e.length-1],!0,v);e[e.length-1]=r}return t}}function y(e){return(0,c.getLinkedConsistentFlowId)(e,!1)||(u.instrument_logger.warn("No consistent flowId found, returning temporary flow id",{flowId:e}),e)}function _(e){return e?function(){return y(e)}:function(e){const t=e[0]?.route[u.hudConfig.express.layerStateSymbol],r=e[0]?.url;if(t)for(const[e,n]of Object.entries(t)){if(n.layerPath instanceof RegExp&&n.layerPath.test(r))return y(e);if(r.includes(n.layerPath))return y(e)}u.instrument_logger.warn("No flowId found for path",{states:t,url:r.split("?")[0]})}}function v(e,t,r){let n=0;if(4===r.length)n=1;else if(3!==r.length)return void u.instrument_logger.error("Invalid number of arguments in express request",{length:r.length});if(!r[n])return void u.instrument_logger.error("No request object in express request");const o=r[n][u.hudConfig.metricSymbol];o?o.setFlowId(e):u.instrument_logger.error("No endpoint metric found in express request")}},2987:e=>{"use strict";e.exports=require("perf_hooks")},3106:e=>{"use strict";e.exports=require("zlib")},3176:e=>{"use strict";e.exports=require("buffer-crc32")},3339:e=>{"use strict";e.exports=require("module")},3531:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getRequestByCallback=function(e){const t=i.get(e);return t&&i.delete(e),t},t.generateKey=a;const n=r(2546);r(1321);const o=r(8949),s=r(714),i=new Map;function a(e,t){const r=Reflect.getMetadata("path",t)??Reflect.getMetadata("microservices:pattern",t);if(!r)return void n.instrument_logger.error("No callback path found on callback",{callback:t});const o=e.constructor.CONTROLLER_ID;if(o)return`${o}.${r}`;n.instrument_logger.error("No controller id found on controller",{controller:e})}class c extends s.FrameworkPatcher{_patch(e){return this._patchIntercept(e),n.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 n;if("rpc"===e[5]){if("win32"===process.platform)return;n=e[1][1].args[0]}else if(n=e[1][0],!n||n.raw)return;const o=a(t,r);if(!o)return;i.set(o,n)}else n.instrument_logger.error("Invalid args in NestJS InterceptorsConsumer.intercept",{args:e})}catch(e){n.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,o.copyPropertiesToTarget)(t,e.InterceptorsConsumer.prototype.intercept)}}t.default=c},3868:e=>{"use strict";e.exports=require("@jridgewell/sourcemap-codec")},3901:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t}),a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.destructImportObj=t.defaultImportObj=void 0,t.getFunctionWrapperTemplate=v,t.splitCode=E,t.editInSplits=M,t.editWithCliBuildId=function(e,t,r,n){let{transformedCode:o,metadatas:s}=F(e,t,r,!0);return o+=`\n//# sourceMappingURL=${h.default.basename(t)}.map`,o+=`\n//"${n}";${l.hudConfig.cliSdkVersionVarName}="${l.SDK_VERSION}";${l.hudConfig.cliBuildIdVarName}`,{transformedCode:o,metadatas:s}},t.edit=F,t.incrementInstrumentedFunctionsCount=N;const c=a(r(3176)),u=r(3903),l=r(2546),d=r(8528),f=r(8269),p=r(2546),g=r(3868),m=i(r(2784)),h=a(r(6928)),y=/([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){return`\n ${l.hudConfig.afterYieldFunctionName}(\n ${e} ${l.hudConfig.beforeYieldFunctionName}(\n ${t}, ${l.hudConfig.callContextVarName}\n ),\n ${l.hudConfig.callContextVarName}\n )\n `}function v(e,r,n=!1){const o="BODY_PLACEHOLDER",s="FUNCTION_ID_PLACEHOLDER",i="AWAITABLE_PLACEHOLDER",a="EXCEPTION_VARIABLE_PLACEHOLDER",c=function(e,r,n=!1){const o=[];if(n)return o;let s;r===d.Format.cjs?s="require":r===d.Format.esm&&(o.push(`import { createRequire as ${e}_createRequire } from "module";`,`const ${e}_require = ${e}_createRequire(import.meta.url);`),s=`${e}_require`);const i=p.myRequire.resolve(l.SDK_MODULE_NAME+"/wrap");return o.push(`let ${e}_temp;`,`try {\n ${e}_temp = ${s}(String.raw\`${i}\`);\n } catch (e) {\n ${e}_temp = ${t.defaultImportObj};\n }`,`const ${t.destructImportObj} = ${e}_temp;`),o}(e,r,n);return{functionWrapper:`{\n let ${l.hudConfig.callContextVarName} = ${l.hudConfig.functionInitFunctionName}(${s});\n try {\n ${o}\n } catch (e) {\n ${l.hudConfig.functionCatchFunctionName}(e, ${l.hudConfig.callContextVarName});\n } finally {\n ${l.hudConfig.functionFinallyFunctionName}(${l.hudConfig.callContextVarName});\n }\n }`,awaitWrapper:`(\n ${_("await",i)}\n )`,yieldWrapper:`\n function* ${e}_generatorWrapper() {\n return (\n ${_("yield",i)}\n )\n }`,yieldStarWrapper:`\n function* ${e}_generatorWrapper() {\n return (\n ${_("yield*",i)}\n )\n }`,initialStatements:c,bodyPlaceholder:o,functionIdPlaceholder:s,awaitablePlaceholder:i,fixStackFunction:`${l.hudConfig.fixStackFunctionName}(${l.hudConfig.callContextVarName})`,exceptionVariablePlaceholder:a,wrapperUserCatch:`${l.hudConfig.wrapperUserCatchFunctionName}(${l.hudConfig.callContextVarName}, ${a});`,asyncIteratorWrapper:`${l.hudConfig.asyncIteratorWrapperFunctionName}`}}function b(e,t,r=!0,n=!1,o){const s=Error.prepareStackTrace;let i=!1,a=function(e){const t=e.match(`${l.hudConfig.bundlerBuildIdVarName}="${y.source}"`);if(t&&t.length>0)return t[1]}(e);a||(a=function(e){return(0,u.v5)(e,l.hudConfig.bundlerBuildUuidNamespace)}(e),i=!0);const d=(0,u.v5)(e,l.hudConfig.functionUuidNamespace),f=(0,c.default)(t.filename).readUInt32BE(),g=(0,c.default)(e).readUInt32BE(),h=(0,p.isNextJsApp)(),_={data:t,bundlerBuildId:a,prefix:l.hudConfig.wrapVarPrefix,...v(l.hudConfig.wrapVarPrefix,t.format,n),uuidNamespace:l.hudConfig.functionUuidNamespace,fileHash:d,useInputSourcemap:r,isNextJsFile:h,markCode:l.hudConfig.nextJsMarkVarName,enableForAwaitInstrumentation:!o},b=m.transform(e,_);return N(b.functionsIds.length,o),h&&b.marksCount!==b.functionsIds.length&&l.instrument_logger.warn("Marks count mismatch while instrumenting functions",{marksCount:b.marksCount,functionsIdsLength:b.functionsIds.length,filename:t.filename}),Error.prepareStackTrace=s,l.instrument_logger.debug(`Successfully transformed ${t.filename}`),{code:b.code,map:b.map,functionIds:b.functionsIds,filename:t.filename,hasInputMap:b.isInputSourcemap,bundlerBuildId:a,bundlerBuildIdGenerated:i,file_path_checksum:f,file_checksum:g,sourceCodeHash:d,moduleBase:b.moduleBase,isNextJsApp:h,marksCount:b.marksCount,detectedForAwaitLoops:b.detectedForAwaitLoops}}t.defaultImportObj="\n {\n wrapperInitial: () => {\n return {};\n },\n wrapperCatch: (e) => {\n throw e;\n },\n wrapperFinally: () => {},\n fixStack: () => {},\n wrapperUserCatch: () => {},\n beforeYield: (x) => x,\n afterYield: (x) => x,\n }\n",t.destructImportObj=`\n {\n wrapperInitial: ${l.hudConfig.functionInitFunctionName},\n wrapperCatch: ${l.hudConfig.functionCatchFunctionName},\n wrapperFinally: ${l.hudConfig.functionFinallyFunctionName},\n fixStack: ${l.hudConfig.fixStackFunctionName},\n asyncIteratorWrapper: ${l.hudConfig.asyncIteratorWrapperFunctionName},\n wrapperUserCatch: ${l.hudConfig.wrapperUserCatchFunctionName},\n beforeYield: ${l.hudConfig.beforeYieldFunctionName},\n afterYield: ${l.hudConfig.afterYieldFunctionName},\n }\n`;class w extends Error{}function k(e,t){if(e&&t)throw new w("Start mark found inside mark");if(!e&&!t)throw new w("End mark found outside mark")}function S(e,t,r,n){const o=e.split("\n");let s=r,i=n;return s+=o.length-1,s+=t.split("\n").length-1,s===r?i+=o.pop()?.length||0:i=o.pop()?.length||0,{lineOffset:s,columnOffset:i}}function*E(e){let t=!1,r=0,n=0,o=!1,s=0,i=0;const a=new RegExp(`globalThis\\s*?&&\\s*?\\(globalThis\\.${l.hudConfig.esbuildGlobalVar}\\s*?=\\s*?"(Start|End):(?<fileName>.*?)"\\);?`,"g");let c="";for(const u of e.matchAll(a)){if(o=!0,!u.groups)throw new w("No groups found in match");const[a,l]=u,d="Start"===l;k(d,t);let f="";if(t){const t=u.index+a.length;f=e.slice(r,t);const o=n+Buffer.byteLength(f,"utf8");yield{edit:!0,code:f,fileName:c,lineOffset:s,columnOffset:i,indexOffset:n,indexOffsetEnd:o},r=t,n=o}else{c=u.groups?.fileName;const t=u.index;f=e.slice(r,t),n+=Buffer.byteLength(f,"utf8"),r=t,yield{edit:!1,code:f}}t=!!d,({lineOffset:s,columnOffset:i}=S(f,a,s,i))}if(t)throw new w("End mark found outside mark");o?r<e.length&&(yield{edit:!1,code:e.slice(r)}):yield{edit:!1,code:e}}function x(e,t,r){l.instrument_logger.debug("Edit chunk",{fileName:e.fileName,size:e.code.length,edit:t}),r?.push({fileName:e.fileName,size:e.code.length,edit:t})}function C(e,t,r){const n=b(e.code,{filename:t,format:r},!1,!0,!1),o=n.code;return n.mapRelativeToChunk=n.map,n.map=function(e,t,r){"string"==typeof e&&(e=JSON.parse(e));const n=(0,g.decode)(e.mappings);return n.forEach(e=>{e.forEach(e=>{e.length>=4&&"number"==typeof e[2]&&("number"==typeof e[3]&&0===e[2]&&(e[3]+=r),e[2]+=t)})}),JSON.stringify({...e,mappings:(0,g.encode)(n),sourcesContent:void 0})}(n.map,e.lineOffset,e.columnOffset),{codeToAppend:o,metadata:{...n,filename:t,lineOffset:e.lineOffset,columnOffset:e.columnOffset}}}function M(e,t,r,n=!1,o=!1,s=()=>!0){const i=e.slice(-1e3);if(!o&&null!==m.getSourceMap(t,i))return l.instrument_logger.error("Source map found for esbuild split",{filename:t}),l.customer_logger.log(l.UserErrorLogs.EsbuildSourceMapFound()),(0,f.detachHud)(!1,!1),{transformedCode:e,metadatas:[],editedChunksSizes:void 0};let a="",c=0,u=0;const d=[];let p=0;const g=n?[]:void 0,h=v(l.hudConfig.wrapVarPrefix,r).initialStatements.join("\n"),y=function(e){return e.slice(l.hudConfig.esbuildMark.length,l.hudConfig.esbuildMark.length+36)}(e);for(const n of E(e)){p++;try{let e="",o=!1;if(n.edit&&(o=s(n.fileName),g&&x(n,o,g)),n.edit&&o){const o=C(n,t,r);e=o.codeToAppend,d.push({...o.metadata,bundlerBuildId:y,transformedLineOffset:c,transformedColumnOffset:u,indexOffset:n.indexOffset,indexOffsetEnd:n.indexOffsetEnd})}else e=0===a.length?I(n.code,h):n.code;({transformedCodeLineOffset:c,transformedCodeColumnOffset:u}=P(e,c,u)),a+=e}catch(r){return l.instrument_logger.error("Failed to patch index",{index:p,filename:t,msg:r instanceof Error?r.message:void 0,stack:r instanceof Error?r.stack:void 0}),{transformedCode:e,metadatas:[],editedChunksSizes:g}}}return{transformedCode:a,metadatas:d,editedChunksSizes:g}}function I(e,t){let r="";return e.startsWith('"use strict";')?(r+='"use strict";',r+=t,r+=e.slice(13),r):(r+=t,r+=e,r)}function P(e,t,r){const n=e.split("\n");return n.length>1?(t+=n.length-1,r=n.pop()?.length||0):r+=e.length,{transformedCodeLineOffset:t,transformedCodeColumnOffset:r}}function F(e,t,r,n){if(e.startsWith(l.hudConfig.esbuildMark))return l.instrument_logger.info("Editing in splits"),M(e,t,r,!1);{const o=b(e,{filename:t,format:r},l.hudConfig.userConfig.disableSourceMapsResolution?.value??!0,!1,n);return{transformedCode:o.code,metadatas:[o]}}}let O=0;function N(e,t){O+=e;const r=l.hudConfig.userConfig?.maxMappedFunctions?.value??0;O>=r&&(t||l.customer_logger.log(l.UserErrorLogs.InstrumentedFunctionCountExceeded(r)),l.app_logger.error("Instrumented function count exceeded",{instrumentedFunctionsCount:O,maxMappedFunctions:r}),(0,f.detachHud)(!1,!1))}},3903:e=>{"use strict";e.exports=require("uuid")},4290:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2546),o=r(8949),s=r(714),i=r(3531);class a extends s.FrameworkPatcher{_patch(e){return this._patchCreate(e),n.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 s=(0,i.generateKey)(t,r);s&&(e[1]=(0,o.wrapFlow)(()=>{try{const e=(0,i.getRequestByCallback)(s);if(!e)return void n.instrument_logger.error("No msg object found for key",{key:s});const t=function(e){if(e)return e[n.hudConfig.metricSymbol]?e[n.hudConfig.metricSymbol].getFlowId?e[n.hudConfig.metricSymbol].getFlowId():void n.instrument_logger.error("No getFlowId function found on metric object"):void n.instrument_logger.error("No metric found on nestjs msg object")}(e);return t||n.instrument_logger.error("No flow id found for key",{key:s}),t}catch(e){n.instrument_logger.error("Error in NestJS getFlowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}},r,!0))}else n.instrument_logger.error("Invalid args in NestJS RpcContextCreator.create",{args:e})}catch(e){n.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,o.copyPropertiesToTarget)(t,e.RpcContextCreator.prototype.create)}}t.default=a},4815:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.patchUse=function(e,t,r=!0){const n=e.use;e.use=function(e){const o=n.apply(this,arguments);try{let n=this[d.uuidSymbol];!n&&d.isVerboseLoggingEnabled&&(n=u.randomUUID(),this[d.uuidSymbol]=n,c.instrument_logger.info("Express use setting uuid",{kind:t,uuid:n})),"application"===t?function(e,t,r,n){try{r&&(e._router?p(e._router):e.router?p(e.router):c.instrument_logger.warn("Express application doesn't have router or _router")),n&&d.isVerboseLoggingEnabled&&c.instrument_logger.info("Express use app",{parent:n,child:t[1]?.[d.uuidSymbol]||"no uuid",path:t[0]})}catch(e){c.instrument_logger.error("Failed to save express app router",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}(this,arguments,r,n):"router"===t&&function(e,t,r,n,o){try{if(!e.stack)return void c.instrument_logger.error("Express router without stack");if(0===e.stack.length)return void c.instrument_logger.warn("Express router with an empty stack");"query"===e.stack[0].name?p(e):d.isVerboseLoggingEnabled&&!d.skipLayerNamesLogs.has(e.stack[0].name)&&(d.skipLayerNamesLogs.add(e.stack[0].name),c.instrument_logger.warn("Found unknown stack name",{stack:e.stack[0].name}));const{path:s,offset:i}=function(e){let t=0,r="/";if("function"!=typeof e){let n=e;for(;Array.isArray(n)&&0!==n.length;)n=n[0];"function"!=typeof n&&(t=1,r=e)}return{path:r,offset:t}}(o),a=f(Array.prototype.slice.call(t,i));for(let t=0;t<a.length&&t<e.stack.length;t++){const o=e.stack[e.stack.length-t-1],i=a[a.length-t-1];"router"===o.name?(i&&!i[d.uuidSymbol]&&d.isVerboseLoggingEnabled&&(i[d.uuidSymbol]=u.randomUUID(),c.instrument_logger.info("Express handle router setting uuid",{uuid:i[d.uuidSymbol]})),r&&(o[c.hudConfig.express.routeNamesSymbol]=s)):d.isVerboseLoggingEnabled&&!d.skipLayerNamesLogs.has(o.name)&&(d.skipLayerNamesLogs.add(o.name),c.instrument_logger.warn("Found unknown layer name",{layer:o.name,parent:n,child:i[d.uuidSymbol]||"no uuid",path:s}))}}catch(e){c.instrument_logger.error("Failed to patch router.use function",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}(this,arguments,r,n,e)}catch(e){c.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})}return o},(0,l.copyPropertiesToTarget)(n,e.use)},t.extractEndpointsFromRouter=function e(t,r){let n=[];if(!r.stack)return c.instrument_logger.error("Router without stack - bad OTEL version",{router:r}),n;for(const o of r.stack)if("router"===o.name){if(!o[c.hudConfig.express.routeNamesSymbol]){c.instrument_logger.error("Router layer without routes",{layer:o});continue}const r=t+o[c.hudConfig.express.routeNamesSymbol];n=n.concat(e(r,o.handle))}else o.route&&o.route[c.hudConfig.express.layerStateSymbol]?n=n.concat(g(o,t)):d.isVerboseLoggingEnabled&&!d.skipLayerNamesLogs.has(o.name)&&(d.skipLayerNamesLogs.add(o.name),c.instrument_logger.warn("Found unknown layer name when extracting endpoints",{layer:o.name}));return n};const a=r(8528),c=r(2546),u=i(r(6982)),l=r(8949),d=r(7225),f=r(8054);function p(e){e[c.hudConfig.express.markedSymbol]||(globalThis.hudExpressState.push(e),e[c.hudConfig.express.markedSymbol]=!0)}function g(e,t){const r=[];for(const[n,o]of Object.entries(e.route[c.hudConfig.express.layerStateSymbol]))r.push(new a.EndpointDeclaration(n,o.methods,"express",t,o.layerPath));return Array.from(r.values())}},5150:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(8269),o=r(2546),s=r(7131),i=r(2822),a=r(8949),c=r(2080),u=r(714);class l extends u.FrameworkPatcher{isSupported(e,t,r,n){const s=o.hudConfig.userConfig.enableDapulse?.value?n.mondayVersion:n.bbcVersion,i=(0,u.extractModuleVersion)(e);return!!(0,u.isSupportedVersion)(i,s)||(o.instrument_logger.warn("Unsupported sqs-consumer version",{framework:"SqsConsumer",version:i,supportedVersion:s,basedir:e,isDapulse:o.hudConfig.userConfig.enableDapulse?.value}),o.customer_logger.log(o.UserErrorLogs.UnsupportedFrameworkVersion("sqs-consumer")),!1)}_patch(e){return function(e){const t=e.Consumer.create;e.Consumer.create=function(...e){const r=t.apply(this,e);try{!function(e){const t=e.queueUrl;if(!t)throw new o.HudNoQueueUrlInSqsConsumer;const r=p(t);if(e.handleMessageBatch&&"function"==typeof e.handleMessageBatch){const t="handleMessageBatch",s=(0,o.generateSqsFlowId)(r,t);(0,n.storeSqsQueueDeclaration)({flow_id:s,queue_name:r,handle_type:t,batch_size:e.batchSize});const i=e.handleMessageBatch,c=(0,a.wrapFlow)(()=>s,i,!0,g);return void(e.handleMessageBatch=c)}if(e.handleMessage&&"function"==typeof e.handleMessage){const t="handleMessage",s=(0,o.generateSqsFlowId)(r,t);(0,n.storeSqsQueueDeclaration)({flow_id:s,queue_name:r,handle_type:t});const i=e.handleMessage,c=(0,a.wrapFlow)(()=>s,i,!0,g);return void(e.handleMessage=c)}o.instrument_logger.warn("Unable to getFlowId - No handleMessage or handleMessageBatch found in SqsConsumer.Consumer",{queueName:r})}(r),function(e){const t=e.on;e.on=function(...r){try{const t=r[0];if(!t||"string"!=typeof t)throw new o.HudNoEventTypeInSqsConsumerOn;const s=r[1];if(!s||"function"!=typeof s)throw new o.HudNoCallbackInSqsConsumerOn;const i=p(e.queueUrl),c="event",u=(0,o.generateSqsFlowId)(i,c,t);(0,n.storeSqsQueueDeclaration)({flow_id:u,queue_name:i,handle_type:c,event_type:t}),r[1]=(0,a.wrapFlow)(()=>u,s,!0,m,h,y)}catch(e){o.instrument_logger.error("Error in SqsConsumer.Consumer.on patched logic",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t.apply(this,r)},(0,a.copyPropertiesToTarget)(t,e.on)}(r),function(e){const t=e.emit;e.emit=function(...e){return function(e){try{const t=e[0];if(!t||"string"!=typeof t)throw new o.HudNoEventTypeInSqsConsumerEmit;let r,n;if("message_processed"===t&&(r=1),["error","timeout_error","processing_error"].includes(t)&&(n=1,r=2),void 0===r)return;const a=e[r];if(!a)throw new o.HudNoMessageInSqsConsumerEmit;let c;if(void 0!==n){const t=e[n];if(!(t&&t instanceof Error))throw new o.HudNoErrorInSqsConsumerEmit;c=(0,s.extractName)(t),"StandardError"===c&&t.cause&&t.cause instanceof Error&&(c=(0,s.extractName)(t.cause))}const u=(e,t)=>{const r=e[o.hudConfig.metricSymbol];r?(c&&r.addError(c,t),r.increaseAndShouldEnd(t)&&(r.end(),(0,i.finishSqsInvestigation)(Array.isArray(a)?a:[a],r))):f||(f=!0,o.instrument_logger.warn("No metric found for message"))};Array.isArray(a)&&a.length>=1?u(a[0],a.length):u(a,1)}catch(e){d||(d=!0,o.instrument_logger.error("Error in SqsConsumer.Consumer.emit patched logic",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0}))}}(e),t.apply(this,e)},(0,a.copyPropertiesToTarget)(t,e.emit)}(r)}catch(e){o.instrument_logger.error("Error in patching SqsConsumer.Consumer",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return r},(0,a.copyPropertiesToTarget)(t,e.Consumer.create)}(e),o.instrument_logger.info("Patched sqs-consumer successfully",{isDapulse:o.hudConfig.userConfig.enableDapulse?.value}),e}}t.default=l;let d=!1,f=!1;function p(e){const t=e.split("/").pop();if(!t)throw new o.HudFailExtractSqsQueueName(`Url: ${e}`);return t}function g(e,t,r){const n=c.SqsMetric.createUsableMetric(e);n.start();const s=r[0];if(!s)return o.instrument_logger.warn("No messages pass to sqs handler",{flowId:e}),void(t.flowMetric=n);if(Array.isArray(s)){if(n.msgCount=s.length,s.forEach(e=>{e[o.hudConfig.metricSymbol]=n}),s[0]?.Attributes?.SentTimestamp){const t=s.reduce((e,t)=>{const r=Number.parseInt(t?.Attributes?.SentTimestamp);return isNaN(r)?e:Math.min(e,r)},1/0);t!==1/0?n.e2eEpocStartTimeMS=t:o.instrument_logger.warn("No valid SentTimestamp found eventhough the first element had SentTimestamp",{flowId:e})}}else n.msgCount=1,s[o.hudConfig.metricSymbol]=n,s?.Attributes?.SentTimestamp&&(n.e2eEpocStartTimeMS=s.Attributes.SentTimestamp);t.flowMetric=n,(0,i.createNewInvestigation)()}function m(e,t,r){const n=c.SqsMetric.createUsableMetric(e);n.start(),t.flowMetric=n}function h(e,t){const r=t.flowMetric;r?r.end():o.instrument_logger.warn("No flowMetric found for message during catch",{flowId:e})}function y(e,t,r){const n=t.flowMetric;n?(n.addError((0,s.extractName)(r)),n.end()):o.instrument_logger.warn("No flowMetric found for message during catch",{flowId:e})}},5459:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getHttpMetricFromRequest=function(e){return e[n.hudConfig.metricSymbol]};const n=r(2546),o=r(2822),s=r(8949),i=r(8901),a=r(714);class c extends a.FrameworkPatcher{_patch(e){return this._patchEmit(e),n.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],s=i.HttpEndpointMetric.createUsableMetric();s.start(),(0,o.createNewInvestigation)(),s.setRequestAttributes(e),t.once("finish",function(){try{(0,o.finishHttpInvestigation)(e,t,s),s.setResponseAttributes(t),s.end()}catch(e){n.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[n.hudConfig.metricSymbol]=s}catch(e){n.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,s.copyPropertiesToTarget)(t,e.Server.prototype.emit)}}t.default=c},5688:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.hudRITM=void 0,t.safeLog=function(e){try{o.app_logger.debug(e)}catch(e){return}},t.registerHook=function(){if(o.app_logger.info("HUD is required"),process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE){if(o.app_logger.info("Running in Lambda environment"),parseInt(process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE)<o.hudConfig.lambdaMinimunMemory){const e=process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE;return o.app_logger.warn("Lambda function memory size is less than required, Hud will not run",{memorySize:e}),o.customer_logger.log(o.UserErrorLogs.UnsupportedLambdaMemory()),!1}globalThis.hudRuningInsideLambda=!0}return(0,n.initGlobals)(),o.app_logger.debug("InitGlobals done"),!(globalThis.hudStartFromAutoInit&&!(0,n.validateAndGetUserInput)())&&(o.instrument_logger.isValid()?globalThis.hudRanOnRequire?(o.instrument_logger.warn("Already ran onRequire!"),!1):(globalThis.hudRanOnRequire=!0,o.instrument_logger.info("Using module",{name:o.SDK_MODULE_NAME}),(0,s.onRequire)(),(0,o.detectNextJsApp)(),o.instrument_logger.debug("onRequire done"),globalThis.hudInitGuard=setTimeout(i,o.hudConfig.userConfig.maxTimeUntilInitSessionMs?.value??0),globalThis.hudInitGuard.unref(),!0):((0,n.detachHud)(!1),!1))};const n=r(8269),o=r(2546),s=r(7166);function i(){o.instrument_logger.warn("Init timeout disabling hud!"),o.customer_logger.log(o.UserErrorLogs.InitTimeout(globalThis.hudIsRunningFromSetup)),(0,n.detachHud)(!1)}t.hudRITM=s.onRequireFn},5946:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2546),o=r(6730),s=r(4815),i=r(714);class a extends i.FrameworkPatcher{_patch(e){return(0,s.patchUse)(e.prototype,"router"),(0,o.patchMethods)(e.prototype,"router"),n.instrument_logger.info("Patched router successfully"),e}}t.default=a},6093:e=>{"use strict";e.exports=require("@cspotcode/source-map-support")},6504:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.GraphQLMetric=void 0;const n=r(9873);class o extends n.FlowMetric{constructor(e){super(e)}_createUsableMetric(e){return this}toRaw(){return{flow_id:this.flowId,type:"GraphQLMetric",duration:this.duration}}}t.GraphQLMetric=o},6730:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.getMethods=d,t.patchMethods=function(e,t){d().concat("all").forEach(function(r){const n=e[r];if(!n)return void(l.isVerboseLoggingEnabled&&a.instrument_logger.warn("Method not found",{method:r}));const o="all"===r;e[r]=function(){try{if(arguments.length<2)return n.apply(this,arguments);let e=this[l.uuidSymbol];l.isVerboseLoggingEnabled&&(e||(e=c.randomUUID(),this[l.uuidSymbol]=e,a.instrument_logger.info("Express method setting uuid",{uuid:e,kind:t})),a.instrument_logger.info("Express added new method",{method:r,uuid:e,path:arguments[0]}));const s=Array.prototype.slice.call(arguments);if(s[1][a.hudConfig.express.layerStateSymbol]={flowId:[],kind:t,allMethod:o},Array.isArray(s[0]))for(const e of s[0]){const e=c.randomUUID();s[1][a.hudConfig.express.layerStateSymbol].flowId.push(e)}else s[1][a.hudConfig.express.layerStateSymbol].flowId.push(c.randomUUID());const i=n.apply(this,s);try{delete s[1][a.hudConfig.express.layerStateSymbol]}catch(e){}return i}catch(e){a.instrument_logger.error("Failed to patch method",{kind:t,method:r,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return n.apply(this,arguments)},(0,u.copyPropertiesToTarget)(n,e[r])})};const a=r(2546),c=i(r(6982)),u=r(8949),l=r(7225);function d(){const e=r(8611);return e.METHODS&&e.METHODS.map(function(e){return e.toLowerCase()})||["get","post","put","head","delete","options","trace","copy","lock","mkcol","move","purge","propfind","proppatch","unlock","report","mkactivity","checkout","merge","m-search","notify","subscribe","unsubscribe","patch","search","connect"]}},6858:e=>{"use strict";e.exports=require("commander")},6928:e=>{"use strict";e.exports=require("path")},6982:e=>{"use strict";e.exports=require("crypto")},7127:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2546),o=r(6730),s=r(2977),i=r(4815),a=r(7225),c=r(714);class u extends c.FrameworkPatcher{_patch(e){return(0,s.patchRoute)(e.Route),(0,i.patchUse)(e.application,"application"),(0,o.patchMethods)(e.application,"application"),a.isVerboseLoggingEnabled&&(0,a.logLazyRouter)(e.application),e.Router.use?((0,i.patchUse)(e.Router,"router"),(0,o.patchMethods)(e.Router,"router")):n.instrument_logger.warn("Skipping express.Router patching"),n.instrument_logger.info("Patched express successfully"),e}}t.default=u},7131:e=>{"use strict";e.exports=require("./wrap")},7166:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.parseCliInstrumentationPattern=k,t.supportSourceMapInstall=S,t.patch=x,t.patchCompile=P,t.onRequireFn=F,t.patchRequire=O,t.createCheckers=R,t.updateModuleChecker=A,t.skip=D,t.onRequire=function(){try{(0,l.setInstrumentedFilesCountInterval)(),A();try{P()}catch(e){l.instrument_logger.error("Failed to patch compile",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}try{H()}catch(e){l.instrument_logger.error("Failed to patch function toString",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}try{(0,l.shouldSupportSourceMap)()&&S()}catch(e){l.instrument_logger.error("Failed to install source map support",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}try{O()}catch(e){l.instrument_logger.error("Failed to patch require",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}catch(e){l.instrument_logger.error("Something went wrong in onRequire",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}try{(0,g.saveMachineMetric)()}catch(e){l.instrument_logger.error("Failed to add metric",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}},t.addNoopToFunction=$,t.patchFunctionToString=H;const a=i(r(9896)),c=i(r(6928)),u=r(8528),l=r(2546),d=i(r(2784)),f=r(3901),p=r(8528),g=r(8269),m=r(2546),h=r(9063),y=r(714),_=r(8949),v=function(){const e=m.SDK_MODULE_NAME;try{return c.dirname(c.dirname(m.myRequire.resolve(e)))}catch(t){return l.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 b(e){const t=globalThis.HudSourceMapCache.get(e);return t?{map:JSON.parse(t)}:null}const w=new RegExp(`//"([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})";${m.hudConfig.cliSdkVersionVarName}="([^"]+)";${m.hudConfig.cliBuildIdVarName}`);function k(e){if(e.slice(-m.hudConfig.cliBuildIdVarName.length)!==m.hudConfig.cliBuildIdVarName)return null;const t=Math.min(100,e.length),r=e.slice(-t).match(w);return r?{buildId:r[1],sdkVersion:r[2],fullPattern:r[0]}:null}function S(){r(6093).install({handleUncaughtExceptions:!1,hookRequire:!1,environment:"node",retrieveSourceMap:b})}let E=!1;function x(e,t,r,n){const o={code:e,map:void 0};try{if(globalThis.hudRunningMode===p.HudRunningMode.detached)return o;if(r===u.Format.esm&&!n)throw new m.HudError("MessagePort is required for patching ESM modules");const s=k(e);if(s)return s.sdkVersion!==m.SDK_VERSION?(l.instrument_logger.error("SDK version mismatch detected, disabling SDK",{filename:t,cliSdkVersion:s.sdkVersion,currentSdkVersion:m.SDK_VERSION}),(0,g.detachHud)(!1,!1),o):((0,g.addReingestValue)(s.buildId),globalThis.hudDeclarationsFound=!0,globalThis.hudInstrumentationIndicator&&(clearTimeout(globalThis.hudInstrumentationIndicator),globalThis.hudInstrumentationIndicator=void 0),o);if(m.hudConfig.userConfig.disableRuntimeInstrumentation?.value)return E||(E=!0,l.instrument_logger.info("Skipping instrumentation due to disableRuntimeInstrumentation")),o;if(D(t))return o;if(e.length>(m.hudConfig.userConfig.maxFileSizeBytes?.value??0)&&!e.startsWith(m.hudConfig.esbuildMark))return l.instrument_logger.info("Skipping large file",{filename:t,size:e.length}),o;const i=Date.now(),a=(0,f.edit)(e,t,r,!1),c=a.metadatas;if(o.code=a.transformedCode,o.map=c,l.instrument_logger.debug("Patched",{filename:t,time:Date.now()-i}),(0,l.incrementInstrumentedFilesCount)(),n)for(const e of c)n.postMessage({key:"HudModulePatch",hudPatched:t,hudProcessedFiles:(0,l.sourceFileMetadataToTransferSourceFileMetadata)(e)});else globalThis.hudPatched.add(t),globalThis.hudProcessedFiles.push(...c.map(e=>(0,l.sourceFileMetadataToTransferSourceFileMetadata)(e))),globalThis.hudDeclarationsFound=!0,globalThis.hudInstrumentationIndicator&&(clearTimeout(globalThis.hudInstrumentationIndicator),globalThis.hudInstrumentationIndicator=void 0);m.hudConfig.writePatched&&(N(t,a.transformedCode),a.metadatas&&N(t+".map",JSON.stringify(JSON.parse(a.metadatas[0].map),null,2)))}catch(e){l.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 o}let C="",M=!0,I=!1;function P(){if(!(0,m.isSupportedNative)())return;const e=r(3339),t=(0,l.shouldSupportSourceMap)();I&&l.instrument_logger.warn("PatchCompile ran twice"),0===Object.keys(globalThis.hudLoadedModules).length&&(globalThis.hudLoadedModules=Object.keys(m.myRequire.cache));const n=e.prototype._compile;e.prototype._compile=function(e,r){if(r===C){try{const e=M?l.instrument_logger.warn.bind(l.instrument_logger):l.instrument_logger.debug.bind(l.instrument_logger);M=!1,e("Skipping compile since already ran",{filename:r})}catch{}return n.call(this,e,r)}C=r,l.instrument_logger.verbose("Compiling requirement",{filename:r});const o=x(e,r,u.Format.cjs);try{if(t&&o.map){const e=(0,l.combineSourceMaps)(o.map,r);e&&globalThis.HudSourceMapCache.set(r,e)}}catch(e){l.instrument_logger.error("Failed to combine source maps",{filename:r,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}const s=n.call(this,o.code,r);return C="",s},(0,_.copyPropertiesToTarget)(n,e.prototype._compile),I=!0,l.instrument_logger.debug("Patched _compile")}function F(e,t,r){try{const n=m.hudConfig.frameworksToPatch.get(t);return n?.patcher&&n.version?(0,y.getFrameworkPatcher)(n.patcher).patch(e,r,n.version,n.extraInfo,t):e}catch(e){l.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}function O(){new h.Hook(Array.from(m.hudConfig.frameworksToPatch.keys()),{internals:!0},F)}function N(e,t){const r=c.parse(e);let n=`${r.dir}/patched.${r.base}`;r.dir.includes("dist")&&(n=c.join(`${r.dir.replace("dist","patched")}`,r.base)),a.existsSync(c.dirname(n))||a.mkdirSync(c.dirname(n),{recursive:!0}),a.writeFileSync(n,t,"utf8"),l.instrument_logger.debug("Dumped patched file",{filename:e,patchedPath:n})}function T(e){const t=c.sep.replace(/\\/g,"\\\\"),r=c.join(e).split(".").join("\\.").split("*").join(".*?"),n=t+"node_modules"+t;return{isAllowdModule:new RegExp(n+r+`(?:${t}|$)`),isAllowdModuleSubModule:new RegExp(n+r+n)}}function j(e,t){return!!t.isAllowdModule.test(e)&&!t.isAllowdModuleSubModule.test(e)}function q(e,t){const r=t.replace(/\//g,c.sep);return e.includes(`node_modules${c.sep}${r}${c.sep}`)&&!e.includes(`node_modules${c.sep}${r}${c.sep}node_modules`)}function R(e){const t=[];for(const r of e){let e;if(r.includes("*")){const t=T(r);e=e=>j(e,t)}else e=e=>q(e,r);t.push(e)}return t}let L=[];function A(){L=R(m.hudConfig.userConfig.includeModules?.value??[])}function D(e,t){if(!m.hudConfig.allowedEditExtensions.includes(c.extname(e))&&!e.endsWith(c.sep))return l.instrument_logger.warn("Skipping non-allowed extension",{filename:e}),!0;const r=t??L;return"/var/runtime/index.mjs"===e?(l.instrument_logger.debug("Skipping lambda runtime",{filename:e}),!0):e.includes("node_modules")&&!function(e,t){for(const r of t)if(r(e))return!0;return!1}(e,r)||e.includes(".yarn")?(l.instrument_logger.debug("Skipping non-monitored imported module",{filename:e}),!0):!(v&&!e.includes(v)||(l.instrument_logger.debug("Skipping hud internal module",{filename:e}),0))}let U=!1;function $(e){try{let t=d.markFunctions(`(${e})`,{filename:"file.js",firstFunctionMarkCode:`\n const ${f.destructImportObj} = ${f.defaultImportObj};\n `}).code.trim();return t.endsWith(";")&&(t=t.slice(0,-1)),t.startsWith("(")&&t.endsWith(")")&&(t=t.slice(1,-1)),t}catch(t){return U||(U=!0,l.instrument_logger.error("Failed to add noop to function",{msg:t instanceof Error?t.message:void 0,stack:t instanceof Error?t.stack:void 0})),e}}function H(){const e=Function.prototype.toString;Function.prototype.toString=function(){const t=e.call(this);return t.includes(m.hudConfig.functionInitFunctionName)?$(t):t},(0,_.copyPropertiesToTarget)(e,Function.prototype.toString)}},7214:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(8528),o=r(8269),s=r(2546),i=r(8949),a=r(6504),c=r(714);class u extends c.FrameworkPatcher{static graphQLPatchedSymbol=Symbol.for(s.hudConfig.hudPatchedName);_patch(e){return this.patchGraphql(e),s.instrument_logger.info("Patched GraphQL successfully"),e}patchGraphql(e){const t=e.execute;e.execute=function(e){!function(e){try{e&&!e[u.graphQLPatchedSymbol]&&(l(e._queryType),l(e._mutationType),e[u.graphQLPatchedSymbol]=!0,s.instrument_logger.info("Patched GraphQL schema successfully"))}catch(e){s.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=>(g(t,r),e)):(g(t,r),e)}(t.apply(this,arguments),e.document,r)},(0,i.copyPropertiesToTarget)(t,e.execute)}}function l(e){if(!e)return;const t=e._fields;Object.keys(t).forEach(r=>{const c=t[r];!function(e,t,r){if(e.resolve&&!e.resolve[u.graphQLPatchedSymbol]){const n=(0,s.generateGraphqlFlowId)(r,t);(0,o.storeResolverDeclaration)({id:n,operation:t,name:r});const c=e.resolve;e.resolve=(0,i.wrapFlow)(p,c,!0,(e,t)=>{const r=a.GraphQLMetric.createUsableMetric();r.start(),r.setFlowId(e),t.flowMetric=r},(e,t)=>{const r=t.flowMetric;r?r.end():s.instrument_logger.warn("No flowMetric found for resolver",{flowId:e})},(e,t)=>{const r=t.flowMetric;r?r.end():s.instrument_logger.warn("No flowMetric found for resolver",{flowId:e})}),e.resolve[u.graphQLPatchedSymbol]=!0,(0,o.storeResolverIdBySelectionName)(n,r)}}(c,n.GraphQLSupportedOperations[e.name.toLowerCase()],r),c.type._fields&&f(c.type)})}t.default=u;const d=new WeakSet;function f(e){e&&e._fields&&!d.has(e)&&(d.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[u.graphQLPatchedSymbol]&&(e.resolve=(0,i.wrapFlow)(p,t,!0),e.resolve[u.graphQLPatchedSymbol]=!0)}(r);let n=r.type;for(;n.ofType;)n=n.ofType;f(n)}))}function p(e){if(void 0===e[2]||void 0===e[3])return void s.instrument_logger.warn("GraphQL resolver arguments are unknown");const t=e[3].path;if(t&&!t.prev){const r=t.key,n=(0,o.getResolverIdBySelectionName)(r);return e[2][u.graphQLPatchedSymbol]=n,n}if(e[2][u.graphQLPatchedSymbol])return e[2][u.graphQLPatchedSymbol];s.instrument_logger.warn("GraphQL No functionId found for resolver")}function g(e,t){try{new o.GraphQLDocumentMetadata(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})}}},7225:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.skipStackNamesLogs=t.skipLayerNamesLogs=t.isVerboseLoggingEnabled=t.uuidSymbol=void 0,t.logLazyRouter=function(e){const r=e.lazyrouter;e.lazyrouter=function(){let e=!1;try{this._router||(e=!0)}catch(e){a.instrument_logger.error("Failed to check this._router",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}const n=r.apply(this,arguments);try{if(e){let e=this[t.uuidSymbol];e||(e=c.randomUUID(),this[t.uuidSymbol]=e,a.instrument_logger.info("Express lazy router setting uuid",{uuid:e})),a.instrument_logger.info("Express lazy router",{parent:e,child:this._router?.[t.uuidSymbol]})}}catch(e){a.instrument_logger.error("Failed to patch express.lazyRouter function",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return n},(0,l.copyPropertiesToTarget)(r,e.lazyrouter)};const a=r(2546),c=i(r(6982)),u=r(932),l=r(8949);t.uuidSymbol=Symbol.for("__hud_uuid__"),t.isVerboseLoggingEnabled="true"===u.env.HUD_LOG_EXPRESS,t.skipLayerNamesLogs=new Set(["query","expressInit","mounted_app"]),t.skipStackNamesLogs=new Set(["router"])},7246:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2546),o=r(8949),s=r(714);class i extends s.FrameworkPatcher{static originalRequestSymbol=Symbol.for("hudOriginalRequest");static hudPatched=Symbol.for("hudPatched");_patch(e){try{if((0,n.setIsNextJsApp)(!0),!e.NextRequestAdapter)return n.instrument_logger.error("Could not find NextRequestAdapter in exports"),e;const t=e.NextRequestAdapter;if(t[i.hudPatched])return n.instrument_logger.debug("NextRequestAdapter already patched"),e;const r=t.fromNodeNextRequest;if(!r)return n.instrument_logger.error("Could not find NextRequestAdapter.fromNodeNextRequest"),e;t.fromNodeNextRequest=function(...e){const t=r.apply(this,e);try{t[i.originalRequestSymbol]=e[0]._req}catch(e){n.instrument_logger.error("Failed to patch NextRequestAdapter",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t},(0,o.copyPropertiesToTarget)(r,t.fromNodeNextRequest),t[i.hudPatched]=!0,n.instrument_logger.info("Successfully patched NextRequestAdapter.fromNodeNextRequest")}catch(e){n.instrument_logger.error("Failed to patch NextRequestAdapter",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return e}}t.default=i},7603:(e,t)=>{"use strict";function r(e){try{return e.headers["x-amzn-trace-id"]}catch{return}}function n(e){try{return e.headers.traceparent}catch{return}}function o(e){try{return e.headers["x-datadog-trace-id"]}catch{return}}Object.defineProperty(t,"__esModule",{value:!0}),t.getObservabilityIdentifiers=function(e){return{datadog_trace_id:o(e),otel_trace_id:n(e),amazon_trace_id:r(e)}}},7707:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AsyncFunction=void 0,t.AsyncFunction=(async()=>{}).constructor},7808:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getMachineMetrics=function(){try{const e=(0,o.getLastMetrics)();return{cpu_usage:e.cpuUsage?l(e.cpuUsage,e.timestamp):void 0,memory_usage:u(),event_loop_utilization:e.elu?c(e.elu):void 0}}catch(e){return void s.app_logger.error("Error getting machine metrics",e)}},t.getCpuUsage=l;const o=r(8269),s=r(2546),i=n(r(857)),a=r(2987);function c(e){try{return a.performance.eventLoopUtilization(e).utilization}catch(e){return void s.app_logger.error("Error getting event loop utilization",e)}}function u(){try{const e=process.memoryUsage(),t=i.default.totalmem();return{rss:e.rss,heap_total:e.heapTotal,heap_used:e.heapUsed,external:e.external,system_memory:t,rss_percentage:e.rss/t*100}}catch(e){return void s.app_logger.error("Error getting memory usage",e)}}function l(e,t){try{const r=process.cpuUsage(),n=1e3*(Date.now()-t),o=(0,s.getCpuLimit)(s.app_logger),i=(r.user-e.user)/n,a=(r.system-e.system)/n;return{user_time:i,system_time:a,limit:o,user_percent_of_limit:"number"==typeof o?i/o*100:void 0,system_percent_of_limit:"number"==typeof o?a/o*100:void 0}}catch(e){return void s.app_logger.error("Error getting cpu usage",e)}}},8054:e=>{"use strict";e.exports=require("array-flatten")},8064:e=>{"use strict";e.exports=require("semver")},8184:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=r(8528),s=r(2030),i=r(2546),a=n(r(8938)),c=r(6858),u=r(9896),l=r(1943),d=n(r(2698)),f=n(r(6928)),p=r(9561),g=r(3903),m=n(r(3106)),h=r(1952);function y(e){const t=(0,i.formatLogMessage)(e.message,e.errCode,e.moreInfo);console.log(t)}const _=new class{messages=[];buildId=null;accessToken=null;client=null;setBuildId(e){this.buildId=e}setAccessToken(e){this.accessToken=e}setClient(e){this.client=e}log(e){"true"===process.env.HUD_VERBOSE&&console.log("Hud CLI: "+e),this.messages.push({message:e,timestamp:(new Date).toISOString()})}async send(){try{if(!this.buildId)return void this.log("Build ID is not set");if(!this.accessToken)return void this.log("Access token is not set");if(!this.client)return void this.log("Client is not set");const e=this.messages.map(e=>({...e,buildId:this.buildId||""}));await this.client.sessionslessLogs(JSON.stringify(e),this.accessToken||"")}catch(e){}}};async function v(e,t,r){try{return await(0,l.writeFile)(e,t,r),!0}catch(e){return!1}}async function b(e,t){try{return await(0,l.rename)(e,t),!0}catch(e){return!1}}async function w(e){try{await(0,l.unlink)(e)}catch(e){}}async function k(e){const t=(0,d.default)(20);await Promise.all(e.map(e=>t(async()=>{await Promise.all([w(e.filePath+".hud"),w(e.filePath+".hud.map")])})))}async function S(e,t,r,n){const s=(await t.getUploadUrls(r,n,1))[0];_.log("Got upload URL");const c={...i.HudClient.defaultRequest,send_time:(new Date).toISOString(),build_id:r,token:n};let u=[];const l=e.map(e=>e.metadatas[0]);try{u=await(0,i.getFilesForDeclarations)(l,t.sendFileDeclarationsCi.bind(t,c))}catch(e){u=l}_.log(`Got ${u.length} files for declarations`);const f=await async function(e){const t=(0,d.default)(process.env.HUD_PARSE_DECLARATIONS_LIMIT?parseInt(process.env.HUD_PARSE_DECLARATIONS_LIMIT):20),r=m.default.createGzip();let n=0;return await Promise.all(e.map(e=>t(async()=>{try{const t=await(0,i.readFile)(e.filename,e.indexOffset,e.indexOffsetEnd);if(!t)return n++,{declarations:[],blacklist:void 0};(function(e){const t=(new Date).toISOString(),r=function(e){const t=[];for(let r=0;r<e.length;r+=100){const n=e.slice(r,r+100);t.push(n)}return t}(e);return r.map(e=>({...i.HudClient.defaultRequest,type:"FunctionDeclaration",arr:e,send_time:t,event_version:o.FUNCTION_DECLARATION_VERSION}))})((await(0,i.parseDeclarations)(e,t)).declarations).forEach(e=>{r.write(JSON.stringify(e)),r.write("\n")})}catch(e){return n++,{declarations:[],blacklist:void 0}}}))),r.end(),n>0&&_.log(`Failed to parse declarations for ${n} files`),r}(u);try{await async function(e,t,r,n,o){const s=await(0,p.buffer)(e);let i=t;for(let e=1;e<=3;e++)try{return await a.default.put(i,s,{headers:{"Content-Encoding":"gzip","Content-Type":"application/x-ndjson"}}),void _.log("Uploaded requests")}catch(t){if(!(a.default.isAxiosError(t)&&405===t.response?.status&&e<3))throw t;_.log(`Upload failed with 405 status, retrying attempt ${e+1}/3, current upload url: ${i}`),i=(await r.getUploadUrls(n,o,1))[0]}}(f,s,t,r,n),_.log("Upload completed")}catch(e){const t={msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0};_.log(`Failed to upload requests, still instrumenting files, error: ${JSON.stringify(t)}`),y(i.UserErrorLogs.HudCliUploadFailed())}}function E(e){const t=f.default.resolve(e);if(!(0,u.existsSync)(t))throw new Error(`Directory does not exist: ${e}`);return t}(async function(){const e=new c.Command;e.requiredOption("--api-key <string>","Your Hud API key").requiredOption("--dirs <list>","Comma-separated directories to scan").option("--include-modules <list>","Comma-separated module names to trace").option("--node-modules-path <string>","Path to node_modules").option("--max-mapped-functions <number>","Max number of mapped functions").option("--exclude-dirs <list>","Comma-separated directories to exclude").parse(process.argv);const t=e.opts(),r={apiKey:t.apiKey,modulesToTrace:t.includeModules?t.includeModules.split(",").map(e=>e.trim()):[],dirs:t.dirs.split(",").map(e=>e.trim()),nodeModulesPath:t.nodeModulesPath,maxMappedFunctions:t.maxMappedFunctions,excludeDirs:t.excludeDirs?t.excludeDirs.split(",").map(e=>e.trim()):void 0},n=(0,g.v4)();_.setBuildId(n),_.setAccessToken(t.apiKey);const a=new i.HudClient;if(_.setClient(a),!await a.validateToken(t.apiKey))return y(i.UserErrorLogs.HudCliInvalidKey()),void await _.send();let l,p;r.maxMappedFunctions&&(i.hudConfig.userConfig.maxMappedFunctions={value:r.maxMappedFunctions,source:"SETUP"});try{({dirs:l,nodeModulesPath:p}=function(e){const t=[];let r;for(const r of e.dirs)try{t.push(E(r))}catch(e){throw y(i.UserErrorLogs.HudCliInvalidDirectory(r)),e}if(e.nodeModulesPath)try{r=E(e.nodeModulesPath)}catch(t){throw y(i.UserErrorLogs.HudCliInvalidDirectory(e.nodeModulesPath)),t}return{dirs:t,nodeModulesPath:r}}(r))}catch(e){return void await _.send()}const m=(0,s.createCheckers)(r.modulesToTrace),x=await(0,h.getFiles)(l,m,p,r.excludeDirs);if(0===x.length)return _.log("No .js files to instrument"),y(i.UserErrorLogs.HudCliNoJsFiles()),void await _.send();_.log(`Found ${x.length} files`);const C=await async function(e,t){const r=(0,d.default)(20);return await Promise.all(e.map(e=>r(async()=>async function(e,t){try{if(globalThis.hudRunningMode===o.HudRunningMode.detached)return{status:"skipped"};const r=f.default.join(e.parentPath,e.name),n=(0,u.readFileSync)(r,"utf-8");if((0,s.parseCliInstrumentationPattern)(n))return{status:"skipped"};const{transformedCode:a,metadatas:c}=(0,s.editWithCliBuildId)(n,r,o.Format.cjs,t);return c[0].detectedForAwaitLoops>0&&_.log(`Detected for-await loops in file ${r}, detectedForAwaitLoops: ${c[0].detectedForAwaitLoops}`),await async function(e,t,r){const n=(0,i.combineSourceMaps)(t,r);return!(!n||!await v(r+".hud",e)||!await v(r+".hud.map",n,"utf-8")&&(await w(r+".hud"),1))}(a,c,r)?{status:"success",metadatas:c.map(e=>(0,i.sourceFileMetadataToTransferSourceFileMetadata)(e)),filePath:r}:{status:"failed"}}catch(e){return{status:"failed"}}}(e,t))))}(x,n);if(globalThis.hudRunningMode===o.HudRunningMode.detached)return _.log("Detached mode, skipping filterEditedFiles"),y(i.UserErrorLogs.HudCliInstrumentedFunctionCountExceeded(i.hudConfig.userConfig.maxMappedFunctions?.value??0)),await k(C.filter(e=>"success"===e.status).map(e=>({filePath:e.filePath}))),void await _.send();const M=await async function(e){const t=e.filter(e=>void 0===e||"failed"===e.status);t.length>0&&_.log(`Failed to edit ${t.length} files out of ${e.length}`);const r=e.filter(e=>"skipped"===e.status);if(r.length>0){if(r.length===e.length)return y(i.UserErrorLogs.HudCliAllFilesInstrumented()),_.log("No files instrumented."),void await _.send();y(i.UserErrorLogs.HudCliSomeFilesInstrumented()),_.log(`Skipped ${r.length} files out of ${e.length}`)}const n=e.filter(e=>"success"===e.status);return n.length>0&&_.log(`Edited ${n.length} files`),n}(C);if(M&&0!==M.length)try{_.log(`Parsing declarations for ${M.length} files`),await S(M,a,n,r.apiKey),await async function(e){const t=(0,d.default)(20);await Promise.all(e.map(e=>t(async()=>{await b(e.filePath+".hud",e.filePath)?await b(e.filePath+".hud.map",e.filePath+".map"):(await w(e.filePath+".hud"),await w(e.filePath+".hud.map"))})))}(M),_.log("Files written to disk"),await _.send(),_.log("Done."),y(i.UserLogs.HudCliCompletedSuccessfully(M.length))}catch(e){throw _.log(`Failed to instrument files, deleting files ${e}`),e instanceof Error&&_.log(e.stack||e.message),await k(M),await _.send(),e}})().catch(async e=>{try{y(i.UserErrorLogs.HudCliUnkownError()),_.log("Failure"),e instanceof Error&&_.log(e.stack||e.message),await _.send()}catch(e){}})},8269:e=>{"use strict";e.exports=require("./globalstate")},8528:e=>{"use strict";e.exports=require("./dto")},8611:e=>{"use strict";e.exports=require("http")},8901:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HttpEndpointMetric=void 0;const n=r(9873);class o extends n.FlowMetric{statusCode;route;method;constructor(e){super(e)}_createUsableMetric(e){return this}setRequestAttributes(e){const t=e.url||e.path;this.route=t?.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=o},8938:e=>{"use strict";e.exports=require("axios")},8949:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.wrapFlow=function(e,t,r=!0,c,u,l){let d;return t[i]?t:(t[i]=!0,d=t instanceof s.AsyncFunction?async function(...s){let i;try{i=e(s)}catch(e){o.instrument_logger.error("Failed to get flowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}if(!i||hudRunningMode!==n.HudRunningMode.enabled)return await t.apply(this,s);hudFlowId=i,hudShouldLinkFunction=r;const a={};if(c)try{c(i,a,s)}catch(e){o.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,s);hudFlowId="";const r=await e;if(u)try{u(i,a)}catch(e){o.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(l)try{l(i,a,e)}catch(e){o.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{hudFlowId="",hudShouldLinkFunction=!1}}:function(...s){let i;try{i=e(s)}catch(e){o.instrument_logger.error("Failed to get flowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}if(!i||hudRunningMode!==n.HudRunningMode.enabled)return t.apply(this,s);hudFlowId=i,hudShouldLinkFunction=r;const a={};if(c)try{c(i,a,s)}catch(e){o.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,s);if(u)if(e instanceof Promise)e.then(()=>{try{u(i,a)}catch(e){o.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{u(i,a)}catch(e){o.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(l)try{l(i,a,e)}catch(e){o.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{hudFlowId="",hudShouldLinkFunction=!1}},a(t,d),d)},t.copyPropertiesToTarget=a;const n=r(8528),o=r(2546),s=r(7707),i=Symbol.for("hudMarked");function a(e,t){const r=Object.getOwnPropertyDescriptors(e),n=Reflect.ownKeys(r);Object.setPrototypeOf(t,e),n.forEach(e=>{try{Object.defineProperty(t,e,r[e])}catch(e){}})}},9063:e=>{"use strict";e.exports=require("require-in-the-middle")},9561:e=>{"use strict";e.exports=require("stream/consumers")},9589:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=r(8528),s=r(8269),i=r(2546),a=r(8949),c=r(714),u=r(5459),l=n(r(7246));class d extends c.FrameworkPatcher{static nextJSHudMarked=Symbol.for("hudNextJSMarked");static routeInfoSymbol=Symbol.for("hudNextJSRouteInfo");static standardMethods=["GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"];_patch(e){return(0,i.setIsNextJsApp)(!0),this._patchBaseServer(e),i.instrument_logger.info("Patched Next.js successfully"),e}_patchBaseServer(e){try{const t=e.default;if(t[d.nextJSHudMarked])return e;const r=t.prototype.renderToResponseWithComponentsImpl;if(!r)return i.instrument_logger.error("Could not find renderToResponseWithComponentsImpl on BaseServer.prototype"),e;t.prototype.renderToResponseWithComponentsImpl=async function(e,t,...n){try{const r=t.components;if(r&&r.routeModule&&!r.routeModule[d.nextJSHudMarked]){const t=r.routeModule,n=t.definition?.pathname||e.pathname;d._detectAndPatchSupportedMethods(t,n),t[d.nextJSHudMarked]=!0}}catch(e){i.instrument_logger.error("Failed to patch Next.js route module",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return await r.apply(this,[e,t,...n])},t[d.nextJSHudMarked]=!0,(0,a.copyPropertiesToTarget)(r,t.prototype.renderToResponseWithComponentsImpl)}catch(e){i.instrument_logger.error("Failed to patch Next.js base server",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return e}static _detectAndPatchSupportedMethods(e,t){try{switch(i.instrument_logger.debug("Patching Next.js route module",{pathname:t,kind:e.definition?.kind||"unknown"}),e.definition.kind){case"APP_ROUTE":case"PAGES_API":d._patchApiModule(e,t);break;case"PAGES":case"APP_PAGE":d._patchPageModule(e,t);break;default:i.instrument_logger.warn("Unknown Next.js route module kind",{pathname:t,kind:e.definition?.kind||"unknown"})}}catch(e){i.instrument_logger.error("Error detecting and patching supported methods",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}static _patchApiModule(e,t){if(e.methods)for(const r of d.standardMethods)if("function"==typeof e.methods[r]&&"function"==typeof e.userland?.[r]){const n=(0,i.generateEndpointFlowId)(t,[r]);(0,s.storeEndpointDeclaration)(new o.EndpointDeclaration(n,[r],"nextjs","",t));try{const t=e.methods[r];e.methods[r]=(0,a.wrapFlow)(()=>n,t,!0,(e,t,r)=>{g(r[0],e)})}catch(e){i.instrument_logger.error("Failed to patch Next.js App Route method",{method:r,pathname:t,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}if(e.userland?.default){const r=d.standardMethods.filter(t=>!e.methods?.[t]),n=(0,i.generateEndpointFlowId)(t,r);(0,s.storeEndpointDeclaration)(new o.EndpointDeclaration(n,r,"nextjs","",t));const c=e.userland.default;e.userland={...e.userland,default:(0,a.wrapFlow)(()=>n,c,!0)}}}static _patchPageModule(e,t){const r=(0,i.generateEndpointFlowId)(t,["GET"]);if((0,s.storeEndpointDeclaration)(new o.EndpointDeclaration(r,["GET"],"nextjs","",t)),e.render&&"function"==typeof e.render&&!e.render[this.nextJSHudMarked])try{const t=e.render;e.render=function(...e){try{g(e[0],r)}catch(e){}return t.apply(this,e)},(0,a.copyPropertiesToTarget)(t,e.render),e.render[this.nextJSHudMarked]=!0}catch(e){i.instrument_logger.error("Failed to patch Next.js Page render method",{pathname:t,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}if(e.userland?.loaderTree)try{p(e.userland.loaderTree,r)}catch(e){i.instrument_logger.error("Failed to patch App Router page component",{pathname:t,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}else i.instrument_logger.warn("No loader tree found on Next.js page component",{pathname:t})}}function f(e,t,r){return(...n)=>{const o=e(...n),s=e=>{if(e&&"function"==typeof e.default&&!e.default[d.nextJSHudMarked]){const n=(0,a.wrapFlow)(()=>r,e.default,t);(e={...e,default:n})[d.nextJSHudMarked]=!0}return e};return o&&"function"==typeof o.then?o.then(s):s(o)}}function p(e,t){const[,r,n]=e;for(const e of Object.keys(n))try{const r=n[e];if(Array.isArray(r)&&"function"==typeof r[0]){const n="page"===e,o=r[0];r[0]=f(o,n,t),(0,a.copyPropertiesToTarget)(o,r[0])}}catch(e){i.instrument_logger.error("Failed to iterate on Next.js components",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}for(const e of Object.values(r))try{p(e,t)}catch(e){i.instrument_logger.error("Failed to walk on Next.js parallel routes",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}function g(e,t){try{let r;if(e&&l.default.originalRequestSymbol in e){const t=e[l.default.originalRequestSymbol];r=(0,u.getHttpMetricFromRequest)(t)}else e&&e.originalRequest&&(r=(0,u.getHttpMetricFromRequest)(e.originalRequest));if(r||(r=(0,u.getHttpMetricFromRequest)(e)),!r)return void i.instrument_logger.error("No endpoint metric found on Next.js request or its original request");r.setFlowId(t)}catch(e){i.instrument_logger.error("Failed to link metric to flow",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}t.default=d},9723:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0});const a=r(8269),c=r(2546),u=r(9896),l=i(r(6928)),d=r(8949),f=r(714);class p extends f.FrameworkPatcher{_patch(e){(0,c.setIsNextJsApp)(!0);const t=this._patchLoadConfig(e);return c.instrument_logger.info("Patched next.js config successfully"),t}_patchLoadConfig(e){const t=e.default,r=async function(...e){const r=await t.call(this,...e);if(!r)return r;try{const t=e[1],n=l.join(t,r.distDir||".next"),o=l.join(n,a.apiManifest),s=l.join(n,a.pageManifest),i=await u.promises.access(o).then(()=>!0).catch(()=>!1),d=await u.promises.access(s).then(()=>!0).catch(()=>!1);(0,a.isNextConfigExtracted)()||!i&&!d||(c.instrument_logger.info("Extracted next.js config successfully"),(0,a.setNextConfig)(r))}catch(e){c.instrument_logger.error("Failed to patch next.js loadConfig",{msg:e instanceof Error?e.message:String(e),stack:e instanceof Error?e.stack:void 0})}return r};(0,d.copyPropertiesToTarget)(t,r);const n=Object.create(Object.getPrototypeOf(e));return Object.defineProperty(n,"default",{enumerable:!0,get:function(){return r}}),(0,d.copyPropertiesToTarget)(e,n),n}}t.default=p},9873:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.FlowMetric=void 0;const o=r(8528),s=r(8269),i=n(r(932));t.FlowMetric=class{_state;flowId;duration;_startTime;_msStartTime;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}getMsStartTime(){return this._msStartTime}start(){this._startTime=i.default.hrtime.bigint(),this._msStartTime=Date.now()}end(){this._startTime&&(this.duration=Number(i.default.hrtime.bigint()-this._startTime)),this.#e(),this._state="unusable"}#e(){if(hudRunningMode===o.HudRunningMode.enabled){const e=this.toRaw();e&&(0,s.storeFlowMetric)(e)}}}},9896:e=>{"use strict";e.exports=require("fs")}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,r),s.exports}return r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r(8184)})());
2
+ !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 n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(global,()=>(()=>{var e={336:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2546),o=r(2822),s=r(8949),i=r(8901),a=r(714);class c extends a.FrameworkPatcher{_patch(e){return this._patchSendRequest(e),n.instrument_logger.info("Patched @codegenie/serverless-express/src/frameworks/express.js successfully"),e}_patchSendRequest(e){const t=e.sendRequest;e.sendRequest=function(e){let r,s;const a=i.HttpEndpointMetric.createUsableMetric();try{if(r=e.request,s=e.response,!r||!s)return t.call(this,e);a.start(),a.setRequestAttributes(r),r[n.hudConfig.metricSymbol]=a}catch(e){n.instrument_logger.error("Failed to start flowMetric during sendRequest patching",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}const c=(0,o.runWithInvestigation)(()=>t.call(this,e));try{s.once("finish",function(){try{(0,o.finishHttpInvestigation)(r,s,a),a.setResponseAttributes(s),a.end()}catch(e){n.instrument_logger.error("Failed to end flowMetric during sendRequest patching",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}})}catch(e){n.instrument_logger.error("Failed to end flowMetric during sendRequest patching",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return c},(0,s.copyPropertiesToTarget)(t,e.sendRequest)}}t.default=c},486:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(8269),o=r(2546),s=r(8949),i=r(828),a=r(714);class c extends a.FrameworkPatcher{_patch(e){return this._patchConsumer(e),o.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,n=[],a=[];!function(e,t){const r=e.subscribe;e.subscribe=async function(...e){const n=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):o.instrument_logger.warn("No topic found in KafkaJS.Consumer.subscribe",{args:e[0]})}catch(e){o.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 n},(0,s.copyPropertiesToTarget)(r,e.subscribe)}(r,a),function(e,t,r,n,a){const c=e.run;function p(e,c){const p="eachBatch"===c;for(const e of a)f(e,n,t,r,c);const g=function(e,t,r){return n=>{const s=n[0],i=r?s.batch.topic:s.topic;return function(e,t,r,n){const s=e.get(l(r,n));if(s)return s;for(const e of t)if(e.isBatch===n&&e.pattern.test(r))return e.flowId;o.instrument_logger.warn("No flowId found for topic",{topicName:r,isBatch:n})}(e,t,i,r)}}(t,r,p),h=function(e){return(t,r,n)=>{const s=i.KafkaJSMetric.createUsableMetric();s.start(),s.setFlowId(t);const a=n[0];void 0!==a&&void 0!==a.message&&(a.message[o.hudConfig.metricSymbol]=s);const c=e?a.batch.partition:a.partition,u=e?a.batch.messages[0]?.timestamp:a.message?.timestamp;s.addPartition(c),s.addProducedTimestamp(u),r.flowMetric=s}}(p),m=(0,s.wrapFlow)(g,e[c],!0,h,u,d);e[c]=m}e.run=async function(...e){try{const t=e[0];t.eachMessage&&p(t,"eachMessage"),t.eachBatch&&p(t,"eachBatch")}catch(e){o.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 c.apply(this,e)},(0,s.copyPropertiesToTarget)(c,e.run)}(r,t,n,e[0].groupId,a)}catch(e){o.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,s.copyPropertiesToTarget)(t,e.Kafka.prototype.consumer)}}function u(e,t){const r=t.flowMetric;r?r.end():o.instrument_logger.warn("No flowMetric found for message",{flowId:e})}function d(e,t,r){const n=t.flowMetric;n?(n.setError(r),n.end()):o.instrument_logger.warn("No flowMetric found for message",{flowId:e})}function l(e,t){return e+"|"+t}function f(e,t,r,s,i){const a=(0,o.generateKafkaFlowId)(e,t,i),c={flow_id:a,topic_name:e.toString(),group_id:t,pulling_type:i};(0,n.storeKafkaJSTopicDeclaration)(c),function(e,t,r,n,o){"string"==typeof r?e.set(l(r,n),o):t.push({pattern:r,isBatch:n,flowId:o})}(r,s,e,"eachBatch"===i,a)}t.default=c},646:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2546),o=r(8949),s=r(714),i=r(3531);class a extends s.FrameworkPatcher{_patch(e){return this._patchCreate(e),n.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 s=(0,i.generateKey)(t,r);s&&(e[1]=(0,o.wrapFlow)(()=>{try{const e=(0,i.getRequestByCallback)(s);if(!e)return void n.instrument_logger.error("No request object found for key",{key:s});const t=function(e){if(e&&!e.raw&&e.socket)return e[n.hudConfig.metricSymbol]?e[n.hudConfig.metricSymbol].getFlowId?e[n.hudConfig.metricSymbol].getFlowId():void n.instrument_logger.error("No getFlowId function found on metric object"):void n.instrument_logger.error("No metric found on nestjs request object")}(e);return t||n.instrument_logger.error("No flow id found for key",{key:s}),t}catch(e){n.instrument_logger.error("Error in NestJS getFlowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}},r,!0))}else n.instrument_logger.error("Invalid args in NestJS RouterExecutionContext.create",{args:e})}catch(e){n.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,o.copyPropertiesToTarget)(t,e.RouterExecutionContext.prototype.create)}}t.default=a},714:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.FrameworkPatcher=void 0,t.isSupportedVersion=l,t.extractModuleVersion=f,t.getFrameworkPatcher=function(e){return new(r(2828)(`./${e}`).default)};const a=r(2546),c=r(9896),u=i(r(6928)),d=r(8064);function l(e,t){return""===e||d.satisfies(d.coerce(e),t)}function f(e){try{const t=(0,c.readFileSync)(u.join(e,"package.json"),{encoding:"utf8"}),r=JSON.parse(t).version;return"string"==typeof r?r:""}catch(t){a.instrument_logger.info("Failed extracting version",{baseDir:e})}return""}t.FrameworkPatcher=class{patch(e,t,r,n,o=this.constructor.name){try{if(this.isSupported(t,o,r,n))return this._patch(e)}catch(e){a.instrument_logger.error("Unhandeled error during patching framework",{framework:o,error:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return e}isSupported(e,t,r,n){const o=f(e);return!!l(o,r)||(a.instrument_logger.warn("Unsupported version",{framework:t,version:o,supportedVersion:r,basedir:e}),a.customer_logger.log(a.UserErrorLogs.UnsupportedFrameworkVersion(t)),!1)}}},828:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.KafkaJSMetric=void 0;const n=r(2546),o=r(7131),s=r(9873);class i extends s.FlowMetric{partition;error;producedTimestamp;totalConsumeDuration;constructor(e){super(e)}_createUsableMetric(e){return this}end(){this.producedTimestamp&&(this.totalConsumeDuration=Number(Date.now()-this.producedTimestamp)*Number(1e6)),super.end()}addProducedTimestamp(e){void 0!==e&&(this.producedTimestamp=Number(e))}addPartition(e){this.partition=e}setError(e){this.error=(0,o.extractName)(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},857:e=>{"use strict";e.exports=require("os")},932:e=>{"use strict";e.exports=require("process")},1321:e=>{"use strict";e.exports=require("reflect-metadata")},1326:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=r(2546),s=r(8949),i=r(714),a=n(r(9589));class c extends i.FrameworkPatcher{static nextJSHudMarked=Symbol.for("hudNextJSMarked");_patch(e){return(0,o.setIsNextJsApp)(!0),this._pathLoad(e),o.instrument_logger.info("Patched Next.js successfully"),e}_pathLoad(e){try{const t=e.RouteModuleLoader;if(t[c.nextJSHudMarked])return e;const r=t.load;t.load=async function(...e){const t=await r.apply(this,e);try{if(t){const e=t.definition?.pathname;e&&!t[c.nextJSHudMarked]&&(a.default._detectAndPatchSupportedMethods(t,e),t[c.nextJSHudMarked]=!0)}}catch(e){o.instrument_logger.error("Failed to patch Next.js route module",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t},t[c.nextJSHudMarked]=!0,(0,s.copyPropertiesToTarget)(r,t.load)}catch(e){o.instrument_logger.error("Failed to patch Next.js base server",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return e}}t.default=c},1427:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getSystemInfo=function(){return{pod_name:u(),node_name:d()}};const o=n(r(9896)),s=n(r(857)),i=Symbol("not found");let a,c;function u(){if(a!==i){if(a)return a;try{return a=s.default.hostname(),a}catch(e){return void(a=i)}}}function d(){if(c!==i){if(c)return c;try{const e=o.default.readFileSync("/etc/machine-id","utf8").trim();return c=e,c}catch(e){return void(c=i)}}}},1502:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(8528),o=r(8269),s=r(2546),i=r(8949),a=r(714);class c extends a.FrameworkPatcher{static koaModuleName="koa";static koaPatchedSymbol=Symbol.for(s.hudConfig.hudPatchedName);_patch(e){return this._patchAppUse(e),s.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++)c._wrapRoute(e[t])}catch(e){s.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,i.copyPropertiesToTarget)(t,e.prototype.use)}static _wrapRoute(e){if(e.methods&&0===e.methods.length)return;if(!e.stack[0][c.koaPatchedSymbol]){const t=(0,i.wrapFlow)(p,e.stack[0],!0,u);e.stack[0]=t,e.stack[0][c.koaPatchedSymbol]=!0}const t=(0,s.generateEndpointFlowId)(e.path,e.methods);(0,o.storeEndpointDeclaration)(new n.EndpointDeclaration(t,e.methods,"koa",void 0,e.path));for(const r of e.methods)f(t,e.path,r)}}function u(e,t,r){if(!r[0])return void s.instrument_logger.error("No ctx object found in koa");const n=r[0].req;if(!n)return void s.instrument_logger.error("No req found in koa ctx");const o=n[s.hudConfig.metricSymbol];o?o.setFlowId(e):s.instrument_logger.error("No endpoint metric found in koa req")}function d(e,t){return e+"|"+t}t.default=c;const l=new Map;function f(e,t,r){l.set(d(t,r),e)}function p(e){if(0===e.length)return;const t=e[0]._matchedRoute,r=e[0].req?.method;return function(e,t){return l.get(d(e,t))}(t,r)}},1943:e=>{"use strict";e.exports=require("fs/promises")},1952:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.createDirectoryExcludeCheckers=c,t.shouldExcludeDirectory=u,t.getAllFilesInDirectory=l,t.getNodeModulesFiles=f,t.getFiles=async function(e,t,r,n){const o=[],s=c(n||[]);for(const t of e){const e=await l(t,s);o.push(...e)}if(r){const e=await f(r,t);o.push(...e)}return o};const o=r(1943),s=n(r(6928)),i=r(2197);function a(e){return e.endsWith(".js")}function c(e){const t=[];for(const r of e){let e;if(r.includes("*")){const t=r.split("*").join(".*?"),n=new RegExp(`^${t}$`);e=e=>n.test(e)}else e=e=>e===r;t.push(e)}return t}function u(e,t){for(const r of t)if(r(e))return!0;return!1}async function d(e,t,r){const n=[];let i;try{i=await(0,o.readdir)(e,{withFileTypes:!0})}catch{return n}for(const o of i){const i=s.default.join(e,o.name);if(o.isFile())a(i)&&!t(i)&&n.push(o);else if(o.isDirectory()&&!r(i)){const e=await d(i,t,r);n.push(...e)}}return n}async function l(e,t){const r=t||[];return d(e,()=>!1,e=>{const t=s.default.basename(e);return"node_modules"===t||u(t,r)})}async function f(e,t){return d(e.endsWith(s.default.sep)?e:e+s.default.sep,e=>(0,i.skip)(e,t),()=>!1)}},2030:e=>{"use strict";e.exports=require("./instrument")},2080:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.SqsMetric=void 0;const n=r(9873);class o extends n.FlowMetric{errors;msgCount;e2eEpocStartTimeMS;e2eDurationNS;_finishedMessageCount;constructor(e){super(e),this._finishedMessageCount=0,this.errors=new Map}addError(e,t=1){this.errors.set(e,(this.errors.get(e)??0)+t)}increaseAndShouldEnd(e=1){return this._finishedMessageCount+=e,!(this.msgCount&&this._finishedMessageCount<this.msgCount)}end(){this.e2eEpocStartTimeMS&&(this.e2eDurationNS=Number(Date.now()-this.e2eEpocStartTimeMS)*Number(1e6)),super.end()}_createUsableMetric(e){return this}toRaw(){return{flow_id:this.flowId,type:"SqsMetric",duration:this.duration,e2e_duration:this.e2eDurationNS,msg_count:this.msgCount,errors:this.errors}}}t.SqsMetric=o},2197:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||o(t,e,r)},a=this&&this.__importStar||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.koa=t.express=t.safeLog=t.registerHook=t.hudRITM=void 0;var c=r(5688);Object.defineProperty(t,"hudRITM",{enumerable:!0,get:function(){return c.hudRITM}}),Object.defineProperty(t,"registerHook",{enumerable:!0,get:function(){return c.registerHook}}),Object.defineProperty(t,"safeLog",{enumerable:!0,get:function(){return c.safeLog}}),i(r(3901),t),t.express=a(r(7127)),i(r(714),t),t.koa=a(r(1502)),i(r(7166),t)},2546:e=>{"use strict";e.exports=require("./lib")},2698:e=>{"use strict";e.exports=require("p-limit")},2729:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2546),o=r(2822),s=r(8949),i=r(8901),a=r(714);class c extends a.FrameworkPatcher{_patch(e){const t=this._patchGetFramework(e);return n.instrument_logger.info("Patched serverless-http/lib/framework/get-framework.js successfully"),t}_patchGetFramework(e){const t=e;return e=function(...e){const r=t.apply(t.this,e);async function a(e,...t){const s=i.HttpEndpointMetric.createUsableMetric();try{s.start(),s.setRequestAttributes(e),e[n.hudConfig.metricSymbol]=s}catch(e){n.instrument_logger.error("Failed to start flowMetric during framework serverless request handler patching",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}const a=await(0,o.runWithInvestigation)(()=>r.apply(r.this,[e,...t]));return a.once("finish",function(){try{(0,o.finishHttpInvestigation)(e,a,s),s.setResponseAttributes(a),s.end()}catch(e){n.instrument_logger.error("Failed to end flowMetric during framework serverless request handler patching",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}),a}return(0,s.copyPropertiesToTarget)(r,a),a},(0,s.copyPropertiesToTarget)(t,e),e}}t.default=c},2741:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2546),o=r(6730),s=r(4815),i=r(7225),a=r(714);class c extends a.FrameworkPatcher{_patch(e){return i.isVerboseLoggingEnabled?((0,o.patchMethods)(e,"application_export"),(0,s.patchUse)(e,"application",!1),(0,i.logLazyRouter)(e),n.instrument_logger.info("Patched express.Application successfully"),e):(n.instrument_logger.info("Skipping express.Application patching, verbose logging is not enabled"),e)}}t.default=c},2784:e=>{"use strict";e.exports=require("../native/_index")},2822:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getStackTrace=d,t.serializableInvestigation=p,t.getBaseInvestigationStorage=g,t.createNewInvestigation=function(){if(!globalThis.hudEnableInvestigation)return;const e=(0,i.getStorage)();void 0!==e&&e.enterWith(g())},t.runWithInvestigation=function(e){if(!globalThis.hudEnableInvestigation)return e();const t=(0,i.getStorage)();return void 0===t?e():t.run(g(),e)},t.closeInvestigation=h,t.storeInvestigation=m,t.getStacktraceUniqString=v,t.finishHttpInvestigation=function(e,t,r){if(t.statusCode<500)return;try{f("http requests headers",{headers:Object.keys(e.headers)})}catch{f("failed to log http requests headers")}const n=w(r);if(void 0===n)return void f("finishHttpInvestigation: base investigation return undefined");const o=r.getFlowId(),s=r.getMsStartTime();void 0!==o&&void 0!==r.route&&void 0!==r.method&&void 0!==s?m(n,{type:"http",endpoint_uuid:o,route:r.route,method:r.method,timestamp:s,params:e.params,query:e.query,request_body:b(e.body),status_code:t.statusCode,machine_metrics:(0,a.getMachineMetrics)(),observability_identifiers:(0,c.getObservabilityIdentifiers)(e),extra_headers:(0,c.getExtraHeaders)(e),system_info:(0,u.getSystemInfo)()}):f("route, method, or reqTimestamp is undefined even though they shouldn't",{flowId:o,route:r.route,method:r.method,reqTimestamp:s})},t.finishSqsInvestigation=function(e,t){if(0===t.errors.size)return;const r=w(t);if(void 0===r)return void f("finishSqsInvestigation: investigation is undefined");const n=t.getFlowId(),o=t.getMsStartTime();void 0!==o&&void 0!==n?m(r,{type:"sqs",timestamp:o,flow_id:n,messages:b(e),machine_metrics:(0,a.getMachineMetrics)(),system_info:(0,u.getSystemInfo)()}):f("reqTimestamp is undefined even though it shouldn't",{flowId:n})};const n=r(8528),o=r(8269),s=r(2546),i=r(7131),a=r(7808),c=r(7603),u=r(1427);function d(e,t){if(void 0===t)return;const r=function(e){let t=0;for(let r=0;r<e.length;r++)"\n"===e[r]&&t++;return t}(e)+1;let n=-1;for(let e=0;e<r;e++)if(n=t.indexOf("\n",n+1)??-1,-1===n)return;return-1!==n?t.slice(n+1):void 0}const l={};function f(e,...t){let r="debug";(void 0===l[e]||l[e]<s.hudConfig.dynamicConfig.investigationRateLimits.maxUniqLogs)&&(r="warn",l[e]=l[e]+1||1),s.app_logger.logLevel(r,e,...t)}function p(e){return{status:e.status,context:e.context,exceptions:Array.from(Array.from(e.exceptions?.values()??[]).map(({exception:e,executionFlow:t})=>({name:(0,i.extractNameOptional)(e),message:(0,i.extractMessage)(e),stackTrace:d(e.message,e.stack),executionFlow:t}))??[])}}function g(){return{status:n.InvestigationStatus.Open}}function h(){if(!globalThis.hudEnableInvestigation)return;const e=(0,i.getStorage)();if(void 0===e)return;const t=e.getStore();return void 0!==t&&t.status===n.InvestigationStatus.Open?(t.status=n.InvestigationStatus.Closed,t):void 0}function m(e,t){e.context=t,(0,o.storeClosedInvestigation)(p(e))}const _=/.*\((.*):(\d+):(\d+)\)/,y=/.*?(\S*):(\d+):(\d+)/;function v(e){const t=Error.prepareStackTrace;if(void 0===t||"function"!=typeof t)return void f("getStacktraceUniqString: prepareStackTrace is undefined or not a function");let r,n;try{Error.prepareStackTrace=(e,t)=>{r=t[0],n=t};const o=e.stack;if(void 0!==o&&void 0===r){const t=function(e,t){const r=d(t,e);if(void 0===r)return;const n=r.indexOf("\n");return r.slice(0,-1===n?void 0:n)}(o,e.message);if(!t)return void f("getStacktraceUniqString: firstStackTraceLine is undefined",{stack:o,message:e.message});const r=t.match(_);if(r&&r[1]&&r[2]&&r[3])return`${e.name}@${r[1]}:${r[2]}:${r[3]}`;const n=t.match(y);return n&&n[1]&&n[2]&&n[3]?`${e.name}@${n[1]}:${n[2]}:${n[3]}`:void f("getStacktraceUniqString: no match found in regex",{stack:o,message:e.message})}if(void 0===r||void 0===n)return void f("getStacktraceUniqString: result or globCallSites is undefined",{result:void 0===r,globCallSites:void 0===n});Object.defineProperty(e,"stack",{configurable:!0,enumerable:!1,get:()=>t(e,n)})}finally{Error.prepareStackTrace=t}try{return`${e.name}@${r.getFileName()}:${r.getLineNumber()}:${r.getColumnNumber()}`}catch{}}function b(e,t=s.hudConfig.investigation.maxObjectDepth){try{if("string"==typeof e)return e.length>s.hudConfig.investigation.maxStringLength?e.slice(0,s.hudConfig.investigation.maxStringLength)+"...":e;if(Array.isArray(e))return e.slice(0,s.hudConfig.investigation.maxArrayLength).map(e=>b(e,t-1));if(null===e||["number","boolean"].includes(typeof e))return e;if("bigint"==typeof e)return e.toString();if("object"==typeof e){const r={...e};for(const n in e)r[n]=b(e[n],t-1);return r}}catch{}}function w(e){const t=h();if(void 0===t)return void f("finishBaseInvestigation: investigation is undefined");if(void 0===t.firstException)return void f("finishBaseInvestigation: firstException is undefined");if(o.globalInvestigationTracking>=s.hudConfig.dynamicConfig.investigationRateLimits.maxTotalInvestigations)return void f("finishBaseInvestigation: globalInvestigationTracking is greater than maxTotalInvestigations",{globalInvestigationTracking:o.globalInvestigationTracking,maxTotalInvestigations:s.hudConfig.dynamicConfig.investigationRateLimits.maxTotalInvestigations});const r=e.getFlowId();if(void 0===r)return void f("finishBaseInvestigation: flowId is undefined");const n=v(t.firstException);if(void 0===n)return void f("finishBaseInvestigation: exceptionUniqString is undefined");const i=((0,o.getInvestigationDedupingCache)(r).get(n)??0)+1;if(!(i>s.hudConfig.dynamicConfig.investigationRateLimits.maxSameInvestigations))return(0,o.increaseGlobalInvestigationTracking)(),(0,o.increaseInvestigationDedupingCache)(r,n),t;f("finishBaseInvestigation: investigationCount is greater than maxSameInvestigations",{investigationCount:i,maxSameInvestigations:s.hudConfig.dynamicConfig.investigationRateLimits.maxSameInvestigations})}},2828:(e,t,r)=>{var n={"./codeGenieServerlessExpress":336,"./codeGenieServerlessExpress.ts":336,"./express":7127,"./express.ts":7127,"./express/methods":6730,"./express/methods.ts":6730,"./express/route":2977,"./express/route.ts":2977,"./express/router":4815,"./express/router.ts":4815,"./express/verbosity":7225,"./express/verbosity.ts":7225,"./expressApplication":2741,"./expressApplication.ts":2741,"./flows/endpoints/metrics":8901,"./flows/endpoints/metrics.ts":8901,"./flows/flow":9873,"./flows/flow.ts":9873,"./flows/graphql":6504,"./flows/graphql.ts":6504,"./flows/kafkajs":828,"./flows/kafkajs.ts":828,"./flows/sqs":2080,"./flows/sqs.ts":2080,"./frameworkPatcher":714,"./frameworkPatcher.ts":714,"./graphql":7214,"./graphql.ts":7214,"./http":5459,"./http.ts":5459,"./kafkajs":486,"./kafkajs.ts":486,"./koa":1502,"./koa.ts":1502,"./nestjsInterceptor":3531,"./nestjsInterceptor.ts":3531,"./nestjsRouterExecutionContext":646,"./nestjsRouterExecutionContext.ts":646,"./nestjsRpcContextCreator":4290,"./nestjsRpcContextCreator.ts":4290,"./nextJsConfig":9723,"./nextJsConfig.ts":9723,"./nextJsModuleLoader":1326,"./nextJsModuleLoader.ts":1326,"./nextRequestAdapter":7246,"./nextRequestAdapter.ts":7246,"./nextjs":9589,"./nextjs.ts":9589,"./router":5946,"./router.ts":5946,"./serverlessHttp":2729,"./serverlessHttp.ts":2729,"./sqsConsumer":5150,"./sqsConsumer.ts":5150};function o(e){var t=s(e);return r(t)}function s(e){if(!r.o(n,e)){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}return n[e]}o.keys=function(){return Object.keys(n)},o.resolve=s,e.exports=o,o.id=2828},2977:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.patchRoute=function(e){const t=(0,f.getMethods)();t.concat("all").forEach(function(r){const n=e.prototype[r];e.prototype[r]=function(){let e;try{e=p(Array.prototype.slice.call(arguments));let n=function(e){const t=e[0][u.hudConfig.express.layerStateSymbol];if(t)return t.flowId}(e);const o=function(e){const t=e[0][u.hudConfig.express.layerStateSymbol];if(t)return t.kind}(e),s=function(e){const t=e[0][u.hudConfig.express.layerStateSymbol];return!!t&&t.allMethod}(e);if(n||(n=[d.randomUUID()]),"application"===o)if(Array.isArray(this.path)){m(e,void 0);for(let e=0;e<this.path.length;e++)h(n[e],s?t:[r],this.path[e])}else m(e,n[0]),h(n[0],s?t:[r],this.path);else if("router"===o)if(Array.isArray(this.path)){m(e,void 0);for(let e=0;e<this.path.length;e++)g(this,n[e],r,this.path[e])}else m(e,n[0]),g(this,n[0],r,this.path);else m(e,n[0]),g(this,n[0],r,this.path)}catch(e){u.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 n.apply(this,e||arguments)}})};const a=r(8528),c=r(8269),u=r(2546),d=i(r(6982)),l=r(8949),f=r(6730),p=r(8054);function g(e,t,r,n){!function(e,t,r,n){e[u.hudConfig.express.layerStateSymbol]||(e[u.hudConfig.express.layerStateSymbol]={}),e[u.hudConfig.express.layerStateSymbol][t]?e[u.hudConfig.express.layerStateSymbol][t].methods.push(r):e[u.hudConfig.express.layerStateSymbol][t]={layerPath:n,methods:[r]}}(e,t,r,n),function(e,t,r){const n=new a.EndpointDeclaration(e,[t],"express",void 0,void 0,r);(0,c.storePartialEndpointDeclaration)(n),(0,c.storeExpressEndpointDeclaration)(n)}(t,r,n)}function h(e,t,r){const n=new a.EndpointDeclaration(e,t,"express",void 0,r,void 0);(0,c.storeExpressEndpointDeclaration)(n)}function m(e,t){if(e&&!(e.length<1)){if(u.hudConfig.express.wrapAllCallbacks)for(let r=0;r<e.length;r++){const n=(0,l.wrapFlow)(y(t),e[r],!0,v);e[r]=n}else{const r=(0,l.wrapFlow)(y(t),e[e.length-1],!0,v);e[e.length-1]=r}return t}}function _(e){return(0,c.getLinkedConsistentFlowId)(e,!1)||(u.instrument_logger.warn("No consistent flowId found, returning temporary flow id",{flowId:e}),e)}function y(e){return e?function(){return _(e)}:function(e){const t=e[0]?.route[u.hudConfig.express.layerStateSymbol],r=e[0]?.url;if(t)for(const[e,n]of Object.entries(t)){if(n.layerPath instanceof RegExp&&n.layerPath.test(r))return _(e);if(r.includes(n.layerPath))return _(e)}u.instrument_logger.warn("No flowId found for path",{states:t,url:r.split("?")[0]})}}function v(e,t,r){let n=0;if(4===r.length)n=1;else if(3!==r.length)return void u.instrument_logger.error("Invalid number of arguments in express request",{length:r.length});if(!r[n])return void u.instrument_logger.error("No request object in express request");const o=r[n][u.hudConfig.metricSymbol];o?o.setFlowId(e):u.instrument_logger.error("No endpoint metric found in express request")}},2987:e=>{"use strict";e.exports=require("perf_hooks")},3106:e=>{"use strict";e.exports=require("zlib")},3176:e=>{"use strict";e.exports=require("buffer-crc32")},3339:e=>{"use strict";e.exports=require("module")},3531:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getRequestByCallback=function(e){const t=i.get(e);return t&&i.delete(e),t},t.generateKey=a;const n=r(2546);r(1321);const o=r(8949),s=r(714),i=new Map;function a(e,t){const r=Reflect.getMetadata("path",t)??Reflect.getMetadata("microservices:pattern",t);if(!r)return void n.instrument_logger.error("No callback path found on callback",{callback:t});const o=e.constructor.CONTROLLER_ID;if(o)return`${o}.${r}`;n.instrument_logger.error("No controller id found on controller",{controller:e})}class c extends s.FrameworkPatcher{_patch(e){return this._patchIntercept(e),n.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 n;if("rpc"===e[5]){if("win32"===process.platform)return;n=e[1][1].args[0]}else if(n=e[1][0],!n||n.raw)return;const o=a(t,r);if(!o)return;i.set(o,n)}else n.instrument_logger.error("Invalid args in NestJS InterceptorsConsumer.intercept",{args:e})}catch(e){n.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,o.copyPropertiesToTarget)(t,e.InterceptorsConsumer.prototype.intercept)}}t.default=c},3868:e=>{"use strict";e.exports=require("@jridgewell/sourcemap-codec")},3901:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t}),a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFunctionWrapperTemplate=y,t.splitCode=S,t.editInSplits=M,t.editWithCliBuildId=function(e,t,r,n){let{transformedCode:o,metadatas:s}=P(e,t,r,!0);return o+=`\n//# sourceMappingURL=${m.default.basename(t)}.map`,o+=`\n//"${n}";${d.hudConfig.cliSdkVersionVarName}="${d.SDK_VERSION}";${d.hudConfig.cliBuildIdVarName}`,{transformedCode:o,metadatas:s}},t.edit=P,t.incrementInstrumentedFunctionsCount=O;const c=a(r(3176)),u=r(3903),d=r(2546),l=r(8528),f=r(8269),p=r(2546),g=r(3868),h=i(r(2784)),m=a(r(6928)),_=/([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 y(e,t,r=!1){const n=`${e}_hudTemp`,o="BODY_PLACEHOLDER",s="FUNCTION_ID_PLACEHOLDER",i="AWAITABLE_PLACEHOLDER",a="EXCEPTION_VARIABLE_PLACEHOLDER",c=function(e,t,r=!1){const n=[];if(r)return n;let o;t===l.Format.cjs?o="require":t===l.Format.esm&&(n.push(`import { createRequire as ${e}_createRequire } from "module";`,`const ${e}_require = ${e}_createRequire(import.meta.url);`),o=`${e}_require`);const s=p.myRequire.resolve(d.SDK_MODULE_NAME+"/wrap");return n.push(`let ${e}_temp;`,`try { ${e}_temp = ${o}(String.raw\`${s}\`); } catch (e) { ${e}_temp = { wrapperInitial: () => {}, wrapperCatch: () => {}, wrapperFinally: () => {}, fixStack: () => {}, wrapperUserCatch: () => {} }; }`,`const { wrapperInitial: ${e}_wi, wrapperCatch: ${e}_wc, wrapperFinally: ${e}_wf, fixStack: ${e}_fs, asyncIteratorWrapper: ${e}_aiw, wrapperUserCatch: ${e}_wuc } = ${e}_temp;`),n}(e,t,r);return{functionWrapper:`{\n let ${n};\n const ${d.hudConfig.functionIdVarName} = ${s};\n const ${e}_cc = {};\n try {\n ${e}_wi(${d.hudConfig.functionIdVarName}, ${e}_cc);\n } catch (e) {\n globalThis._hud_SI = { value: 0 };\n globalThis._hud_S = [];\n globalThis._hud_F = "";\n }\n try {\n ${o}\n } catch (e) {\n try {\n ${e}_wc(${d.hudConfig.functionIdVarName}, ${e}_cc, e);\n } catch (e) {}\n throw e;\n } finally {\n try {\n ${e}_wf(${d.hudConfig.functionIdVarName}, ${e}_cc);\n } catch (e) {}\n }\n }`,awaitWrapper:`(${n} = ${i}, _hud_SI.value--, _hud_F = "", ${e}_cc.ff = true, ${n} = await ${n}, _hud_S[++_hud_SI.value] = ${d.hudConfig.functionIdVarName}, _hud_F = ${e}_cc.currentFlowId, ${e}_cc.ff= false, ${n})`,yieldWrapper:`\n function* ${e}_generatorWrapper() {\n return (${n} = ${i}, _hud_SI.value--, _hud_F = "", ${e}_cc.ff = true, ${n} = yield ${n}, _hud_S[++_hud_SI.value] = ${d.hudConfig.functionIdVarName}, _hud_F = ${e}_cc.currentFlowId, ${e}_cc.ff= false, ${n})\n }`,yieldStarWrapper:`\n function* ${e}_generatorWrapper() {\n return (${n} = ${i}, _hud_SI.value--, _hud_F = "", ${e}_cc.ff = true, ${n} = yield* ${n}, _hud_S[++_hud_SI.value] = ${d.hudConfig.functionIdVarName}, _hud_F = ${e}_cc.currentFlowId, ${e}_cc.ff= false, ${n})\n }`,initialStatements:c,bodyPlaceholder:o,functionIdPlaceholder:s,awaitablePlaceholder:i,fixStackFunction:`\n try{\n ${e}_fs(${d.hudConfig.functionIdVarName}, ${e}_cc)\n }catch(e){};`,exceptionVariablePlaceholder:a,wrapperUserCatch:`\n try {\n ${e}_wuc(${d.hudConfig.functionIdVarName}, ${e}_cc, ${a});\n } catch(e){};`,asyncIteratorWrapper:`${e}_aiw`,awaitableVariable:n}}function v(e,t,r=!0,n=!1,o){const s=Error.prepareStackTrace;let i=!1,a=function(e){const t=e.match(`${d.hudConfig.bundlerBuildIdVarName}="${_.source}"`);if(t&&t.length>0)return t[1]}(e);a||(a=function(e){return(0,u.v5)(e,d.hudConfig.bundlerBuildUuidNamespace)}(e),i=!0);const l=(0,u.v5)(e,d.hudConfig.functionUuidNamespace),f=(0,c.default)(t.filename).readUInt32BE(),g=(0,c.default)(e).readUInt32BE(),m=(0,p.isNextJsApp)(),v={data:t,bundlerBuildId:a,prefix:d.hudConfig.wrapVarPrefix,...y(d.hudConfig.wrapVarPrefix,t.format,n),uuidNamespace:d.hudConfig.functionUuidNamespace,fileHash:l,useInputSourcemap:r,isNextJsFile:m,markCode:d.hudConfig.nextJsMarkVarName,enableForAwaitInstrumentation:!o},b=h.transform(e,v);return O(b.functionsIds.length,o),m&&b.marksCount!==b.functionsIds.length&&d.instrument_logger.warn("Marks count mismatch while instrumenting functions",{marksCount:b.marksCount,functionsIdsLength:b.functionsIds.length,filename:t.filename}),Error.prepareStackTrace=s,d.instrument_logger.debug(`Successfully transformed ${t.filename}`),{code:b.code,map:b.map,functionIds:b.functionsIds,filename:t.filename,hasInputMap:b.isInputSourcemap,bundlerBuildId:a,bundlerBuildIdGenerated:i,file_path_checksum:f,file_checksum:g,sourceCodeHash:l,moduleBase:b.moduleBase,isNextJsApp:m,marksCount:b.marksCount,detectedForAwaitLoops:b.detectedForAwaitLoops}}class b extends Error{}function w(e,t){if(e&&t)throw new b("Start mark found inside mark");if(!e&&!t)throw new b("End mark found outside mark")}function k(e,t,r,n){const o=e.split("\n");let s=r,i=n;return s+=o.length-1,s+=t.split("\n").length-1,s===r?i+=o.pop()?.length||0:i=o.pop()?.length||0,{lineOffset:s,columnOffset:i}}function*S(e){let t=!1,r=0,n=0,o=!1,s=0,i=0;const a=new RegExp(`globalThis\\s*?&&\\s*?\\(globalThis\\.${d.hudConfig.esbuildGlobalVar}\\s*?=\\s*?"(Start|End):(?<fileName>.*?)"\\);?`,"g");for(const c of e.matchAll(a)){if(o=!0,!c.groups)throw new b("No groups found in match");const{fileName:a}=c.groups,[u,d]=c,l="Start"===d;w(l,t);let f="";if(t){const t=c.index+u.length;f=e.slice(r,t);const o=n+Buffer.byteLength(f,"utf8");yield{edit:!0,code:f,fileName:a,lineOffset:s,columnOffset:i,indexOffset:n,indexOffsetEnd:o},r=t,n=o}else{const t=c.index;f=e.slice(r,t),n+=Buffer.byteLength(f,"utf8"),r=t,yield{edit:!1,code:f}}t=!!l,({lineOffset:s,columnOffset:i}=k(f,u,s,i))}if(t)throw new b("End mark found outside mark");o?r<e.length&&(yield{edit:!1,code:e.slice(r)}):yield{edit:!1,code:e}}function E(e,t,r){d.instrument_logger.debug("Edit chunk",{fileName:e.fileName,size:e.code.length,edit:t}),r?.push({fileName:e.fileName,size:e.code.length,edit:t})}function x(e,t,r){const n=v(e.code,{filename:t,format:r},!1,!0,!1),o=n.code;return n.mapRelativeToChunk=n.map,n.map=function(e,t,r){"string"==typeof e&&(e=JSON.parse(e));const n=(0,g.decode)(e.mappings);return n.forEach(e=>{e.forEach(e=>{e.length>=4&&"number"==typeof e[2]&&("number"==typeof e[3]&&0===e[2]&&(e[3]+=r),e[2]+=t)})}),JSON.stringify({...e,mappings:(0,g.encode)(n),sourcesContent:void 0})}(n.map,e.lineOffset,e.columnOffset),{codeToAppend:o,metadata:{...n,filename:t,lineOffset:e.lineOffset,columnOffset:e.columnOffset}}}function M(e,t,r,n=!1,o=!1,s=()=>!0){const i=e.slice(-1e3);if(!o&&null!==h.getSourceMap(t,i))return d.instrument_logger.error("Source map found for esbuild split",{filename:t}),d.customer_logger.log(d.UserErrorLogs.EsbuildSourceMapFound()),(0,f.detachHud)(!1,!1),{transformedCode:e,metadatas:[],editedChunksSizes:void 0};let a="",c=0,u=0;const l=[];let p=0;const g=n?[]:void 0,m=y(d.hudConfig.wrapVarPrefix,r).initialStatements.join("\n"),_=function(e){return e.slice(d.hudConfig.esbuildMark.length,d.hudConfig.esbuildMark.length+36)}(e);for(const n of S(e)){p++;try{let e="",o=!1;if(n.edit&&(o=s(n.fileName),g&&E(n,o,g)),n.edit&&o){const o=x(n,t,r);e=o.codeToAppend,l.push({...o.metadata,bundlerBuildId:_,transformedLineOffset:c,transformedColumnOffset:u,indexOffset:n.indexOffset,indexOffsetEnd:n.indexOffsetEnd})}else e=0===a.length?C(n.code,m):n.code;({transformedCodeLineOffset:c,transformedCodeColumnOffset:u}=I(e,c,u)),a+=e}catch(r){return d.instrument_logger.error("Failed to patch index",{index:p,filename:t,msg:r instanceof Error?r.message:void 0,stack:r instanceof Error?r.stack:void 0}),{transformedCode:e,metadatas:[],editedChunksSizes:g}}}return{transformedCode:a,metadatas:l,editedChunksSizes:g}}function C(e,t){let r="";return e.startsWith('"use strict";')?(r+='"use strict";',r+=t,r+=e.slice(13),r):(r+=t,r+=e,r)}function I(e,t,r){const n=e.split("\n");return n.length>1?(t+=n.length-1,r=n.pop()?.length||0):r+=e.length,{transformedCodeLineOffset:t,transformedCodeColumnOffset:r}}function P(e,t,r,n){if(e.startsWith(d.hudConfig.esbuildMark))return d.instrument_logger.info("Editing in splits"),M(e,t,r,!1);{const o=v(e,{filename:t,format:r},d.hudConfig.userConfig.disableSourceMapsResolution?.value??!0,!1,n);return{transformedCode:o.code,metadatas:[o]}}}let F=0;function O(e,t){F+=e;const r=d.hudConfig.userConfig?.maxMappedFunctions?.value??0;F>=r&&(t||d.customer_logger.log(d.UserErrorLogs.InstrumentedFunctionCountExceeded(r)),d.app_logger.error("Instrumented function count exceeded",{instrumentedFunctionsCount:F,maxMappedFunctions:r}),(0,f.detachHud)(!1,!1))}},3903:e=>{"use strict";e.exports=require("uuid")},4290:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2546),o=r(8949),s=r(714),i=r(3531);class a extends s.FrameworkPatcher{_patch(e){return this._patchCreate(e),n.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 s=(0,i.generateKey)(t,r);s&&(e[1]=(0,o.wrapFlow)(()=>{try{const e=(0,i.getRequestByCallback)(s);if(!e)return void n.instrument_logger.error("No msg object found for key",{key:s});const t=function(e){if(e)return e[n.hudConfig.metricSymbol]?e[n.hudConfig.metricSymbol].getFlowId?e[n.hudConfig.metricSymbol].getFlowId():void n.instrument_logger.error("No getFlowId function found on metric object"):void n.instrument_logger.error("No metric found on nestjs msg object")}(e);return t||n.instrument_logger.error("No flow id found for key",{key:s}),t}catch(e){n.instrument_logger.error("Error in NestJS getFlowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}},r,!0))}else n.instrument_logger.error("Invalid args in NestJS RpcContextCreator.create",{args:e})}catch(e){n.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,o.copyPropertiesToTarget)(t,e.RpcContextCreator.prototype.create)}}t.default=a},4815:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.patchUse=function(e,t,r=!0){const n=e.use;e.use=function(e){const o=n.apply(this,arguments);try{let n=this[l.uuidSymbol];!n&&l.isVerboseLoggingEnabled&&(n=u.randomUUID(),this[l.uuidSymbol]=n,c.instrument_logger.info("Express use setting uuid",{kind:t,uuid:n})),"application"===t?function(e,t,r,n){try{r&&(e._router?p(e._router):e.router?p(e.router):c.instrument_logger.warn("Express application doesn't have router or _router")),n&&l.isVerboseLoggingEnabled&&c.instrument_logger.info("Express use app",{parent:n,child:t[1]?.[l.uuidSymbol]||"no uuid",path:t[0]})}catch(e){c.instrument_logger.error("Failed to save express app router",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}(this,arguments,r,n):"router"===t&&function(e,t,r,n,o){try{if(!e.stack)return void c.instrument_logger.error("Express router without stack");if(0===e.stack.length)return void c.instrument_logger.warn("Express router with an empty stack");"query"===e.stack[0].name?p(e):l.isVerboseLoggingEnabled&&!l.skipLayerNamesLogs.has(e.stack[0].name)&&(l.skipLayerNamesLogs.add(e.stack[0].name),c.instrument_logger.warn("Found unknown stack name",{stack:e.stack[0].name}));const{path:s,offset:i}=function(e){let t=0,r="/";if("function"!=typeof e){let n=e;for(;Array.isArray(n)&&0!==n.length;)n=n[0];"function"!=typeof n&&(t=1,r=e)}return{path:r,offset:t}}(o),a=f(Array.prototype.slice.call(t,i));for(let t=0;t<a.length&&t<e.stack.length;t++){const o=e.stack[e.stack.length-t-1],i=a[a.length-t-1];"router"===o.name?(i&&!i[l.uuidSymbol]&&l.isVerboseLoggingEnabled&&(i[l.uuidSymbol]=u.randomUUID(),c.instrument_logger.info("Express handle router setting uuid",{uuid:i[l.uuidSymbol]})),r&&(o[c.hudConfig.express.routeNamesSymbol]=s)):l.isVerboseLoggingEnabled&&!l.skipLayerNamesLogs.has(o.name)&&(l.skipLayerNamesLogs.add(o.name),c.instrument_logger.warn("Found unknown layer name",{layer:o.name,parent:n,child:i[l.uuidSymbol]||"no uuid",path:s}))}}catch(e){c.instrument_logger.error("Failed to patch router.use function",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}(this,arguments,r,n,e)}catch(e){c.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})}return o},(0,d.copyPropertiesToTarget)(n,e.use)},t.extractEndpointsFromRouter=function e(t,r){let n=[];if(!r.stack)return c.instrument_logger.error("Router without stack - bad OTEL version",{router:r}),n;for(const o of r.stack)if("router"===o.name){if(!o[c.hudConfig.express.routeNamesSymbol]){c.instrument_logger.error("Router layer without routes",{layer:o});continue}const r=t+o[c.hudConfig.express.routeNamesSymbol];n=n.concat(e(r,o.handle))}else o.route&&o.route[c.hudConfig.express.layerStateSymbol]?n=n.concat(g(o,t)):l.isVerboseLoggingEnabled&&!l.skipLayerNamesLogs.has(o.name)&&(l.skipLayerNamesLogs.add(o.name),c.instrument_logger.warn("Found unknown layer name when extracting endpoints",{layer:o.name}));return n};const a=r(8528),c=r(2546),u=i(r(6982)),d=r(8949),l=r(7225),f=r(8054);function p(e){e[c.hudConfig.express.markedSymbol]||(globalThis.hudExpressState.push(e),e[c.hudConfig.express.markedSymbol]=!0)}function g(e,t){const r=[];for(const[n,o]of Object.entries(e.route[c.hudConfig.express.layerStateSymbol]))r.push(new a.EndpointDeclaration(n,o.methods,"express",t,o.layerPath));return Array.from(r.values())}},5150:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(8269),o=r(2546),s=r(7131),i=r(2822),a=r(8949),c=r(2080),u=r(714);class d extends u.FrameworkPatcher{isSupported(e,t,r,n){const s=o.hudConfig.userConfig.enableDapulse?.value?n.mondayVersion:n.bbcVersion,i=(0,u.extractModuleVersion)(e);return!!(0,u.isSupportedVersion)(i,s)||(o.instrument_logger.warn("Unsupported sqs-consumer version",{framework:"SqsConsumer",version:i,supportedVersion:s,basedir:e,isDapulse:o.hudConfig.userConfig.enableDapulse?.value}),o.customer_logger.log(o.UserErrorLogs.UnsupportedFrameworkVersion("sqs-consumer")),!1)}_patch(e){return function(e){const t=e.Consumer.create;e.Consumer.create=function(...e){const r=t.apply(this,e);try{!function(e){const t=e.queueUrl;if(!t)throw new o.HudNoQueueUrlInSqsConsumer;const r=p(t);if(e.handleMessageBatch&&"function"==typeof e.handleMessageBatch){const t="handleMessageBatch",s=(0,o.generateSqsFlowId)(r,t);(0,n.storeSqsQueueDeclaration)({flow_id:s,queue_name:r,handle_type:t,batch_size:e.batchSize});const i=e.handleMessageBatch,c=(0,a.wrapFlow)(()=>s,i,!0,g);return void(e.handleMessageBatch=c)}if(e.handleMessage&&"function"==typeof e.handleMessage){const t="handleMessage",s=(0,o.generateSqsFlowId)(r,t);(0,n.storeSqsQueueDeclaration)({flow_id:s,queue_name:r,handle_type:t});const i=e.handleMessage,c=(0,a.wrapFlow)(()=>s,i,!0,g);return void(e.handleMessage=c)}o.instrument_logger.warn("Unable to getFlowId - No handleMessage or handleMessageBatch found in SqsConsumer.Consumer",{queueName:r})}(r),function(e){const t=e.on;e.on=function(...r){try{const t=r[0];if(!t||"string"!=typeof t)throw new o.HudNoEventTypeInSqsConsumerOn;const s=r[1];if(!s||"function"!=typeof s)throw new o.HudNoCallbackInSqsConsumerOn;const i=p(e.queueUrl),c="event",u=(0,o.generateSqsFlowId)(i,c,t);(0,n.storeSqsQueueDeclaration)({flow_id:u,queue_name:i,handle_type:c,event_type:t}),r[1]=(0,a.wrapFlow)(()=>u,s,!0,h,m,_)}catch(e){o.instrument_logger.error("Error in SqsConsumer.Consumer.on patched logic",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t.apply(this,r)},(0,a.copyPropertiesToTarget)(t,e.on)}(r),function(e){const t=e.emit;e.emit=function(...e){return function(e){try{const t=e[0];if(!t||"string"!=typeof t)throw new o.HudNoEventTypeInSqsConsumerEmit;let r,n;if("message_processed"===t&&(r=1),["error","timeout_error","processing_error"].includes(t)&&(n=1,r=2),void 0===r)return;const a=e[r];if(!a)throw new o.HudNoMessageInSqsConsumerEmit;let c;if(void 0!==n){const t=e[n];if(!(t&&t instanceof Error))throw new o.HudNoErrorInSqsConsumerEmit;c=(0,s.extractName)(t),"StandardError"===c&&t.cause&&t.cause instanceof Error&&(c=(0,s.extractName)(t.cause))}const u=(e,t)=>{const r=e[o.hudConfig.metricSymbol];r?(c&&r.addError(c,t),r.increaseAndShouldEnd(t)&&(r.end(),(0,i.finishSqsInvestigation)(Array.isArray(a)?a:[a],r))):f||(f=!0,o.instrument_logger.warn("No metric found for message"))};Array.isArray(a)&&a.length>=1?u(a[0],a.length):u(a,1)}catch(e){l||(l=!0,o.instrument_logger.error("Error in SqsConsumer.Consumer.emit patched logic",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0}))}}(e),t.apply(this,e)},(0,a.copyPropertiesToTarget)(t,e.emit)}(r)}catch(e){o.instrument_logger.error("Error in patching SqsConsumer.Consumer",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return r},(0,a.copyPropertiesToTarget)(t,e.Consumer.create)}(e),o.instrument_logger.info("Patched sqs-consumer successfully",{isDapulse:o.hudConfig.userConfig.enableDapulse?.value}),e}}t.default=d;let l=!1,f=!1;function p(e){const t=e.split("/").pop();if(!t)throw new o.HudFailExtractSqsQueueName(`Url: ${e}`);return t}function g(e,t,r){const n=c.SqsMetric.createUsableMetric(e);n.start();const s=r[0];if(!s)return o.instrument_logger.warn("No messages pass to sqs handler",{flowId:e}),void(t.flowMetric=n);if(Array.isArray(s)){if(n.msgCount=s.length,s.forEach(e=>{e[o.hudConfig.metricSymbol]=n}),s[0]?.Attributes?.SentTimestamp){const t=s.reduce((e,t)=>{const r=Number.parseInt(t?.Attributes?.SentTimestamp);return isNaN(r)?e:Math.min(e,r)},1/0);t!==1/0?n.e2eEpocStartTimeMS=t:o.instrument_logger.warn("No valid SentTimestamp found eventhough the first element had SentTimestamp",{flowId:e})}}else n.msgCount=1,s[o.hudConfig.metricSymbol]=n,s?.Attributes?.SentTimestamp&&(n.e2eEpocStartTimeMS=s.Attributes.SentTimestamp);t.flowMetric=n,(0,i.createNewInvestigation)()}function h(e,t,r){const n=c.SqsMetric.createUsableMetric(e);n.start(),t.flowMetric=n}function m(e,t){const r=t.flowMetric;r?r.end():o.instrument_logger.warn("No flowMetric found for message during catch",{flowId:e})}function _(e,t,r){const n=t.flowMetric;n?(n.addError((0,s.extractName)(r)),n.end()):o.instrument_logger.warn("No flowMetric found for message during catch",{flowId:e})}},5459:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getHttpMetricFromRequest=function(e){return e[n.hudConfig.metricSymbol]};const n=r(2546),o=r(2822),s=r(8949),i=r(8901),a=r(714);class c extends a.FrameworkPatcher{_patch(e){return this._patchEmit(e),n.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],s=i.HttpEndpointMetric.createUsableMetric();s.start(),(0,o.createNewInvestigation)(),s.setRequestAttributes(e),t.once("finish",function(){try{(0,o.finishHttpInvestigation)(e,t,s),s.setResponseAttributes(t),s.end()}catch(e){n.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[n.hudConfig.metricSymbol]=s}catch(e){n.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,s.copyPropertiesToTarget)(t,e.Server.prototype.emit)}}t.default=c},5688:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.hudRITM=void 0,t.safeLog=function(e){try{o.app_logger.debug(e)}catch(e){return}},t.registerHook=function(){if(o.app_logger.info("HUD is required"),process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE){if(o.app_logger.info("Running in Lambda environment"),parseInt(process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE)<o.hudConfig.lambdaMinimunMemory){const e=process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE;return o.app_logger.warn("Lambda function memory size is less than required, Hud will not run",{memorySize:e}),o.customer_logger.log(o.UserErrorLogs.UnsupportedLambdaMemory()),!1}globalThis.hudRuningInsideLambda=!0}return(0,n.initGlobals)(),o.app_logger.debug("InitGlobals done"),!(globalThis.hudStartFromAutoInit&&!(0,n.validateAndGetUserInput)())&&(o.instrument_logger.isValid()?globalThis.hudRanOnRequire?(o.instrument_logger.warn("Already ran onRequire!"),!1):(globalThis.hudRanOnRequire=!0,o.instrument_logger.info("Using module",{name:o.SDK_MODULE_NAME}),(0,s.onRequire)(),(0,o.detectNextJsApp)(),o.instrument_logger.debug("onRequire done"),globalThis.hudInitGuard=setTimeout(i,o.hudConfig.userConfig.maxTimeUntilInitSessionMs?.value??0),globalThis.hudInitGuard.unref(),!0):((0,n.detachHud)(!1),!1))};const n=r(8269),o=r(2546),s=r(7166);function i(){o.instrument_logger.warn("Init timeout disabling hud!"),o.customer_logger.log(o.UserErrorLogs.InitTimeout(globalThis.hudIsRunningFromSetup)),(0,n.detachHud)(!1)}t.hudRITM=s.onRequireFn},5946:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2546),o=r(6730),s=r(4815),i=r(714);class a extends i.FrameworkPatcher{_patch(e){return(0,s.patchUse)(e.prototype,"router"),(0,o.patchMethods)(e.prototype,"router"),n.instrument_logger.info("Patched router successfully"),e}}t.default=a},6093:e=>{"use strict";e.exports=require("@cspotcode/source-map-support")},6504:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.GraphQLMetric=void 0;const n=r(9873);class o extends n.FlowMetric{constructor(e){super(e)}_createUsableMetric(e){return this}toRaw(){return{flow_id:this.flowId,type:"GraphQLMetric",duration:this.duration}}}t.GraphQLMetric=o},6730:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.getMethods=l,t.patchMethods=function(e,t){l().concat("all").forEach(function(r){const n=e[r];if(!n)return void(d.isVerboseLoggingEnabled&&a.instrument_logger.warn("Method not found",{method:r}));const o="all"===r;e[r]=function(){try{if(arguments.length<2)return n.apply(this,arguments);let e=this[d.uuidSymbol];d.isVerboseLoggingEnabled&&(e||(e=c.randomUUID(),this[d.uuidSymbol]=e,a.instrument_logger.info("Express method setting uuid",{uuid:e,kind:t})),a.instrument_logger.info("Express added new method",{method:r,uuid:e,path:arguments[0]}));const s=Array.prototype.slice.call(arguments);if(s[1][a.hudConfig.express.layerStateSymbol]={flowId:[],kind:t,allMethod:o},Array.isArray(s[0]))for(const e of s[0]){const e=c.randomUUID();s[1][a.hudConfig.express.layerStateSymbol].flowId.push(e)}else s[1][a.hudConfig.express.layerStateSymbol].flowId.push(c.randomUUID());const i=n.apply(this,s);try{delete s[1][a.hudConfig.express.layerStateSymbol]}catch(e){}return i}catch(e){a.instrument_logger.error("Failed to patch method",{kind:t,method:r,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return n.apply(this,arguments)},(0,u.copyPropertiesToTarget)(n,e[r])})};const a=r(2546),c=i(r(6982)),u=r(8949),d=r(7225);function l(){const e=r(8611);return e.METHODS&&e.METHODS.map(function(e){return e.toLowerCase()})||["get","post","put","head","delete","options","trace","copy","lock","mkcol","move","purge","propfind","proppatch","unlock","report","mkactivity","checkout","merge","m-search","notify","subscribe","unsubscribe","patch","search","connect"]}},6858:e=>{"use strict";e.exports=require("commander")},6928:e=>{"use strict";e.exports=require("path")},6982:e=>{"use strict";e.exports=require("crypto")},7127:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2546),o=r(6730),s=r(2977),i=r(4815),a=r(7225),c=r(714);class u extends c.FrameworkPatcher{_patch(e){return(0,s.patchRoute)(e.Route),(0,i.patchUse)(e.application,"application"),(0,o.patchMethods)(e.application,"application"),a.isVerboseLoggingEnabled&&(0,a.logLazyRouter)(e.application),e.Router.use?((0,i.patchUse)(e.Router,"router"),(0,o.patchMethods)(e.Router,"router")):n.instrument_logger.warn("Skipping express.Router patching"),n.instrument_logger.info("Patched express successfully"),e}}t.default=u},7131:e=>{"use strict";e.exports=require("./wrap")},7166:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.parseCliInstrumentationPattern=b,t.supportSourceMapInstall=w,t.patch=k,t.patchCompile=M,t.onRequireFn=C,t.patchRequire=I,t.createCheckers=N,t.updateModuleChecker=j,t.skip=q,t.onRequire=function(){try{(0,d.setInstrumentedFilesCountInterval)(),j();try{M()}catch(e){d.instrument_logger.error("Failed to patch compile",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}try{(0,d.shouldSupportSourceMap)()&&w()}catch(e){d.instrument_logger.error("Failed to install source map support",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}try{I()}catch(e){d.instrument_logger.error("Failed to patch require",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}catch(e){d.instrument_logger.error("Something went wrong in onRequire",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}try{(0,p.saveMachineMetric)()}catch(e){d.instrument_logger.error("Failed to add metric",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}};const a=i(r(9896)),c=i(r(6928)),u=r(8528),d=r(2546),l=r(3901),f=r(8528),p=r(8269),g=r(2546),h=r(9063),m=r(714),_=function(){const e=g.SDK_MODULE_NAME;try{return c.dirname(c.dirname(g.myRequire.resolve(e)))}catch(t){return d.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 y(e){const t=globalThis.HudSourceMapCache.get(e);return t?{map:JSON.parse(t)}:null}const v=new RegExp(`//"([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})";${g.hudConfig.cliSdkVersionVarName}="([^"]+)";${g.hudConfig.cliBuildIdVarName}`);function b(e){if(e.slice(-g.hudConfig.cliBuildIdVarName.length)!==g.hudConfig.cliBuildIdVarName)return null;const t=Math.min(100,e.length),r=e.slice(-t).match(v);return r?{buildId:r[1],sdkVersion:r[2],fullPattern:r[0]}:null}function w(){r(6093).install({handleUncaughtExceptions:!1,hookRequire:!1,environment:"node",retrieveSourceMap:y})}function k(e,t,r,n){const o={code:e,map:void 0};try{if(globalThis.hudRunningMode===f.HudRunningMode.detached)return o;if(r===u.Format.esm&&!n)throw new g.HudError("MessagePort is required for patching ESM modules");const s=b(e);if(s)return s.sdkVersion!==g.SDK_VERSION?(d.instrument_logger.error("SDK version mismatch detected, disabling SDK",{filename:t,cliSdkVersion:s.sdkVersion,currentSdkVersion:g.SDK_VERSION}),(0,p.detachHud)(!1,!1),o):((0,p.addReingestValue)(s.buildId),globalThis.hudDeclarationsFound=!0,globalThis.hudInstrumentationIndicator&&(clearTimeout(globalThis.hudInstrumentationIndicator),globalThis.hudInstrumentationIndicator=void 0),o);if(g.hudConfig.userConfig.disableRuntimeInstrumentation?.value)return o;if(q(t))return o;if(e.length>(g.hudConfig.userConfig.maxFileSizeBytes?.value??0)&&!e.startsWith(g.hudConfig.esbuildMark))return d.instrument_logger.info("Skipping large file",{filename:t,size:e.length}),o;const i=Date.now(),h=(0,l.edit)(e,t,r,!1),m=h.metadatas;if(o.code=h.transformedCode,o.map=m,d.instrument_logger.debug("Patched",{filename:t,time:Date.now()-i}),(0,d.incrementInstrumentedFilesCount)(),n)for(const e of m)n.postMessage({key:"HudModulePatch",hudPatched:t,hudProcessedFiles:(0,d.sourceFileMetadataToTransferSourceFileMetadata)(e)});else globalThis.hudPatched.add(t),globalThis.hudProcessedFiles.push(...m.map(e=>(0,d.sourceFileMetadataToTransferSourceFileMetadata)(e))),globalThis.hudDeclarationsFound=!0,globalThis.hudInstrumentationIndicator&&(clearTimeout(globalThis.hudInstrumentationIndicator),globalThis.hudInstrumentationIndicator=void 0);g.hudConfig.writePatched&&function(e,t){const r=c.parse(e);let n=`${r.dir}/patched.${r.base}`;r.dir.includes("dist")&&(n=c.join(`${r.dir.replace("dist","patched")}`,r.base)),a.existsSync(c.dirname(n))||a.mkdirSync(c.dirname(n),{recursive:!0}),a.writeFileSync(n,t,"utf8"),d.instrument_logger.debug("Dumped patched file",{filename:e,patchedPath:n})}(t,h.transformedCode)}catch(e){d.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 o}let S="",E=!0,x=!1;function M(){if(!(0,g.isSupportedNative)())return;const e=r(3339),t=(0,d.shouldSupportSourceMap)();x&&d.instrument_logger.warn("PatchCompile ran twice"),0===Object.keys(globalThis.hudLoadedModules).length&&(globalThis.hudLoadedModules=Object.keys(g.myRequire.cache));const n=e.prototype._compile;e.prototype._compile=function(e,r){if(r===S){try{const e=E?d.instrument_logger.warn.bind(d.instrument_logger):d.instrument_logger.debug.bind(d.instrument_logger);E=!1,e("Skipping compile since already ran",{filename:r})}catch{}return n.call(this,e,r)}S=r,d.instrument_logger.verbose("Compiling requirement",{filename:r});const o=k(e,r,u.Format.cjs);try{if(t&&o.map){const e=(0,d.combineSourceMaps)(o.map,r);e&&globalThis.HudSourceMapCache.set(r,e)}}catch(e){d.instrument_logger.error("Failed to combine source maps",{filename:r,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}const s=n.call(this,o.code,r);return S="",s},x=!0,d.instrument_logger.debug("Patched _compile")}function C(e,t,r){try{const n=g.hudConfig.frameworksToPatch.get(t);return n?.patcher&&n.version?(0,m.getFrameworkPatcher)(n.patcher).patch(e,r,n.version,n.extraInfo,t):e}catch(e){d.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}function I(){new h.Hook(Array.from(g.hudConfig.frameworksToPatch.keys()),{internals:!0},C)}function P(e){const t=c.sep.replace(/\\/g,"\\\\"),r=c.join(e).split(".").join("\\.").split("*").join(".*?"),n=t+"node_modules"+t;return{isAllowdModule:new RegExp(n+r+`(?:${t}|$)`),isAllowdModuleSubModule:new RegExp(n+r+n)}}function F(e,t){return!!t.isAllowdModule.test(e)&&!t.isAllowdModuleSubModule.test(e)}function O(e,t){const r=t.replace(/\//g,c.sep);return e.includes(`node_modules${c.sep}${r}${c.sep}`)&&!e.includes(`node_modules${c.sep}${r}${c.sep}node_modules`)}function N(e){const t=[];for(const r of e){let e;if(r.includes("*")){const t=P(r);e=e=>F(e,t)}else e=e=>O(e,r);t.push(e)}return t}let T=[];function j(){T=N(g.hudConfig.userConfig.includeModules?.value??[])}function q(e,t){if(!g.hudConfig.allowedEditExtensions.includes(c.extname(e))&&!e.endsWith(c.sep))return d.instrument_logger.warn("Skipping non-allowed extension",{filename:e}),!0;const r=t??T;return"/var/runtime/index.mjs"===e?(d.instrument_logger.debug("Skipping lambda runtime",{filename:e}),!0):e.includes("node_modules")&&!function(e,t){for(const r of t)if(r(e))return!0;return!1}(e,r)||e.includes(".yarn")?(d.instrument_logger.debug("Skipping non-monitored imported module",{filename:e}),!0):!(_&&!e.includes(_)||(d.instrument_logger.debug("Skipping hud internal module",{filename:e}),0))}},7214:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(8528),o=r(8269),s=r(2546),i=r(8949),a=r(6504),c=r(714);class u extends c.FrameworkPatcher{static graphQLPatchedSymbol=Symbol.for(s.hudConfig.hudPatchedName);_patch(e){return this.patchGraphql(e),s.instrument_logger.info("Patched GraphQL successfully"),e}patchGraphql(e){const t=e.execute;e.execute=function(e){!function(e){try{e&&!e[u.graphQLPatchedSymbol]&&(d(e._queryType),d(e._mutationType),e[u.graphQLPatchedSymbol]=!0,s.instrument_logger.info("Patched GraphQL schema successfully"))}catch(e){s.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=>(g(t,r),e)):(g(t,r),e)}(t.apply(this,arguments),e.document,r)},(0,i.copyPropertiesToTarget)(t,e.execute)}}function d(e){if(!e)return;const t=e._fields;Object.keys(t).forEach(r=>{const c=t[r];!function(e,t,r){if(e.resolve&&!e.resolve[u.graphQLPatchedSymbol]){const n=(0,s.generateGraphqlFlowId)(r,t);(0,o.storeResolverDeclaration)({id:n,operation:t,name:r});const c=e.resolve;e.resolve=(0,i.wrapFlow)(p,c,!0,(e,t)=>{const r=a.GraphQLMetric.createUsableMetric();r.start(),r.setFlowId(e),t.flowMetric=r},(e,t)=>{const r=t.flowMetric;r?r.end():s.instrument_logger.warn("No flowMetric found for resolver",{flowId:e})},(e,t)=>{const r=t.flowMetric;r?r.end():s.instrument_logger.warn("No flowMetric found for resolver",{flowId:e})}),e.resolve[u.graphQLPatchedSymbol]=!0,(0,o.storeResolverIdBySelectionName)(n,r)}}(c,n.GraphQLSupportedOperations[e.name.toLowerCase()],r),c.type._fields&&f(c.type)})}t.default=u;const l=new WeakSet;function f(e){e&&e._fields&&!l.has(e)&&(l.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[u.graphQLPatchedSymbol]&&(e.resolve=(0,i.wrapFlow)(p,t,!0),e.resolve[u.graphQLPatchedSymbol]=!0)}(r);let n=r.type;for(;n.ofType;)n=n.ofType;f(n)}))}function p(e){if(void 0===e[2]||void 0===e[3])return void s.instrument_logger.warn("GraphQL resolver arguments are unknown");const t=e[3].path;if(t&&!t.prev){const r=t.key,n=(0,o.getResolverIdBySelectionName)(r);return e[2][u.graphQLPatchedSymbol]=n,n}if(e[2][u.graphQLPatchedSymbol])return e[2][u.graphQLPatchedSymbol];s.instrument_logger.warn("GraphQL No functionId found for resolver")}function g(e,t){try{new o.GraphQLDocumentMetadata(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})}}},7225:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.skipStackNamesLogs=t.skipLayerNamesLogs=t.isVerboseLoggingEnabled=t.uuidSymbol=void 0,t.logLazyRouter=function(e){const r=e.lazyrouter;e.lazyrouter=function(){let e=!1;try{this._router||(e=!0)}catch(e){a.instrument_logger.error("Failed to check this._router",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}const n=r.apply(this,arguments);try{if(e){let e=this[t.uuidSymbol];e||(e=c.randomUUID(),this[t.uuidSymbol]=e,a.instrument_logger.info("Express lazy router setting uuid",{uuid:e})),a.instrument_logger.info("Express lazy router",{parent:e,child:this._router?.[t.uuidSymbol]})}}catch(e){a.instrument_logger.error("Failed to patch express.lazyRouter function",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return n},(0,d.copyPropertiesToTarget)(r,e.lazyrouter)};const a=r(2546),c=i(r(6982)),u=r(932),d=r(8949);t.uuidSymbol=Symbol.for("__hud_uuid__"),t.isVerboseLoggingEnabled="true"===u.env.HUD_LOG_EXPRESS,t.skipLayerNamesLogs=new Set(["query","expressInit","mounted_app"]),t.skipStackNamesLogs=new Set(["router"])},7246:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2546),o=r(8949),s=r(714);class i extends s.FrameworkPatcher{static originalRequestSymbol=Symbol.for("hudOriginalRequest");static hudPatched=Symbol.for("hudPatched");_patch(e){try{if((0,n.setIsNextJsApp)(!0),!e.NextRequestAdapter)return n.instrument_logger.error("Could not find NextRequestAdapter in exports"),e;const t=e.NextRequestAdapter;if(t[i.hudPatched])return n.instrument_logger.debug("NextRequestAdapter already patched"),e;const r=t.fromNodeNextRequest;if(!r)return n.instrument_logger.error("Could not find NextRequestAdapter.fromNodeNextRequest"),e;t.fromNodeNextRequest=function(...e){const t=r.apply(this,e);try{t[i.originalRequestSymbol]=e[0]._req}catch(e){n.instrument_logger.error("Failed to patch NextRequestAdapter",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t},(0,o.copyPropertiesToTarget)(r,t.fromNodeNextRequest),t[i.hudPatched]=!0,n.instrument_logger.info("Successfully patched NextRequestAdapter.fromNodeNextRequest")}catch(e){n.instrument_logger.error("Failed to patch NextRequestAdapter",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return e}}t.default=i},7603:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getObservabilityIdentifiers=function(e){return{datadog_trace_id:i(e,"x-datadog-trace-id"),w3c_trace_context:o(e),w3c_baggage:i(e,"baggage"),amazon_trace_id:i(e,"x-amzn-trace-id"),b3_propagation:s(e),jaeger_trace_id:i(e,"uber-trace-id")}},t.getExtraHeaders=function(e){const t={};for(const r of n.hudConfig.dynamicConfig.extraHeaders){const n=i(e,r);void 0!==n&&(t[r]=n)}return t};const n=r(2546);function o(e){try{return{traceparent:i(e,"traceparent"),tracestate:i(e,"tracestate")}}catch{return}}function s(e){try{return{full:i(e,"b3"),trace_id:i(e,"x-b3-traceid"),span_id:i(e,"x-b3-spanid"),parent_span_id:i(e,"x-b3-parentspanid")}}catch{return}}function i(e,t){try{return e.headers[t]}catch{return}}},7707:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AsyncFunction=void 0,t.AsyncFunction=(async()=>{}).constructor},7808:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getMachineMetrics=function(){try{const e=(0,o.getLastMetrics)();return{cpu_usage:e.cpuUsage?d(e.cpuUsage,e.timestamp):void 0,memory_usage:u(),event_loop_utilization:e.elu?c(e.elu):void 0}}catch(e){return void s.app_logger.error("Error getting machine metrics",e)}},t.getCpuUsage=d;const o=r(8269),s=r(2546),i=n(r(857)),a=r(2987);function c(e){try{return a.performance.eventLoopUtilization(e).utilization}catch(e){return void s.app_logger.error("Error getting event loop utilization",e)}}function u(){try{const e=process.memoryUsage(),t=i.default.totalmem();return{rss:e.rss,heap_total:e.heapTotal,heap_used:e.heapUsed,external:e.external,system_memory:t,rss_percentage:e.rss/t*100}}catch(e){return void s.app_logger.error("Error getting memory usage",e)}}function d(e,t){try{const r=process.cpuUsage(),n=1e3*(Date.now()-t),o=(0,s.getCpuLimit)(s.app_logger),i=(r.user-e.user)/n,a=(r.system-e.system)/n;return{user_time:i,system_time:a,limit:o,user_percent_of_limit:"number"==typeof o?i/o*100:void 0,system_percent_of_limit:"number"==typeof o?a/o*100:void 0}}catch(e){return void s.app_logger.error("Error getting cpu usage",e)}}},8054:e=>{"use strict";e.exports=require("array-flatten")},8064:e=>{"use strict";e.exports=require("semver")},8184:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=r(8528),s=r(2030),i=r(2546),a=n(r(8938)),c=r(6858),u=r(9896),d=r(1943),l=n(r(2698)),f=n(r(6928)),p=r(9561),g=r(3903),h=n(r(3106)),m=r(1952);function _(e){const t=(0,i.formatLogMessage)(e.message,e.errCode,e.moreInfo);console.log(t)}const y=new class{messages=[];buildId=null;accessToken=null;client=null;setBuildId(e){this.buildId=e}setAccessToken(e){this.accessToken=e}setClient(e){this.client=e}log(e){this.messages.push({message:e,timestamp:(new Date).toISOString()})}async send(){try{if(!this.buildId)return void this.log("Build ID is not set");if(!this.accessToken)return void this.log("Access token is not set");if(!this.client)return void this.log("Client is not set");const e=this.messages.map(e=>({...e,buildId:this.buildId||""}));await this.client.sessionslessLogs(JSON.stringify(e),this.accessToken||"")}catch(e){}}};async function v(e,t,r){try{return await(0,d.writeFile)(e,t,r),!0}catch(e){return!1}}async function b(e,t){try{return await(0,d.rename)(e,t),!0}catch(e){return!1}}async function w(e){try{await(0,d.unlink)(e)}catch(e){}}async function k(e){const t=(0,l.default)(20);await Promise.all(e.map(e=>t(async()=>{await Promise.all([w(e.filePath+".hud"),w(e.filePath+".hud.map")])})))}async function S(e,t,r,n){const s=(await t.getUploadUrls(r,n,1))[0];y.log("Got upload URL");const c={...i.HudClient.defaultRequest,send_time:(new Date).toISOString(),build_id:r,token:n};let u=[];const d=e.map(e=>e.metadatas[0]);try{u=await(0,i.getFilesForDeclarations)(d,t.sendFileDeclarationsCi.bind(t,c))}catch(e){u=d}y.log(`Got ${u.length} files for declarations`);const f=await async function(e){const t=(0,l.default)(process.env.HUD_PARSE_DECLARATIONS_LIMIT?parseInt(process.env.HUD_PARSE_DECLARATIONS_LIMIT):20),r=h.default.createGzip();let n=0;return await Promise.all(e.map(e=>t(async()=>{try{const t=await(0,i.readFile)(e.filename,e.indexOffset,e.indexOffsetEnd);if(!t)return n++,{declarations:[],blacklist:void 0};(function(e){const t=(new Date).toISOString(),r=function(e){const t=[];for(let r=0;r<e.length;r+=100){const n=e.slice(r,r+100);t.push(n)}return t}(e);return r.map(e=>({...i.HudClient.defaultRequest,type:"FunctionDeclaration",arr:e,send_time:t,event_version:o.FUNCTION_DECLARATION_VERSION}))})((await(0,i.parseDeclarations)(e,t)).declarations).forEach(e=>{r.write(JSON.stringify(e)),r.write("\n")})}catch(e){return n++,{declarations:[],blacklist:void 0}}}))),r.end(),n>0&&y.log(`Failed to parse declarations for ${n} files`),r}(u);try{await async function(e,t,r,n,o){const s=await(0,p.buffer)(e);let i=t;for(let e=1;e<=3;e++)try{return await a.default.put(i,s,{headers:{"Content-Encoding":"gzip","Content-Type":"application/x-ndjson"}}),void y.log("Uploaded requests")}catch(t){if(!(a.default.isAxiosError(t)&&405===t.response?.status&&e<3))throw t;y.log(`Upload failed with 405 status, retrying attempt ${e+1}/3, current upload url: ${i}`),i=(await r.getUploadUrls(n,o,1))[0]}}(f,s,t,r,n),y.log("Upload completed")}catch(e){const t={msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0};y.log(`Failed to upload requests, still instrumenting files, error: ${JSON.stringify(t)}`),_(i.UserErrorLogs.HudCliUploadFailed())}}function E(e){const t=f.default.resolve(e);if(!(0,u.existsSync)(t))throw new Error(`Directory does not exist: ${e}`);return t}(async function(){const e=new c.Command;e.requiredOption("--api-key <string>","Your Hud API key").requiredOption("--dirs <list>","Comma-separated directories to scan").option("--include-modules <list>","Comma-separated module names to trace").option("--node-modules-path <string>","Path to node_modules").option("--max-mapped-functions <number>","Max number of mapped functions").option("--exclude-dirs <list>","Comma-separated directories to exclude").parse(process.argv);const t=e.opts(),r={apiKey:t.apiKey,modulesToTrace:t.includeModules?t.includeModules.split(",").map(e=>e.trim()):[],dirs:t.dirs.split(",").map(e=>e.trim()),nodeModulesPath:t.nodeModulesPath,maxMappedFunctions:t.maxMappedFunctions,excludeDirs:t.excludeDirs?t.excludeDirs.split(",").map(e=>e.trim()):void 0},n=(0,g.v4)();y.setBuildId(n),y.setAccessToken(t.apiKey);const a=new i.HudClient;if(y.setClient(a),!await a.validateToken(t.apiKey))return _(i.UserErrorLogs.HudCliInvalidKey()),void await y.send();let d,p;r.maxMappedFunctions&&(i.hudConfig.userConfig.maxMappedFunctions={value:r.maxMappedFunctions,source:"SETUP"});try{({dirs:d,nodeModulesPath:p}=function(e){const t=[];let r;for(const r of e.dirs)try{t.push(E(r))}catch(e){throw _(i.UserErrorLogs.HudCliInvalidDirectory(r)),e}if(e.nodeModulesPath)try{r=E(e.nodeModulesPath)}catch(t){throw _(i.UserErrorLogs.HudCliInvalidDirectory(e.nodeModulesPath)),t}return{dirs:t,nodeModulesPath:r}}(r))}catch(e){return void await y.send()}const h=(0,s.createCheckers)(r.modulesToTrace),x=await(0,m.getFiles)(d,h,p,r.excludeDirs);if(0===x.length)return y.log("No .js files to instrument"),_(i.UserErrorLogs.HudCliNoJsFiles()),void await y.send();y.log(`Found ${x.length} files`);const M=await async function(e,t){const r=(0,l.default)(20);return await Promise.all(e.map(e=>r(async()=>async function(e,t){try{if(globalThis.hudRunningMode===o.HudRunningMode.detached)return{status:"skipped"};const r=f.default.join(e.parentPath,e.name),n=(0,u.readFileSync)(r,"utf-8");if((0,s.parseCliInstrumentationPattern)(n))return{status:"skipped"};const{transformedCode:a,metadatas:c}=(0,s.editWithCliBuildId)(n,r,o.Format.cjs,t);return c[0].detectedForAwaitLoops>0&&y.log(`Detected for-await loops in file ${r}, detectedForAwaitLoops: ${c[0].detectedForAwaitLoops}`),await async function(e,t,r){const n=(0,i.combineSourceMaps)(t,r);return!(!n||!await v(r+".hud",e)||!await v(r+".hud.map",n,"utf-8")&&(await w(r+".hud"),1))}(a,c,r)?{status:"success",metadatas:c.map(e=>(0,i.sourceFileMetadataToTransferSourceFileMetadata)(e)),filePath:r}:{status:"failed"}}catch(e){return{status:"failed"}}}(e,t))))}(x,n);if(globalThis.hudRunningMode===o.HudRunningMode.detached)return y.log("Detached mode, skipping filterEditedFiles"),_(i.UserErrorLogs.HudCliInstrumentedFunctionCountExceeded(i.hudConfig.userConfig.maxMappedFunctions?.value??0)),await k(M.filter(e=>"success"===e.status).map(e=>({filePath:e.filePath}))),void await y.send();const C=await async function(e){const t=e.filter(e=>void 0===e||"failed"===e.status);t.length>0&&y.log(`Failed to edit ${t.length} files out of ${e.length}`);const r=e.filter(e=>"skipped"===e.status);if(r.length>0){if(r.length===e.length)return _(i.UserErrorLogs.HudCliAllFilesInstrumented()),y.log("No files instrumented."),void await y.send();_(i.UserErrorLogs.HudCliSomeFilesInstrumented()),y.log(`Skipped ${r.length} files out of ${e.length}`)}const n=e.filter(e=>"success"===e.status);return n.length>0&&y.log(`Edited ${n.length} files`),n}(M);if(C&&0!==C.length)try{y.log(`Parsing declarations for ${C.length} files`),await S(C,a,n,r.apiKey),await async function(e){const t=(0,l.default)(20);await Promise.all(e.map(e=>t(async()=>{await b(e.filePath+".hud",e.filePath)?await b(e.filePath+".hud.map",e.filePath+".map"):(await w(e.filePath+".hud"),await w(e.filePath+".hud.map"))})))}(C),y.log("Files written to disk"),await y.send(),y.log("Done."),_(i.UserLogs.HudCliCompletedSuccessfully(C.length))}catch(e){throw y.log("Failed to instrument files, deleting files"),await k(C),await y.send(),e}})().catch(async e=>{try{_(i.UserErrorLogs.HudCliUnkownError()),y.log("Failure"),y.log(e.message),await y.send()}catch(e){}})},8269:e=>{"use strict";e.exports=require("./globalstate")},8528:e=>{"use strict";e.exports=require("./dto")},8611:e=>{"use strict";e.exports=require("http")},8901:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HttpEndpointMetric=void 0;const n=r(9873);class o extends n.FlowMetric{statusCode;route;method;constructor(e){super(e)}_createUsableMetric(e){return this}setRequestAttributes(e){const t=e.url||e.path;this.route=t?.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=o},8938:e=>{"use strict";e.exports=require("axios")},8949:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.wrapFlow=function(e,t,r=!0,c,u,d){let l;return t[i]?t:(t[i]=!0,l=t instanceof s.AsyncFunction?async function(...s){let i;try{i=e(s)}catch(e){o.instrument_logger.error("Failed to get flowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}if(!i||hudRunningMode!==n.HudRunningMode.enabled)return await t.apply(this,s);_hud_F=i,hudShouldLinkFunction=r;const a={};if(c)try{c(i,a,s)}catch(e){o.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,s);_hud_F="";const r=await e;if(u)try{u(i,a)}catch(e){o.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(d)try{d(i,a,e)}catch(e){o.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{_hud_F="",hudShouldLinkFunction=!1}}:function(...s){let i;try{i=e(s)}catch(e){o.instrument_logger.error("Failed to get flowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}if(!i||hudRunningMode!==n.HudRunningMode.enabled)return t.apply(this,s);_hud_F=i,hudShouldLinkFunction=r;const a={};if(c)try{c(i,a,s)}catch(e){o.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,s);if(u)if(e instanceof Promise)e.then(()=>{try{u(i,a)}catch(e){o.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{u(i,a)}catch(e){o.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(d)try{d(i,a,e)}catch(e){o.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{_hud_F="",hudShouldLinkFunction=!1}},a(t,l),l)},t.copyPropertiesToTarget=a;const n=r(8528),o=r(2546),s=r(7707),i=Symbol.for("hudMarked");function a(e,t){const r=Object.getOwnPropertyDescriptors(e),n=Reflect.ownKeys(r);Object.setPrototypeOf(t,e),n.forEach(e=>{try{Object.defineProperty(t,e,r[e])}catch(e){}})}},9063:e=>{"use strict";e.exports=require("require-in-the-middle")},9561:e=>{"use strict";e.exports=require("stream/consumers")},9589:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=r(8528),s=r(8269),i=r(2546),a=r(8949),c=r(714),u=r(5459),d=n(r(7246));class l extends c.FrameworkPatcher{static nextJSHudMarked=Symbol.for("hudNextJSMarked");static routeInfoSymbol=Symbol.for("hudNextJSRouteInfo");static standardMethods=["GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"];_patch(e){return(0,i.setIsNextJsApp)(!0),this._patchBaseServer(e),i.instrument_logger.info("Patched Next.js successfully"),e}_patchBaseServer(e){try{const t=e.default;if(t[l.nextJSHudMarked])return e;const r=t.prototype.renderToResponseWithComponentsImpl;if(!r)return i.instrument_logger.error("Could not find renderToResponseWithComponentsImpl on BaseServer.prototype"),e;t.prototype.renderToResponseWithComponentsImpl=async function(e,t,...n){try{const r=t.components;if(r&&r.routeModule&&!r.routeModule[l.nextJSHudMarked]){const t=r.routeModule,n=t.definition?.pathname||e.pathname;l._detectAndPatchSupportedMethods(t,n),t[l.nextJSHudMarked]=!0}}catch(e){i.instrument_logger.error("Failed to patch Next.js route module",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return await r.apply(this,[e,t,...n])},t[l.nextJSHudMarked]=!0,(0,a.copyPropertiesToTarget)(r,t.prototype.renderToResponseWithComponentsImpl)}catch(e){i.instrument_logger.error("Failed to patch Next.js base server",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return e}static _detectAndPatchSupportedMethods(e,t){try{switch(i.instrument_logger.debug("Patching Next.js route module",{pathname:t,kind:e.definition?.kind||"unknown"}),e.definition.kind){case"APP_ROUTE":case"PAGES_API":l._patchApiModule(e,t);break;case"PAGES":case"APP_PAGE":l._patchPageModule(e,t);break;default:i.instrument_logger.warn("Unknown Next.js route module kind",{pathname:t,kind:e.definition?.kind||"unknown"})}}catch(e){i.instrument_logger.error("Error detecting and patching supported methods",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}static _patchApiModule(e,t){if(e.methods)for(const r of l.standardMethods)if("function"==typeof e.methods[r]&&"function"==typeof e.userland?.[r]){const n=(0,i.generateEndpointFlowId)(t,[r]);(0,s.storeEndpointDeclaration)(new o.EndpointDeclaration(n,[r],"nextjs","",t));try{const t=e.methods[r];e.methods[r]=(0,a.wrapFlow)(()=>n,t,!0,(e,t,r)=>{g(r[0],e)})}catch(e){i.instrument_logger.error("Failed to patch Next.js App Route method",{method:r,pathname:t,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}if(e.userland?.default){const r=l.standardMethods.filter(t=>!e.methods?.[t]),n=(0,i.generateEndpointFlowId)(t,r);(0,s.storeEndpointDeclaration)(new o.EndpointDeclaration(n,r,"nextjs","",t));const c=e.userland.default;e.userland={...e.userland,default:(0,a.wrapFlow)(()=>n,c,!0)}}}static _patchPageModule(e,t){const r=(0,i.generateEndpointFlowId)(t,["GET"]);if((0,s.storeEndpointDeclaration)(new o.EndpointDeclaration(r,["GET"],"nextjs","",t)),e.render&&"function"==typeof e.render&&!e.render[this.nextJSHudMarked])try{const t=e.render;e.render=function(...e){try{g(e[0],r)}catch(e){}return t.apply(this,e)},(0,a.copyPropertiesToTarget)(t,e.render),e.render[this.nextJSHudMarked]=!0}catch(e){i.instrument_logger.error("Failed to patch Next.js Page render method",{pathname:t,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}if(e.userland?.loaderTree)try{p(e.userland.loaderTree,r)}catch(e){i.instrument_logger.error("Failed to patch App Router page component",{pathname:t,msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}else i.instrument_logger.warn("No loader tree found on Next.js page component",{pathname:t})}}function f(e,t,r){return(...n)=>{const o=e(...n),s=e=>{if(e&&"function"==typeof e.default&&!e.default[l.nextJSHudMarked]){const n=(0,a.wrapFlow)(()=>r,e.default,t);(e={...e,default:n})[l.nextJSHudMarked]=!0}return e};return o&&"function"==typeof o.then?o.then(s):s(o)}}function p(e,t){const[,r,n]=e;for(const e of Object.keys(n))try{const r=n[e];if(Array.isArray(r)&&"function"==typeof r[0]){const n="page"===e,o=r[0];r[0]=f(o,n,t),(0,a.copyPropertiesToTarget)(o,r[0])}}catch(e){i.instrument_logger.error("Failed to iterate on Next.js components",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}for(const e of Object.values(r))try{p(e,t)}catch(e){i.instrument_logger.error("Failed to walk on Next.js parallel routes",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}function g(e,t){try{let r;if(e&&d.default.originalRequestSymbol in e){const t=e[d.default.originalRequestSymbol];r=(0,u.getHttpMetricFromRequest)(t)}else e&&e.originalRequest&&(r=(0,u.getHttpMetricFromRequest)(e.originalRequest));if(r||(r=(0,u.getHttpMetricFromRequest)(e)),!r)return void i.instrument_logger.error("No endpoint metric found on Next.js request or its original request");r.setFlowId(t)}catch(e){i.instrument_logger.error("Failed to link metric to flow",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}t.default=l},9723:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=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||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0});const a=r(8269),c=r(2546),u=r(9896),d=i(r(6928)),l=r(8949),f=r(714);class p extends f.FrameworkPatcher{_patch(e){(0,c.setIsNextJsApp)(!0);const t=this._patchLoadConfig(e);return c.instrument_logger.info("Patched next.js config successfully"),t}_patchLoadConfig(e){const t=e.default,r=async function(...e){const r=await t.call(this,...e);if(!r)return r;try{const t=e[1],n=d.join(t,r.distDir||".next"),o=d.join(n,a.apiManifest),s=d.join(n,a.pageManifest),i=await u.promises.access(o).then(()=>!0).catch(()=>!1),l=await u.promises.access(s).then(()=>!0).catch(()=>!1);(0,a.isNextConfigExtracted)()||!i&&!l||(c.instrument_logger.info("Extracted next.js config successfully"),(0,a.setNextConfig)(r))}catch(e){c.instrument_logger.error("Failed to patch next.js loadConfig",{msg:e instanceof Error?e.message:String(e),stack:e instanceof Error?e.stack:void 0})}return r};(0,l.copyPropertiesToTarget)(t,r);const n=Object.create(Object.getPrototypeOf(e));return Object.defineProperty(n,"default",{enumerable:!0,get:function(){return r}}),(0,l.copyPropertiesToTarget)(e,n),n}}t.default=p},9873:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.FlowMetric=void 0;const o=r(8528),s=r(8269),i=n(r(932));t.FlowMetric=class{_state;flowId;duration;_startTime;_msStartTime;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}getMsStartTime(){return this._msStartTime}start(){this._startTime=i.default.hrtime.bigint(),this._msStartTime=Date.now()}end(){this._startTime&&(this.duration=Number(i.default.hrtime.bigint()-this._startTime)),this.#e(),this._state="unusable"}#e(){if(hudRunningMode===o.HudRunningMode.enabled){const e=this.toRaw();e&&(0,s.storeFlowMetric)(e)}}}},9896:e=>{"use strict";e.exports=require("fs")}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,r),s.exports}return r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r(8184)})());
3
3
  //# sourceMappingURL=cli.js.map
@@ -1,2 +1,2 @@
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,()=>(()=>{"use strict";var e={857:e=>{e.exports=require("os")},870:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.limitedParallel=async function(e,t,r,o=!1){const n=[],i=[];return await Promise.all(Array.from({length:t},async function(){for(;e.length>0;){const t=e.shift();try{const e=await r(t);n.push(e)}catch(e){if(i.push(e),o)throw e}}})),{results:n,errors:i}}},2030:e=>{e.exports=require("./instrument")},2305:e=>{e.exports=require("form-data")},2546:e=>{e.exports=require("./lib")},2784:e=>{e.exports=require("../native/_index")},3066:function(e,t,r){var o,n=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]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||(o=function(e){return o=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},o(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=o(e),a=0;a<r.length;a++)"default"!==r[a]&&n(t,e,r[a]);return i(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.requestRelentless=async function(e,t,r,o=3){for(let n=0;n<o;n++)try{return await u.default.post(e,t,r)}catch(t){if(t instanceof u.AxiosError&&401===t.response?.status)throw new s.HudClientUnauthorizedError(`Unauthorized request for ${e}`);(0,l.logToHud)(`Failed request to ${e}, attempt ${n+1} of ${o}. Error: ${t}`),await new Promise(e=>setTimeout(e,1))}throw new s.HudClientExceededMaxRetries(`Exceeded max retries for ${e}`)};const s=r(2546),u=a(r(8938)),l=r(5231)},3903:e=>{e.exports=require("uuid")},4414:function(e,t,r){var o,n=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]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||(o=function(e){return o=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},o(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=o(e),a=0;a<r.length;a++)"default"!==r[a]&&n(t,e,r[a]);return i(t,e),t}),s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.uploadSourceMap=g,t.uploadAllSourceMaps=async function(e,t){if(process.env.HUD_SKIP_SOURCEMAP_UPLOAD)(0,c.logToHud)("Skipping source map upload due to env var");else{(0,c.logToHud)(`Uploading source maps for ${e.length} files`);try{const r=[];for(const{buildId:o,filepath:n}of e){const e=`${n}.map`;try{await d.promises.access(e,d.constants.F_OK),r.push({buildId:o,filePath:e,hudKey:t})}catch{(0,c.logToHud)(`No source map found for file: ${n}`)}}await(0,f.limitedParallel)(r,10,g,!0),(0,c.logToHud)("Finished uploading source maps")}catch{return(0,c.logToUser)(u.UserErrorLogs.EsbuildFailedUploadingSourcemapUnauthorized()),void(0,c.setDontSendLogs)()}}};const u=r(2546),l=s(r(2305)),d=a(r(9896)),c=r(5231),f=r(870),p=r(3066);async function g(e){const{buildId:t,filePath:r,hudKey:o}=e,n=new l.default;n.append("build_id",t),n.append("token",o);try{const e=await d.promises.readFile(r,"utf8"),t=JSON.parse(e);delete t.sourcesContent,n.append("sourcemap",JSON.stringify(t),{filename:"sourcemap",contentType:"application/json"})}catch(e){return(0,c.logToHud)(`failed parsing source map, skipping upload. Error: ${e}`),void(0,c.logToUser)(u.UserErrorLogs.EsbuildFailedParsingSourcemap())}try{await(0,p.requestRelentless)(`${u.hudConfig.sink.url}/${u.hudConfig.endpoints.sourceMap}`,n,{headers:{"Content-Type":"multipart/form-data"},timeout:u.hudConfig.esbuildUploadSourceMapTimeout})}catch(e){if(e instanceof Error&&e.message.includes("Unauthorized"))throw e;(0,c.logToHud)(`failed uploading source map. File: ${r}, Error: ${e}`),(0,c.logToUser)(u.UserErrorLogs.EsbuildFailedUploadingSourcemap(r))}}},5231:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.logToUser=function(e){let t="";t="string"==typeof e?(0,o.formatLogMessage)(`${s}${e}`):(0,o.formatLogMessage)(`${s}${e.message}`,e.errCode,e.moreInfo),console.log(t),c(t,!1)},t.logToHudDebug=function(e,t=!0){"true"===process.env.HUD_PLUGIN_DEBUG&&c(e,t)},t.logToHud=c,t.exportBuildLogs=async function(e){const t=[];for(let r=0;r<l.length;r+=o.hudConfig.esbuildPluginLogsBatchSize){const n=l.slice(r,r+o.hudConfig.esbuildPluginLogsBatchSize).map(t=>({...t,accessToken:e}));t.push(n)}await(0,i.limitedParallel)(t,10,f)},t.setDontSendLogs=function(){d=!1},t.getShouldSendLogs=function(){return d};const o=r(2546),n=r(6982),i=r(870),a=r(3066),s=o.hudConfig.esbuildPluginMessagePrefix,u=(0,n.randomUUID)(),l=[];let d=!0;function c(e,t=!0){"true"===process.env.HUD_PLUGIN_VERBOSE&&(t&&(e=(0,o.formatLogMessage)(`${s}${e}`)),console.log(e)),l.push({message:e,SessionID:u,timestamp:Date.now()})}async function f(e){await(0,a.requestRelentless)(o.hudConfig.pluginsLogEndpoint,{messages:e},{headers:{"x-hudx-plugin":"true","Content-Type":"application/json"}})}},6928:e=>{e.exports=require("path")},6932:function(e,t,r){var o,n=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]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||(o=function(e){return o=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},o(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=o(e),a=0;a<r.length;a++)"default"!==r[a]&&n(t,e,r[a]);return i(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.HudBuildError=void 0,t.verifyAndMarkFinalFiles=async function(e,t,r){const o=[];for(const n of e){if(!n.path.endsWith(".js")){t&&await(0,f.writeFileAndFolder)(n.path,n.contents);continue}if(!n.text.includes(u.hudConfig.esbuildGlobalVar)){t&&await(0,f.writeFileAndFolder)(n.path,n.contents);continue}const e=(0,d.v5)(n.contents,u.hudConfig.bundlerBuildUuidNamespace);o.push({filepath:n.path,buildId:e});const i=h(n.text,e);process.env.HUD_SKIP_FILE_VALIDATION||b(i,n.path,r),n.contents=new Uint8Array(Buffer.from(i,"utf8")),t&&await(0,f.writeFileAndFolder)(n.path,n.contents)}return o},t.markFileAsHudModified=h,t.markFile=function(e,t){const r=l.markFile(t,{data:{filename:e,format:"esm"},initialStatements:[m(e,!0)],suffixStatements:[m(e,!1)]});if(!r||!r.code||!r.map)throw new Error("Failed generating ast");return(0,u.appendInlineSourceMap)(r.code,r.map)},t.createMark=m,t.verifyFileContent=b;const s=r(2030),u=r(2546),l=a(r(2784)),d=r(3903),c=a(r(9154)),f=r(7085),p=r(5231);class g extends Error{}function h(e,t){return`/*modifiedByHudESBuildPlugin-${t}*/${e}`}function m(e,t){const r=t?"Start":"End";return e=t?e:"",`;globalThis && (globalThis.${u.hudConfig.esbuildGlobalVar}="${r}:${e}");`}function b(e,t,r){try{(0,p.logToHud)(`Verifying file content: ${t}, with marks`),new c.Script(e),(0,p.logToHud)(`Editing in splits file content: ${t}`);const{transformedCode:o,editedChunksSizes:n}=(0,s.editInSplits)(e,t,r,!0,!0,e=>!e.includes("node_modules"));if(!o)throw new g(`Failed verify file content, ${t}`);for(let e=0;e<n.length;e+=f.LOG_CHUNKS_SIZE_BATCH){const t=JSON.stringify(n.slice(e,e+f.LOG_CHUNKS_SIZE_BATCH));(0,p.logToHudDebug)(`Edited chunks sizes: ${t}`)}(0,p.logToHud)(`Verifying new file content: ${t}`),new c.Script(o),(0,p.logToHud)(`Verified new file content: ${t}`),(0,p.logToHud)(`${t}: Original code size: ${e.length}, new code size: ${o.length}`)}catch(e){throw(0,p.logToHud)(`Failed verify file content, ${t}, error: ${e}`),new g(`Failed verify file content, ${t}`)}}t.HudBuildError=g},6982:e=>{e.exports=require("crypto")},7085:function(e,t,r){var o,n=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]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||(o=function(e){return o=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},o(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=o(e),a=0;a<r.length;a++)"default"!==r[a]&&n(t,e,r[a]);return i(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.plugin=t.LOG_CHUNKS_SIZE_BATCH=void 0,t.writeFileAndFolder=async function(e,t){const r=f.dirname(e);try{await d.promises.stat(r)}catch{await d.promises.mkdir(r,{recursive:!0})}await d.promises.writeFile(e,t)},t.getModuleRoot=v;const s=r(8528),u=r(2030),l=r(6982),d=a(r(9896)),c=a(r(857)),f=a(r(6928)),p=r(2546),g=r(9929),h=r(5231),m=r(6932),b=r(4414),y=30;async function w(e,t,r,o,n){if(!(r&&o&&n&&o.test(e)))return;const i=f.join(n,e),a=f.dirname(i);try{await d.promises.access(a)}catch{await d.promises.mkdir(a,{recursive:!0})}await d.promises.writeFile(i,t,"utf8");const s=await r(i);return s?.contents&&(t=s.contents),t}async function v(e){let t=f.dirname(e);for(let e=0;e<y&&"/"!==t;e++){const e=f.join(t,"package.json");try{return await d.promises.access(e),t}catch{t=f.dirname(t)}}}t.LOG_CHUNKS_SIZE_BATCH=p.hudConfig.esbuildPluginLogsChunkSize;const _="hud-esbuild-plugin";t.plugin=e=>({name:_,async setup(t){if("inline"===t.initialOptions.sourcemap||"both"===t.initialOptions.sourcemap)return void(0,h.logToUser)(p.UserErrorLogs.EsbuildSourceMapInline());if("node"!==t.initialOptions.platform)return void(0,h.logToUser)(p.UserErrorLogs.EsbuildUnsupportedPlatform());if("win32"===c.platform())return void(0,h.logToUser)(p.UserErrorLogs.EsbuildUnsupportedWindows());const r=e?.hudKey??process.env.HUD_KEY;if(!r)return void(0,h.logToUser)(p.UserErrorLogs.EsbuildMissingKey());const o=e?.includeModules??(0,p.getModulesToTraceFromEnv)()??[],n=(0,u.createCheckers)(o);(0,h.logToUser)("started running");const i=t.initialOptions.write??!0;t.initialOptions.write=!1;const a="esm"===t.initialOptions?.format?s.Format.esm:s.Format.cjs,{callback:y,filter:O,tempDir:T}=await async function(e){const t=e.initialOptions;if(!t.plugins)return;const r=t.plugins.findIndex(e=>e.name===_),o=t.plugins[r+1];if(!o||"datadog-esbuild"!==o.name)return;let n;(0,h.logToHud)("datadog-esbuild plugin detected");const i={...e,onLoad:(...e)=>{n=e},onStart:()=>{},onEnd:()=>{},onResolve:()=>{},onDispose:()=>{}};if(o.setup(i),!n)return void(0,h.logToHud)("datadog-esbuild plugin detected but failed receive onLoad callback");const a=f.join(c.tmpdir(),`hud-${(0,l.randomUUID)()}`);try{return await d.promises.access(a),void(0,h.logToUser)("temp dir already exists, try rerunning the build.")}catch(e){}return(0,h.logToHud)(`creating temp dir to be used by datadog plugin.\n\tPath: ${a}`),await d.promises.mkdir(a,{recursive:!0}),{filter:n[0].filter,callback:n[1],tempDir:a}}(t)??{},S=new Set(t.initialOptions.external||[]),$=new Map;t.onResolve({filter:/.*/},async e=>{if(e.pluginData?.hud?.calledFromHud)return;if(S.has(e.path))return;if(!p.hudConfig.frameworksToPatch.get(e.path)?.enableEsbuild)return;const r={...e};delete r.path;const o=await t.resolve(e.path,{...r,pluginData:{...e.pluginData,hud:{calledFromHud:!0}}}),n=await v(o.path);n&&($.set(n,e.path),(0,h.logToHud)(`mapping framework: ${n} => ${e.path}`))}),t.onLoad({filter:/.*\.(js|ts)$/},async e=>{try{const t=y?async t=>await y({...e,path:t}):void 0;if((0,u.skip)(e.path,n)){const r=await(0,g.getFrameworkContentSuffix)(e.path,$);if(!r)return;let o=await d.promises.readFile(e.path,"utf8");return o=await w(e.path,o,t,O,T)??o,o+=r,{contents:o,loader:e.path.endsWith("ts")?"ts":"js",resolveDir:f.dirname(e.path)}}let r=await d.promises.readFile(e.path,"utf8");return r=(0,m.markFile)(e.path,r),r=await w(e.path,r,t,O,T)??r,r+=await(0,g.getFrameworkContentSuffix)(e.path,$)??"",{contents:r,loader:e.path.endsWith("ts")?"ts":"js",resolveDir:f.dirname(e.path)}}catch(t){return(0,h.logToHud)(`failed patching file "${e.path}", fallbacking to original loader. Error: ${t}`),void(0,h.logToUser)(`failed patching file "${e.path}", fallbacking to original loader`)}}),t.onEnd(async e=>{if(!e?.outputFiles)return;let t;try{t=await(0,m.verifyAndMarkFinalFiles)(e.outputFiles,i,a),(0,h.logToUser)("finished")}catch(e){throw(0,h.logToHud)(`failed validating. Error: ${e}`),(0,h.logToUser)(p.UserErrorLogs.EsbuildFailedBundling()),e}finally{if(t)try{await(0,b.uploadAllSourceMaps)(t,r)}catch(e){(0,h.logToHud)(`failed uploading source maps. Shouldnt get here since we catch all errors in verifyAndMarkFinalFiles, error: ${e}`)}try{if(T)try{await d.promises.access(T),(0,h.logToHud)("cleaning temp dir"),await d.promises.rm(T,{recursive:!0,force:!0})}catch{}}catch(e){(0,h.logToHud)(`failed cleaning temp dir. Error: ${e}`)}try{!process.env.HUD_SKIP_BUILD_LOG_EXPORT&&(0,h.getShouldSendLogs)()&&await(0,h.exportBuildLogs)(r)}catch(e){"true"===process.env.HUD_PLUGIN_VERBOSE&&"true"===process.env.HUD_DEBUG&&(0,h.logToUser)(`Failed exporting build logs. Error: ${e}`)}}})}})},8528:e=>{e.exports=require("./dto")},8938:e=>{e.exports=require("axios")},9154:e=>{e.exports=require("vm")},9896:e=>{e.exports=require("fs")},9929:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getFrameworkContentSuffix=async function(e,t){const r=[...t.entries()].find(([t,r])=>e.startsWith(t));if(!r)return;const[u,l]=r;let d=l+e.slice(u.length);(d.endsWith("index.js")||d.endsWith("index.ts"))&&(d=d.slice(0,d.length-9));const c=i.hudConfig.frameworksToPatch.get(d);if(!(c?.enableEsbuild&&c?.patcher&&c?.version))return;(0,s.logToHud)(`Patching framwork: ${d}`);const f=await(0,a.getModuleRoot)(e);if(!f)return void(0,s.logToHud)(`Failed to find package.json for ${d}`);const p=(0,n.extractModuleVersion)(f);if((0,s.logToHud)(`Patching framework ${d}, version: ${p}`),(0,n.getFrameworkPatcher)(c.patcher).isSupported(f,d,c.version,c.extraInfo))return`\n ;\n try {\n const { hudRITM, infoSafeLog: hudSafeLogger } = require("hud-sdk/instrument");\n if (globalThis.hudRunningMode === ${o.HudRunningMode.enabled}) {\n if (typeof hudRITM === "function") {\n if (typeof hudSafeLogger === "function") {\n hudSafeLogger("esbuild patching ${d}");\n }\n module.exports = hudRITM(module.exports, "${d}", "hud-esbuild-folder-should-not-exists");\n }\n }\n } catch (e) {\n try {\n const { errorSafeLog: hudSafeLogger } = require("hud-sdk/internal");\n if (typeof hudSafeLogger === "function") {\n hudSafeLogger(\`esbuild patching ${f} failed: \${e}\`);\n }\n } catch {}\n }\n `;(0,s.logToHud)(`Failed to patch ${d}, unsupported version: ${p}`)};const o=r(8528),n=r(2030),i=r(2546),a=r(7085),s=r(5231)}},t={};return 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}(7085)})());
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,()=>(()=>{"use strict";var e={857:e=>{e.exports=require("os")},870:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.limitedParallel=async function(e,t,r,o=!1){const n=[],i=[];return await Promise.all(Array.from({length:t},async function(){for(;e.length>0;){const t=e.shift();try{const e=await r(t);n.push(e)}catch(e){if(i.push(e),o)throw e}}})),{results:n,errors:i}}},2030:e=>{e.exports=require("./instrument")},2305:e=>{e.exports=require("form-data")},2546:e=>{e.exports=require("./lib")},2784:e=>{e.exports=require("../native/_index")},3066:function(e,t,r){var o,n=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]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||(o=function(e){return o=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},o(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=o(e),a=0;a<r.length;a++)"default"!==r[a]&&n(t,e,r[a]);return i(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.requestRelentless=async function(e,t,r,o=3){for(let n=0;n<o;n++)try{return await u.default.post(e,t,r)}catch(t){if(t instanceof u.AxiosError&&401===t.response?.status)throw new s.HudClientUnauthorizedError(`Unauthorized request for ${e}`);(0,l.logToHud)(`Failed request to ${e}, attempt ${n+1} of ${o}. Error: ${t}`),await new Promise(e=>setTimeout(e,1))}throw new s.HudClientExceededMaxRetries(`Exceeded max retries for ${e}`)};const s=r(2546),u=a(r(8938)),l=r(5231)},3903:e=>{e.exports=require("uuid")},4414:function(e,t,r){var o,n=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]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||(o=function(e){return o=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},o(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=o(e),a=0;a<r.length;a++)"default"!==r[a]&&n(t,e,r[a]);return i(t,e),t}),s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.uploadSourceMap=g,t.uploadAllSourceMaps=async function(e,t){if(process.env.HUD_SKIP_SOURCEMAP_UPLOAD)(0,c.logToHud)("Skipping source map upload due to env var");else{(0,c.logToHud)(`Uploading source maps for ${e.length} files`);try{const r=[];for(const{buildId:o,filepath:n}of e){const e=`${n}.map`;try{await d.promises.access(e,d.constants.F_OK),r.push({buildId:o,filePath:e,hudKey:t})}catch{(0,c.logToHud)(`No source map found for file: ${n}`)}}await(0,f.limitedParallel)(r,10,g,!0),(0,c.logToHud)("Finished uploading source maps")}catch{return(0,c.logToUser)(u.UserErrorLogs.EsbuildFailedUploadingSourcemapUnauthorized()),void(0,c.setDontSendLogs)()}}};const u=r(2546),l=s(r(2305)),d=a(r(9896)),c=r(5231),f=r(870),p=r(3066);async function g(e){const{buildId:t,filePath:r,hudKey:o}=e,n=new l.default;n.append("build_id",t),n.append("token",o);try{const e=await d.promises.readFile(r,"utf8"),t=JSON.parse(e);delete t.sourcesContent,n.append("sourcemap",JSON.stringify(t),{filename:"sourcemap",contentType:"application/json"})}catch(e){return(0,c.logToHud)(`failed parsing source map, skipping upload. Error: ${e}`),void(0,c.logToUser)(u.UserErrorLogs.EsbuildFailedParsingSourcemap())}try{await(0,p.requestRelentless)(`${u.hudConfig.sink.url}/${u.hudConfig.endpoints.sourceMap}`,n,{headers:{"Content-Type":"multipart/form-data"},timeout:u.hudConfig.esbuildUploadSourceMapTimeout})}catch(e){if(e instanceof Error&&e.message.includes("Unauthorized"))throw e;(0,c.logToHud)(`failed uploading source map. File: ${r}, Error: ${e}`),(0,c.logToUser)(u.UserErrorLogs.EsbuildFailedUploadingSourcemap(r))}}},5231:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.logToUser=function(e){let t="";t="string"==typeof e?(0,o.formatLogMessage)(`${s}${e}`):(0,o.formatLogMessage)(`${s}${e.message}`,e.errCode,e.moreInfo),console.log(t),c(t,!1)},t.logToHudDebug=function(e,t=!0){"true"===process.env.HUD_PLUGIN_DEBUG&&c(e,t)},t.logToHud=c,t.exportBuildLogs=async function(e){const t=[];for(let r=0;r<l.length;r+=o.hudConfig.esbuildPluginLogsBatchSize){const n=l.slice(r,r+o.hudConfig.esbuildPluginLogsBatchSize).map(t=>({...t,accessToken:e}));t.push(n)}await(0,i.limitedParallel)(t,10,f)},t.setDontSendLogs=function(){d=!1},t.getShouldSendLogs=function(){return d};const o=r(2546),n=r(6982),i=r(870),a=r(3066),s=o.hudConfig.esbuildPluginMessagePrefix,u=(0,n.randomUUID)(),l=[];let d=!0;function c(e,t=!0){"true"===process.env.HUD_PLUGIN_VERBOSE&&(t&&(e=(0,o.formatLogMessage)(`${s}${e}`)),console.log(e)),l.push({message:e,SessionID:u,timestamp:Date.now()})}async function f(e){await(0,a.requestRelentless)(o.hudConfig.pluginsLogEndpoint,{messages:e},{headers:{"x-hudx-plugin":"true","Content-Type":"application/json"}})}},6928:e=>{e.exports=require("path")},6932:function(e,t,r){var o,n=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]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||(o=function(e){return o=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},o(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=o(e),a=0;a<r.length;a++)"default"!==r[a]&&n(t,e,r[a]);return i(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.HudBuildError=void 0,t.verifyAndMarkFinalFiles=async function(e,t,r){const o=[];for(const n of e){if(!n.path.endsWith(".js")){t&&await(0,f.writeFileAndFolder)(n.path,n.contents);continue}if(!n.text.includes(u.hudConfig.esbuildGlobalVar)){t&&await(0,f.writeFileAndFolder)(n.path,n.contents);continue}const e=(0,d.v5)(n.contents,u.hudConfig.bundlerBuildUuidNamespace);o.push({filepath:n.path,buildId:e});const i=h(n.text,e);process.env.HUD_SKIP_FILE_VALIDATION||b(i,n.path,r),n.contents=new Uint8Array(Buffer.from(i,"utf8")),t&&await(0,f.writeFileAndFolder)(n.path,n.contents)}return o},t.markFileAsHudModified=h,t.markFile=function(e,t){const r=l.markFile(t,{data:{filename:e,format:"esm"},initialStatements:[m(e,!0)],suffixStatements:[m(e,!1)]});if(!r||!r.code||!r.map)throw new Error("Failed generating ast");return(0,u.appendInlineSourceMap)(r.code,r.map)},t.createMark=m,t.verifyFileContent=b;const s=r(2030),u=r(2546),l=a(r(2784)),d=r(3903),c=a(r(9154)),f=r(7085),p=r(5231);class g extends Error{}function h(e,t){return`/*modifiedByHudESBuildPlugin-${t}*/${e}`}function m(e,t){const r=t?"Start":"End";return`;globalThis && (globalThis.${u.hudConfig.esbuildGlobalVar}="${r}:${e}");`}function b(e,t,r){try{(0,p.logToHud)(`Verifying file content: ${t}, with marks`),new c.Script(e),(0,p.logToHud)(`Editing in splits file content: ${t}`);const{transformedCode:o,editedChunksSizes:n}=(0,s.editInSplits)(e,t,r,!0,!0,e=>!e.includes("node_modules"));if(!o)throw new g(`Failed verify file content, ${t}`);for(let e=0;e<n.length;e+=f.LOG_CHUNKS_SIZE_BATCH){const t=JSON.stringify(n.slice(e,e+f.LOG_CHUNKS_SIZE_BATCH));(0,p.logToHudDebug)(`Edited chunks sizes: ${t}`)}(0,p.logToHud)(`Verifying new file content: ${t}`),new c.Script(o),(0,p.logToHud)(`Verified new file content: ${t}`),(0,p.logToHud)(`${t}: Original code size: ${e.length}, new code size: ${o.length}`)}catch(e){throw(0,p.logToHud)(`Failed verify file content, ${t}, error: ${e}`),new g(`Failed verify file content, ${t}`)}}t.HudBuildError=g},6982:e=>{e.exports=require("crypto")},7085:function(e,t,r){var o,n=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]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||(o=function(e){return o=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},o(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=o(e),a=0;a<r.length;a++)"default"!==r[a]&&n(t,e,r[a]);return i(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.plugin=t.LOG_CHUNKS_SIZE_BATCH=void 0,t.writeFileAndFolder=async function(e,t){const r=f.dirname(e);try{await d.promises.stat(r)}catch{await d.promises.mkdir(r,{recursive:!0})}await d.promises.writeFile(e,t)},t.getModuleRoot=v;const s=r(8528),u=r(2030),l=r(6982),d=a(r(9896)),c=a(r(857)),f=a(r(6928)),p=r(2546),g=r(9929),h=r(5231),m=r(6932),b=r(4414),y=30;async function w(e,t,r,o,n){if(!(r&&o&&n&&o.test(e)))return;const i=f.join(n,e),a=f.dirname(i);try{await d.promises.access(a)}catch{await d.promises.mkdir(a,{recursive:!0})}await d.promises.writeFile(i,t,"utf8");const s=await r(i);return s?.contents&&(t=s.contents),t}async function v(e){let t=f.dirname(e);for(let e=0;e<y&&"/"!==t;e++){const e=f.join(t,"package.json");try{return await d.promises.access(e),t}catch{t=f.dirname(t)}}}t.LOG_CHUNKS_SIZE_BATCH=p.hudConfig.esbuildPluginLogsChunkSize;const _="hud-esbuild-plugin";t.plugin=e=>({name:_,async setup(t){if("inline"===t.initialOptions.sourcemap||"both"===t.initialOptions.sourcemap)return void(0,h.logToUser)(p.UserErrorLogs.EsbuildSourceMapInline());if("node"!==t.initialOptions.platform)return void(0,h.logToUser)(p.UserErrorLogs.EsbuildUnsupportedPlatform());if("win32"===c.platform())return void(0,h.logToUser)(p.UserErrorLogs.EsbuildUnsupportedWindows());const r=e?.hudKey??process.env.HUD_KEY;if(!r)return void(0,h.logToUser)(p.UserErrorLogs.EsbuildMissingKey());const o=e?.includeModules??(0,p.getModulesToTraceFromEnv)()??[],n=(0,u.createCheckers)(o);(0,h.logToUser)("started running");const i=t.initialOptions.write??!0;t.initialOptions.write=!1;const a="esm"===t.initialOptions?.format?s.Format.esm:s.Format.cjs,{callback:y,filter:O,tempDir:T}=await async function(e){const t=e.initialOptions;if(!t.plugins)return;const r=t.plugins.findIndex(e=>e.name===_),o=t.plugins[r+1];if(!o||"datadog-esbuild"!==o.name)return;let n;(0,h.logToHud)("datadog-esbuild plugin detected");const i={...e,onLoad:(...e)=>{n=e},onStart:()=>{},onEnd:()=>{},onResolve:()=>{},onDispose:()=>{}};if(o.setup(i),!n)return void(0,h.logToHud)("datadog-esbuild plugin detected but failed receive onLoad callback");const a=f.join(c.tmpdir(),`hud-${(0,l.randomUUID)()}`);try{return await d.promises.access(a),void(0,h.logToUser)("temp dir already exists, try rerunning the build.")}catch(e){}return(0,h.logToHud)(`creating temp dir to be used by datadog plugin.\n\tPath: ${a}`),await d.promises.mkdir(a,{recursive:!0}),{filter:n[0].filter,callback:n[1],tempDir:a}}(t)??{},S=new Set(t.initialOptions.external||[]),$=new Map;t.onResolve({filter:/.*/},async e=>{if(e.pluginData?.hud?.calledFromHud)return;if(S.has(e.path))return;if(!p.hudConfig.frameworksToPatch.get(e.path)?.enableEsbuild)return;const r={...e};delete r.path;const o=await t.resolve(e.path,{...r,pluginData:{...e.pluginData,hud:{calledFromHud:!0}}}),n=await v(o.path);n&&($.set(n,e.path),(0,h.logToHud)(`mapping framework: ${n} => ${e.path}`))}),t.onLoad({filter:/.*\.(js|ts)$/},async e=>{try{const t=y?async t=>await y({...e,path:t}):void 0;if((0,u.skip)(e.path,n)){const r=await(0,g.getFrameworkContentSuffix)(e.path,$);if(!r)return;let o=await d.promises.readFile(e.path,"utf8");return o=await w(e.path,o,t,O,T)??o,o+=r,{contents:o,loader:e.path.endsWith("ts")?"ts":"js",resolveDir:f.dirname(e.path)}}let r=await d.promises.readFile(e.path,"utf8");return r=(0,m.markFile)(e.path,r),r=await w(e.path,r,t,O,T)??r,r+=await(0,g.getFrameworkContentSuffix)(e.path,$)??"",{contents:r,loader:e.path.endsWith("ts")?"ts":"js",resolveDir:f.dirname(e.path)}}catch(t){return(0,h.logToHud)(`failed patching file "${e.path}", fallbacking to original loader. Error: ${t}`),void(0,h.logToUser)(`failed patching file "${e.path}", fallbacking to original loader`)}}),t.onEnd(async e=>{if(!e?.outputFiles)return;let t;try{t=await(0,m.verifyAndMarkFinalFiles)(e.outputFiles,i,a),(0,h.logToUser)("finished")}catch(e){throw(0,h.logToHud)(`failed validating. Error: ${e}`),(0,h.logToUser)(p.UserErrorLogs.EsbuildFailedBundling()),e}finally{if(t)try{await(0,b.uploadAllSourceMaps)(t,r)}catch(e){(0,h.logToHud)(`failed uploading source maps. Shouldnt get here since we catch all errors in verifyAndMarkFinalFiles, error: ${e}`)}try{if(T)try{await d.promises.access(T),(0,h.logToHud)("cleaning temp dir"),await d.promises.rm(T,{recursive:!0,force:!0})}catch{}}catch(e){(0,h.logToHud)(`failed cleaning temp dir. Error: ${e}`)}try{!process.env.HUD_SKIP_BUILD_LOG_EXPORT&&(0,h.getShouldSendLogs)()&&await(0,h.exportBuildLogs)(r)}catch(e){"true"===process.env.HUD_PLUGIN_VERBOSE&&"true"===process.env.HUD_DEBUG&&(0,h.logToUser)(`Failed exporting build logs. Error: ${e}`)}}})}})},8528:e=>{e.exports=require("./dto")},8938:e=>{e.exports=require("axios")},9154:e=>{e.exports=require("vm")},9896:e=>{e.exports=require("fs")},9929:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getFrameworkContentSuffix=async function(e,t){const r=[...t.entries()].find(([t,r])=>e.startsWith(t));if(!r)return;const[u,l]=r;let d=l+e.slice(u.length);(d.endsWith("index.js")||d.endsWith("index.ts"))&&(d=d.slice(0,d.length-9));const c=i.hudConfig.frameworksToPatch.get(d);if(!(c?.enableEsbuild&&c?.patcher&&c?.version))return;(0,s.logToHud)(`Patching framwork: ${d}`);const f=await(0,a.getModuleRoot)(e);if(!f)return void(0,s.logToHud)(`Failed to find package.json for ${d}`);const p=(0,n.extractModuleVersion)(f);if((0,s.logToHud)(`Patching framework ${d}, version: ${p}`),(0,n.getFrameworkPatcher)(c.patcher).isSupported(f,d,c.version,c.extraInfo))return`\n ;\n try {\n const { hudRITM, infoSafeLog: hudSafeLogger } = require("hud-sdk/instrument");\n if (globalThis.hudRunningMode === ${o.HudRunningMode.enabled}) {\n if (typeof hudRITM === "function") {\n if (typeof hudSafeLogger === "function") {\n hudSafeLogger("esbuild patching ${d}");\n }\n module.exports = hudRITM(module.exports, "${d}", "hud-esbuild-folder-should-not-exists");\n }\n }\n } catch (e) {\n try {\n const { errorSafeLog: hudSafeLogger } = require("hud-sdk/internal");\n if (typeof hudSafeLogger === "function") {\n hudSafeLogger(\`esbuild patching ${f} failed: \${e}\`);\n }\n } catch {}\n }\n `;(0,s.logToHud)(`Failed to patch ${d}, unsupported version: ${p}`)};const o=r(8528),n=r(2030),i=r(2546),a=r(7085),s=r(5231)}},t={};return 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}(7085)})());
2
2
  //# sourceMappingURL=esbuildPlugin.js.map