hud-sdk
Version:
Hud's Node SDK
1 lines • 70.5 kB
JavaScript
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(global,()=>(()=>{var e={336:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const o=r(2546),n=r(2822),s=r(8949),i=r(8901),a=r(714);class c extends a.FrameworkPatcher{_patch(e){return this._patchSendRequest(e),o.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[o.hudConfig.metricSymbol]=a}catch(e){o.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,n.runWithInvestigation)(()=>t.call(this,e));try{s.once("finish",function(){try{(0,n.finishHttpInvestigation)(r,s,a),a.setResponseAttributes(s),a.end()}catch(e){o.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){o.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 o=r(8269),n=r(2546),s=r(8949),i=r(828),a=r(714);class c extends a.FrameworkPatcher{_patch(e){return this._patchConsumer(e),n.instrument_logger.info("Patched KafkaJS successfully"),e}_patchConsumer(e){const t=e.Kafka.prototype.consumer;e.Kafka.prototype.consumer=function(...e){const r=t.apply(this,e);try{const t=new Map,o=[],a=[];!function(e,t){const r=e.subscribe;e.subscribe=async function(...e){const o=await r.apply(this,e);try{const r=e[0].topics;r?r.forEach(e=>{t.push(e)}):e[0].topic?t.push(e[0].topic):n.instrument_logger.warn("No topic found in KafkaJS.Consumer.subscribe",{args:e[0]})}catch(e){n.instrument_logger.error("Error in patching KafkaJS.Consumer.subscribe",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return o},(0,s.copyPropertiesToTarget)(r,e.subscribe)}(r,a),function(e,t,r,o,a){const c=e.run;function g(e,c){const g="eachBatch"===c;for(const e of a)f(e,o,t,r,c);const p=function(e,t,r){return o=>{const s=o[0],i=r?s.batch.topic:s.topic;return function(e,t,r,o){const s=e.get(d(r,o));if(s)return s;for(const e of t)if(e.isBatch===o&&e.pattern.test(r))return e.flowId;n.instrument_logger.warn("No flowId found for topic",{topicName:r,isBatch:o})}(e,t,i,r)}}(t,r,g),h=function(e){return(t,r,o)=>{const s=i.KafkaJSMetric.createUsableMetric();s.start(),s.setFlowId(t);const a=o[0];void 0!==a&&void 0!==a.message&&(a.message[n.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}}(g),m=(0,s.wrapFlow)(p,e[c],h,u,l);e[c]=m}e.run=async function(...e){try{const t=e[0];t.eachMessage&&g(t,"eachMessage"),t.eachBatch&&g(t,"eachBatch")}catch(e){n.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,o,e[0].groupId,a)}catch(e){n.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():n.instrument_logger.warn("No flowMetric found for message",{flowId:e})}function l(e,t,r){const o=t.flowMetric;o?(o.setError(r),o.end()):n.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,n.generateKafkaFlowId)(e,t,i),c={flow_id:a,topic_name:e.toString(),group_id:t,pulling_type:i};(0,o.storeKafkaJSTopicDeclaration)(c),function(e,t,r,o,n){"string"==typeof r?e.set(d(r,o),n):t.push({pattern:r,isBatch:o,flowId:n})}(r,s,e,"eachBatch"===i,a)}t.default=c},646:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const o=r(2546),n=r(8949),s=r(714),i=r(3531);class a extends s.FrameworkPatcher{_patch(e){return this._patchCreate(e),o.instrument_logger.info("Patched NestJS RouterExecutionContext successfully"),e}_patchCreate(e){const t=e.RouterExecutionContext.prototype.create;e.RouterExecutionContext.prototype.create=function(...e){try{const t=e[0],r=e[1];if("function"==typeof t.constructor&&"function"==typeof r){const s=(0,i.generateKey)(t,r);s&&(e[1]=(0,n.wrapFlow)(()=>{try{const e=(0,i.getRequestByCallback)(s);if(!e)return void o.instrument_logger.error("No request object found for key",{key:s});const t=function(e){if(e&&!e.raw&&e.socket)return e[o.hudConfig.metricSymbol]?e[o.hudConfig.metricSymbol].getFlowId?e[o.hudConfig.metricSymbol].getFlowId():void o.instrument_logger.error("No getFlowId function found on metric object"):void o.instrument_logger.error("No metric found on nestjs request object")}(e);return t||o.instrument_logger.error("No flow id found for key",{key:s}),t}catch(e){o.instrument_logger.error("Error in NestJS getFlowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}},r))}else o.instrument_logger.error("Invalid args in NestJS RouterExecutionContext.create",{args:e})}catch(e){o.instrument_logger.error("Error in NestJS RouterExecutionContext patcher",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t.apply(this,e)},(0,n.copyPropertiesToTarget)(t,e.RouterExecutionContext.prototype.create)}}t.default=a},714:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),s=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.getFrameworkPatcher=t.extractModuleVersion=t.isSupportedVersion=t.FrameworkPatcher=void 0;const i=r(2546),a=r(9896),c=s(r(6928)),u=r(8064);function l(e,t){return""===e||u.satisfies(u.coerce(e),t)}function d(e){try{const t=(0,a.readFileSync)(c.join(e,"package.json"),{encoding:"utf8"}),r=JSON.parse(t).version;return"string"==typeof r?r:""}catch(t){i.instrument_logger.info("Failed extracting version",{baseDir:e})}return""}t.FrameworkPatcher=class{patch(e,t,r,o,n=this.constructor.name){try{if(this.isSupported(t,n,r,o))return this._patch(e)}catch(e){i.instrument_logger.error("Unhandeled error during patching framework",{framework:n,error:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return e}isSupported(e,t,r,o){const n=d(e);return!!l(n,r)||(i.instrument_logger.warn("Unsupported version",{framework:t,version:n,supportedVersion:r,basedir:e}),i.customer_logger.log(i.UserErrorLogs.UnsupportedFrameworkVersion(t)),!1)}},t.isSupportedVersion=l,t.extractModuleVersion=d,t.getFrameworkPatcher=function(e){return new(r(2828)(`./${e}`).default)}},828:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.KafkaJSMetric=void 0;const o=r(2546),n=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,n.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};o.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")},1427:function(e,t,r){"use strict";var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getSystemInfo=void 0;const n=o(r(9896)),s=o(r(857));t.getSystemInfo=function(){return{pod_name:u(),node_name:l()}};const 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=n.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 o=r(8528),n=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)(g,e.stack[0],u);e.stack[0]=t,e.stack[0][c.koaPatchedSymbol]=!0}const t=(0,s.generateEndpointFlowId)(e.path,e.methods);(0,n.storeKoaEndpointDeclaration)(new o.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 o=r[0].req;if(!o)return void s.instrument_logger.error("No req found in koa ctx");const n=o[s.hudConfig.metricSymbol];n?n.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 g(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)}},2080:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.SqsMetric=void 0;const o=r(9873);class n extends o.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=n},2197:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),s=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||o(t,e,r)},i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.koa=t.express=t.safeLog=t.registerHook=t.hudRITM=void 0;var a=r(5688);Object.defineProperty(t,"hudRITM",{enumerable:!0,get:function(){return a.hudRITM}}),Object.defineProperty(t,"registerHook",{enumerable:!0,get:function(){return a.registerHook}}),Object.defineProperty(t,"safeLog",{enumerable:!0,get:function(){return a.safeLog}}),s(r(3901),t),t.express=i(r(7127)),s(r(714),t),t.koa=i(r(1502)),s(r(7166),t)},2546:e=>{"use strict";e.exports=require("./lib")},2729:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const o=r(2546),n=r(2822),s=r(8949),i=r(8901),a=r(714);class c extends a.FrameworkPatcher{_patch(e){const t=this._patchGetFramework(e);return o.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[o.hudConfig.metricSymbol]=s}catch(e){o.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,n.runWithInvestigation)(()=>r.apply(r.this,[e,...t]));return a.once("finish",function(){try{(0,n.finishHttpInvestigation)(e,a,s),s.setResponseAttributes(a),s.end()}catch(e){o.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 o=r(2546),n=r(6730),s=r(4815),i=r(7225),a=r(714);class c extends a.FrameworkPatcher{_patch(e){return i.isVerboseLoggingEnabled?((0,n.patchMethods)(e,"application_export"),(0,s.patchUse)(e,"application",!1),(0,i.logLazyRouter)(e),o.instrument_logger.info("Patched express.Application successfully"),e):(o.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.finishSqsInvestigation=t.finishHttpInvestigation=t.getStacktraceUniqString=t.storeInvestigation=t.closeInvestigation=t.runWithInvestigation=t.createNewInvestigation=t.getBaseInvestigationStorage=t.serializableInvestigation=void 0;const o=r(8528),n=r(8269),s=r(2546),i=r(7131),a=r(7808),c=r(7603),u=r(1427),l=/(?:\n\s*at.*)+$/,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.log(r,e,...t)}function g(e){return{status:e.status,context:e.context,exceptions:Array.from(Array.from(e.exceptions?.values()??[]).map(({exception:e,executionFlow:t})=>{return{name:(0,i.extractNameOptional)(e),message:(0,i.extractMessage)(e),stackTrace:(r=e,r?.stack?.match(l)?.[0]),executionFlow:t};var r})??[])}}function p(){return{status:o.InvestigationStatus.Open}}function h(){if(!globalThis.hudEnableInvestigation)return;const e=(0,i.getStorage)().getStore();return void 0!==e&&e.status===o.InvestigationStatus.Open?(e.status=o.InvestigationStatus.Closed,e):void 0}function m(e,t){e.context=t,(0,n.storeClosedInvestigation)(g(e))}t.serializableInvestigation=g,t.getBaseInvestigationStorage=p,t.createNewInvestigation=function(){globalThis.hudEnableInvestigation&&(0,i.getStorage)().enterWith(p())},t.runWithInvestigation=function(e){return globalThis.hudEnableInvestigation?(0,i.getStorage)().run(p(),e):e()},t.closeInvestigation=h,t.storeInvestigation=m;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,o;try{Error.prepareStackTrace=(e,t)=>{r=t[0],o=t};const n=e.stack;if(void 0!==n&&void 0===r){const t=function(e,t){const r=function(e){let t=0;for(let r=0;r<e.length;r++)"\n"===e[r]&&t++;return t}(t)+1;let o=-1;for(let t=0;t<r;t++)if(o=e.indexOf("\n",o+1),-1===o)return;if(-1===o)return;const n=e.indexOf("\n",o+1);return e.slice(o+1,-1===n?void 0:n)}(n,e.message);if(!t)return void f("getStacktraceUniqString: firstStackTraceLine is undefined",{stack:n,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 o=t.match(y);return o&&o[1]&&o[2]&&o[3]?`${e.name}@${o[1]}:${o[2]}:${o[3]}`:void f("getStacktraceUniqString: no match found in regex",{stack:n,message:e.message})}if(void 0===r||void 0===o)return void f("getStacktraceUniqString: result or globCallSites is undefined",{result:void 0===r,globCallSites:void 0===o});Object.defineProperty(e,"stack",{configurable:!0,enumerable:!1,get:()=>t(e,o)})}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 o in e)r[o]=b(e[o],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(n.globalInvestigationTracking>=s.hudConfig.dynamicConfig.investigationRateLimits.maxTotalInvestigations)return void f("finishBaseInvestigation: globalInvestigationTracking is greater than maxTotalInvestigations",{globalInvestigationTracking:n.globalInvestigationTracking,maxTotalInvestigations:s.hudConfig.dynamicConfig.investigationRateLimits.maxTotalInvestigations});const r=e.getFlowId();if(void 0===r)return void f("finishBaseInvestigation: flowId is undefined");const o=v(t.firstException);if(void 0===o)return void f("finishBaseInvestigation: exceptionUniqString is undefined");const i=((0,n.getInvestigationDedupingCache)(r).get(o)??0)+1;if(!(i>s.hudConfig.dynamicConfig.investigationRateLimits.maxSameInvestigations))return(0,n.increaseGlobalInvestigationTracking)(),(0,n.increaseInvestigationDedupingCache)(r,o),t;f("finishBaseInvestigation: investigationCount is greater than maxSameInvestigations",{investigationCount:i,maxSameInvestigations:s.hudConfig.dynamicConfig.investigationRateLimits.maxSameInvestigations})}t.getStacktraceUniqString=v,t.finishHttpInvestigation=function(e,t,r){if(t.statusCode<500)return;const o=w(r);if(void 0===o)return void f("finishHttpInvestigation: base investigation return undefined");const n=r.getFlowId(),s=r.getMsStartTime();void 0!==n&&void 0!==r.route&&void 0!==r.method&&void 0!==s?m(o,{type:"http",endpoint_uuid:n,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:n,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 o=t.getFlowId(),n=t.getMsStartTime();void 0!==n&&void 0!==o?m(r,{type:"sqs",timestamp:n,flow_id:o,messages:b(e),machine_metrics:(0,a.getMachineMetrics)(),system_info:(0,u.getSystemInfo)()}):f("reqTimestamp is undefined even though it shouldn't",{flowId:o})}},2828:(e,t,r)=>{var o={"./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,"./router":5946,"./router.ts":5946,"./serverlessHttp":2729,"./serverlessHttp.ts":2729,"./sqsConsumer":5150,"./sqsConsumer.ts":5150};function n(e){var t=s(e);return r(t)}function s(e){if(!r.o(o,e)){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}return o[e]}n.keys=function(){return Object.keys(o)},n.resolve=s,e.exports=n,n.id=2828},2977:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),s=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.patchRoute=void 0;const i=r(8528),a=r(8269),c=r(2546),u=s(r(6982)),l=r(8949),d=r(6730),f=r(5673);function g(e,t,r,o){!function(e,t,r,o){e[c.hudConfig.express.layerStateSymbol]||(e[c.hudConfig.express.layerStateSymbol]={}),e[c.hudConfig.express.layerStateSymbol][t]?e[c.hudConfig.express.layerStateSymbol][t].methods.push(r):e[c.hudConfig.express.layerStateSymbol][t]={layerPath:o,methods:[r]}}(e,t,r,o),function(e,t,r){const o=new i.EndpointDeclaration(e,[t],"express",void 0,void 0,r);(0,a.storePartialEndpointDeclaration)(o),(0,a.storeExpressEndpointDeclaration)(o)}(t,r,o)}function p(e,t,r){const o=new i.EndpointDeclaration(e,t,"express",void 0,r,void 0);(0,a.storeExpressEndpointDeclaration)(o)}function h(e,t){if(e&&!(e.length<1)){if(c.hudConfig.express.wrapAllCallbacks)for(let r=0;r<e.length;r++){const o=(0,l.wrapFlow)(_(t),e[r],y);e[r]=o}else{const r=(0,l.wrapFlow)(_(t),e[e.length-1],y);e[e.length-1]=r}return t}}function m(e){return(0,a.getLinkedConsistentFlowId)(e,!1)||(c.instrument_logger.warn("No consistent flowId found, returning temporary flow id",{flowId:e}),e)}function _(e){return e?function(){return m(e)}:function(e){const t=e[0]?.route[c.hudConfig.express.layerStateSymbol],r=e[0]?.url;if(t)for(const[e,o]of Object.entries(t)){if(o.layerPath instanceof RegExp&&o.layerPath.test(r))return m(e);if(r.includes(o.layerPath))return m(e)}c.instrument_logger.warn("No flowId found for path",{states:t,url:r.split("?")[0]})}}function y(e,t,r){let o=0;if(4===r.length)o=1;else if(3!==r.length)return void c.instrument_logger.error("Invalid number of arguments in express request",{length:r.length});if(!r[o])return void c.instrument_logger.error("No request object in express request");const n=r[o][c.hudConfig.metricSymbol];n?n.setFlowId(e):c.instrument_logger.error("No endpoint metric found in express request")}t.patchRoute=function(e){const t=(0,d.getMethods)();t.concat("all").forEach(function(r){const o=e.prototype[r];e.prototype[r]=function(){let e;try{e=f(Array.prototype.slice.call(arguments));let o=function(e){const t=e[0][c.hudConfig.express.layerStateSymbol];if(t)return t.flowId}(e);const n=function(e){const t=e[0][c.hudConfig.express.layerStateSymbol];if(t)return t.kind}(e),s=function(e){const t=e[0][c.hudConfig.express.layerStateSymbol];return!!t&&t.allMethod}(e);if(o||(o=[u.randomUUID()]),"application"===n)if(Array.isArray(this.path)){h(e,void 0);for(let e=0;e<this.path.length;e++)p(o[e],s?t:[r],this.path[e])}else h(e,o[0]),p(o[0],s?t:[r],this.path);else if("router"===n)if(Array.isArray(this.path)){h(e,void 0);for(let e=0;e<this.path.length;e++)g(this,o[e],r,this.path[e])}else h(e,o[0]),g(this,o[0],r,this.path);else h(e,o[0]),g(this,o[0],r,this.path)}catch(e){c.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 o.apply(this,e||arguments)}})}},2987:e=>{"use strict";e.exports=require("perf_hooks")},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.generateKey=t.getRequestByCallback=void 0;const o=r(2546);r(3702);const n=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 o.instrument_logger.error("No callback path found on callback",{callback:t});const n=e.constructor.CONTROLLER_ID;if(n)return`${n}.${r}`;o.instrument_logger.error("No controller id found on controller",{controller:e})}t.getRequestByCallback=function(e){const t=i.get(e);return t&&i.delete(e),t},t.generateKey=a;class c extends s.FrameworkPatcher{_patch(e){return this._patchIntercept(e),o.instrument_logger.info("Patched NestJS intercept successfully"),e}_patchIntercept(e){const t=e.InterceptorsConsumer.prototype.intercept;e.InterceptorsConsumer.prototype.intercept=async function(...e){return function(e){try{const t=e[2],r=e[3];if("function"==typeof t.constructor&&"function"==typeof r){let o;if("rpc"===e[5]){if("win32"===process.platform)return;o=e[1][1].args[0]}else if(o=e[1][0],!o||o.raw)return;const n=a(t,r);if(!n)return;i.set(n,o)}else o.instrument_logger.error("Invalid args in NestJS InterceptorsConsumer.intercept",{args:e})}catch(e){o.instrument_logger.error("Error in NestJS intercept patcher",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}(e),await t.apply(this,e)},(0,n.copyPropertiesToTarget)(t,e.InterceptorsConsumer.prototype.intercept)}}t.default=c},3702:e=>{"use strict";e.exports=require("reflect-metadata")},3868:e=>{"use strict";e.exports=require("@jridgewell/sourcemap-codec")},3901:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),s=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.incrementInstrumentedFunctionsCount=t.edit=t.editInSplits=t.splitCode=t.getFunctionWrapperTemplate=void 0;const a=i(r(3176)),c=r(3903),u=r(2546),l=r(8528),d=r(8269),f=r(2546),g=r(3868),p=s(r(2784)),h=/([0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12})/;function m(e,t,r=!1){const o=`${e}_hudTemp`,n="BODY_PLACEHOLDER",s="FUNCTION_ID_PLACEHOLDER",i="AWAITABLE_PLACEHOLDER",a="EXCEPTION_VARIABLE_PLACEHOLDER",c=function(e,t,r=!1){const o=[];if(r)return o;let n;t===l.Format.cjs?n="require":t===l.Format.esm&&(o.push(`import { createRequire as ${e}_createRequire } from "module";`,`const ${e}_require = ${e}_createRequire(import.meta.url);`),n=`${e}_require`);const s=f.myRequire.resolve(u.SDK_MODULE_NAME+"/wrap");return o.push(`let ${e}_temp;`,`try { ${e}_temp = ${n}(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;`),o}(e,t,r);return{functionWrapper:`{\n let ${o};\n const ${u.hudConfig.functionIdVarName} = ${s};\n const ${e}_cc = {};\n try {\n ${e}_wi(${u.hudConfig.functionIdVarName}, ${e}_cc);\n } catch (e) {\n globalThis._hud_SI = { value: 0 };\n globalThis._hud_S = [];\n }\n try {\n ${n}\n } catch (e) {\n try {\n ${e}_wc(${u.hudConfig.functionIdVarName}, ${e}_cc, e);\n } catch (e) {}\n throw e;\n } finally {\n try {\n ${e}_wf(${u.hudConfig.functionIdVarName}, ${e}_cc);\n } catch (e) {}\n }\n }`,awaitWrapper:`(${o} = ${i}, _hud_SI.value--, _hud_F = "", ${e}_cc.ff = true, ${o} = await ${o}, _hud_S[++_hud_SI.value] = ${u.hudConfig.functionIdVarName}, _hud_F = ${e}_cc.currentFlowId, ${e}_cc.ff= false, ${o})`,yieldWrapper:`\n function* ${e}_generatorWrapper() {\n return (${o} = ${i}, _hud_SI.value--, _hud_F = "", ${e}_cc.ff = true, ${o} = yield ${o}, _hud_S[++_hud_SI.value] = ${u.hudConfig.functionIdVarName}, _hud_F = ${e}_cc.currentFlowId, ${e}_cc.ff= false, ${o})\n }`,yieldStarWrapper:`\n function* ${e}_generatorWrapper() {\n return (${o} = ${i}, _hud_SI.value--, _hud_F = "", ${e}_cc.ff = true, ${o} = yield* ${o}, _hud_S[++_hud_SI.value] = ${u.hudConfig.functionIdVarName}, _hud_F = ${e}_cc.currentFlowId, ${e}_cc.ff= false, ${o})\n }`,initialStatements:c,bodyPlaceholder:n,functionIdPlaceholder:s,awaitablePlaceholder:i,fixStackFunction:`\n try{\n ${e}_fs(${u.hudConfig.functionIdVarName}, ${e}_cc)\n }catch(e){};`,exceptionVariablePlaceholder:a,wrapperUserCatch:`\n try {\n ${e}_wuc(${u.hudConfig.functionIdVarName}, ${e}_cc, ${a});\n } catch(e){};`,asyncIteratorWrapper:`${e}_aiw`,awaitableVariable:o}}function _(e,t,r=!0,o=!1){const n=Error.prepareStackTrace;let s=!1,i=function(e){const t=e.match(`${u.hudConfig.bundlerBuildIdVarName}="${h.source}"`);if(t&&t.length>0)return t[1]}(e);i||(i=function(e){return(0,c.v5)(e,u.hudConfig.bundlerBuildUuidNamespace)}(e),s=!0);const l=(0,c.v5)(e,u.hudConfig.functionUuidNamespace),d=(0,a.default)(t.filename).readUInt32BE(),f=(0,a.default)(e).readUInt32BE(),g={data:t,bundlerBuildId:i,prefix:u.hudConfig.wrapVarPrefix,...m(u.hudConfig.wrapVarPrefix,t.format,o),uuidNamespace:u.hudConfig.functionUuidNamespace,fileHash:l,useInputSourcemap:r},_=p.transform(e,g);return I(_.functionsIds.length),Error.prepareStackTrace=n,u.instrument_logger.debug(`Successfully transformed ${t.filename}`),{code:_.code,map:_.map,functionIds:_.functionsIds,filename:t.filename,hasInputMap:_.isInputSourcemap,bundlerBuildId:i,bundlerBuildIdGenerated:s,file_path_checksum:d,file_checksum:f,sourceCodeHash:l,moduleBase:_.moduleBase}}t.getFunctionWrapperTemplate=m;class y extends Error{}function v(e,t){if(e&&t)throw new y("Start mark found inside mark");if(!e&&!t)throw new y("End mark found outside mark")}function b(e,t,r,o){const n=e.split("\n");let s=r,i=o;return s+=n.length-1,s+=t.split("\n").length-1,s===r?i+=n.pop()?.length||0:i=n.pop()?.length||0,{lineOffset:s,columnOffset:i}}function*w(e){let t=!1,r=0,o=0,n=!1,s=0,i=0;const a=new RegExp(`globalThis\\s*?&&\\s*?\\(globalThis\\.${u.hudConfig.esbuildGlobalVar}\\s*?=\\s*?"(Start|End):(?<fileName>.*?)"\\);?`,"g");for(const c of e.matchAll(a)){if(n=!0,!c.groups)throw new y("No groups found in match");const{fileName:a}=c.groups,[u,l]=c,d="Start"===l;v(d,t);let f="";if(t){const t=c.index+u.length;f=e.slice(r,t);const n=o+Buffer.byteLength(f,"utf8");yield{edit:!0,code:f,fileName:a,lineOffset:s,columnOffset:i,indexOffset:o,indexOffsetEnd:n},r=t,o=n}else{const t=c.index;f=e.slice(r,t),o+=Buffer.byteLength(f,"utf8"),r=t,yield{edit:!1,code:f}}t=!!d,({lineOffset:s,columnOffset:i}=b(f,u,s,i))}if(t)throw new y("End mark found outside mark");n?r<e.length&&(yield{edit:!1,code:e.slice(r)}):yield{edit:!1,code:e}}function k(e,t,r){u.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 S(e,t,r){const o=_(e.code,{filename:t,format:r},!1,!0),n=o.code;return o.mapRelativeToChunk=o.map,o.map=function(e,t,r){"string"==typeof e&&(e=JSON.parse(e));const o=(0,g.decode)(e.mappings);return o.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)(o),sourcesContent:void 0})}(o.map,e.lineOffset,e.columnOffset),{codeToAppend:n,metadata:{...o,filename:t,lineOffset:e.lineOffset,columnOffset:e.columnOffset}}}function E(e,t,r,o=!1,n=()=>!0){let s="",i=0,a=0;const c=[];let l=0;const d=o?[]:void 0,f=m(u.hudConfig.wrapVarPrefix,r).initialStatements.join("\n"),g=function(e){return e.slice(u.hudConfig.esbuildMark.length,u.hudConfig.esbuildMark.length+36)}(e);for(const o of w(e)){l++;try{let e="",u=!1;if(o.edit&&(u=n(o.fileName),d&&k(o,u,d)),o.edit&&u){const n=S(o,t,r);e=n.codeToAppend,c.push({...n.metadata,bundlerBuildId:g,transformedLineOffset:i,transformedColumnOffset:a,indexOffset:o.indexOffset,indexOffsetEnd:o.indexOffsetEnd})}else e=0===s.length?M(o.code,f):o.code;({transformedCodeLineOffset:i,transformedCodeColumnOffset:a}=C(e,i,a)),s+=e}catch(r){return u.instrument_logger.error("Failed to patch index",{index:l,filename:t,msg:r instanceof Error?r.message:void 0,stack:r instanceof Error?r.stack:void 0}),{transformedCode:e,metadatas:[],editedChunksSizes:d}}}return{transformedCode:s,metadatas:c,editedChunksSizes:d}}function M(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 C(e,t,r){const o=e.split("\n");return o.length>1?(t+=o.length-1,r=o.pop()?.length||0):r+=e.length,{transformedCodeLineOffset:t,transformedCodeColumnOffset:r}}t.splitCode=w,t.editInSplits=E,t.edit=function(e,t,r){if(e.startsWith(u.hudConfig.esbuildMark))return u.instrument_logger.info("Editing in splits"),E(e,t,r,!1);{const o=_(e,{filename:t,format:r},u.hudConfig.userConfig.disableSourceMapsResolution?.value??!0);return{transformedCode:o.code,metadatas:[o]}}};let x=0;function I(e){x+=e;const t=u.hudConfig.userConfig?.maxMappedFunctions?.value??0;x>=t&&(u.customer_logger.log(u.UserErrorLogs.InstrumentedFunctionCountExceeded(t)),u.app_logger.error("Instrumented function count exceeded",{instrumentedFunctionsCount:x,maxMappedFunctions:t}),(0,d.detachHud)(!1,!1))}t.incrementInstrumentedFunctionsCount=I},3903:e=>{"use strict";e.exports=require("uuid")},4290:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const o=r(2546),n=r(8949),s=r(714),i=r(3531);class a extends s.FrameworkPatcher{_patch(e){return this._patchCreate(e),o.instrument_logger.info("Patched NestJS RpcContextCreator successfully"),e}_patchCreate(e){const t=e.RpcContextCreator.prototype.create;e.RpcContextCreator.prototype.create=function(...e){try{const t=e[0],r=e[1];if("function"==typeof t.constructor&&"function"==typeof r){const s=(0,i.generateKey)(t,r);s&&(e[1]=(0,n.wrapFlow)(()=>{try{const e=(0,i.getRequestByCallback)(s);if(!e)return void o.instrument_logger.error("No msg object found for key",{key:s});const t=function(e){if(e)return e[o.hudConfig.metricSymbol]?e[o.hudConfig.metricSymbol].getFlowId?e[o.hudConfig.metricSymbol].getFlowId():void o.instrument_logger.error("No getFlowId function found on metric object"):void o.instrument_logger.error("No metric found on nestjs msg object")}(e);return t||o.instrument_logger.error("No flow id found for key",{key:s}),t}catch(e){o.instrument_logger.error("Error in NestJS getFlowId",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}},r))}else o.instrument_logger.error("Invalid args in NestJS RpcContextCreator.create",{args:e})}catch(e){o.instrument_logger.error("Error in NestJS RpcContextCreator patcher",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t.apply(this,e)},(0,n.copyPropertiesToTarget)(t,e.RpcContextCreator.prototype.create)}}t.default=a},4815:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),s=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.extractEndpointsFromRouter=t.patchUse=void 0;const i=r(8528),a=r(2546),c=s(r(6982)),u=r(8949),l=r(7225),d=r(5673);function f(e){e[a.hudConfig.express.markedSymbol]||(globalThis.hudExpressState.push(e),e[a.hudConfig.express.markedSymbol]=!0)}function g(e,t){const r=[];for(const[o,n]of Object.entries(e.route[a.hudConfig.express.layerStateSymbol]))r.push(new i.EndpointDeclaration(o,n.methods,"express",t,n.layerPath));return Array.from(r.values())}t.patchUse=function(e,t,r=!0){const o=e.use;e.use=function(e){const n=o.apply(this,arguments);try{let o=this[l.uuidSymbol];!o&&l.isVerboseLoggingEnabled&&(o=c.randomUUID(),this[l.uuidSymbol]=o,a.instrument_logger.info("Express use setting uuid",{kind:t,uuid:o})),"application"===t?function(e,t,r,o){try{r&&(e._router?f(e._router):e.router?f(e.router):a.instrument_logger.warn("Express application doesn't have router or _router")),o&&l.isVerboseLoggingEnabled&&a.instrument_logger.info("Express use app",{parent:o,child:t[1]?.[l.uuidSymbol]||"no uuid",path:t[0]})}catch(e){a.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,o):"router"===t&&function(e,t,r,o,n){try{if(!e.stack)return void a.instrument_logger.error("Express router without stack");if(0===e.stack.length)return void a.instrument_logger.warn("Express router with an empty stack");"query"===e.stack[0].name?f(e):l.isVerboseLoggingEnabled&&!l.skipLayerNamesLogs.has(e.stack[0].name)&&(l.skipLayerNamesLogs.add(e.stack[0].name),a.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 o=e;for(;Array.isArray(o)&&0!==o.length;)o=o[0];"function"!=typeof o&&(t=1,r=e)}return{path:r,offset:t}}(n),u=d(Array.prototype.slice.call(t,i));for(let t=0;t<u.length&&t<e.stack.length;t++){const n=e.stack[e.stack.length-t-1],i=u[u.length-t-1];"router"===n.name?(i&&!i[l.uuidSymbol]&&l.isVerboseLoggingEnabled&&(i[l.uuidSymbol]=c.randomUUID(),a.instrument_logger.info("Express handle router setting uuid",{uuid:i[l.uuidSymbol]})),r&&(n[a.hudConfig.express.routeNamesSymbol]=s)):l.isVerboseLoggingEnabled&&!l.skipLayerNamesLogs.has(n.name)&&(l.skipLayerNamesLogs.add(n.name),a.instrument_logger.warn("Found unknown layer name",{layer:n.name,parent:o,child:i[l.uuidSymbol]||"no uuid",path:s}))}}catch(e){a.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,o,e)}catch(e){a.instrument_logger.error("Failed to patch express.use function",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return n},(0,u.copyPropertiesToTarget)(o,e.use)},t.extractEndpointsFromRouter=function e(t,r){let o=[];if(!r.stack)return a.instrument_logger.error("Router without stack - bad OTEL version",{router:r}),o;for(const n of r.stack)if("router"===n.name){if(!n[a.hudConfig.express.routeNamesSymbol]){a.instrument_logger.error("Router layer without routes",{layer:n});continue}const r=t+n[a.hudConfig.express.routeNamesSymbol];o=o.concat(e(r,n.handle))}else n.route&&n.route[a.hudConfig.express.layerStateSymbol]?o=o.concat(g(n,t)):l.isVerboseLoggingEnabled&&!l.skipLayerNamesLogs.has(n.name)&&(l.skipLayerNamesLogs.add(n.name),a.instrument_logger.warn("Found unknown layer name when extracting endpoints",{layer:n.name}));return o}},5150:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const o=r(8269),n=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,o){const s=n.hudConfig.userConfig.enableDapulse?.value?o.mondayVersion:o.bbcVersion,i=(0,u.extractModuleVersion)(e);return!!(0,u.isSupportedVersion)(i,s)||(n.instrument_logger.warn("Unsupported sqs-consumer version",{framework:"SqsConsumer",version:i,supportedVersion:s,basedir:e,isDapulse:n.hudConfig.userConfig.enableDapulse?.value}),n.customer_logger.log(n.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 n.HudNoQueueUrlInSqsConsumer;const r=g(t);if(e.handleMessageBatch&&"function"==typeof e.handleMessageBatch){const t="handleMessageBatch",s=(0,n.generateSqsFlowId)(r,t);(0,o.storeSqsQueueDeclaration)({flow_id:s,queue_name:r,handle_type:t,batch_size:e.batchSize});const i=e.handleMessageBatch,c=(0,a.wrapFlow)(()=>s,i,p);return void(e.handleMessageBatch=c)}if(e.handleMessage&&"function"==typeof e.handleMessage){const t="handleMessage",s=(0,n.generateSqsFlowId)(r,t);(0,o.storeSqsQueueDeclaration)({flow_id:s,queue_name:r,handle_type:t});const i=e.handleMessage,c=(0,a.wrapFlow)(()=>s,i,p);return void(e.handleMessage=c)}n.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 n.HudNoEventTypeInSqsConsumerOn;const s=r[1];if(!s||"function"!=typeof s)throw new n.HudNoCallbackInSqsConsumerOn;const i=g(e.queueUrl),c="event",u=(0,n.generateSqsFlowId)(i,c,t);(0,o.storeSqsQueueDeclaration)({flow_id:u,queue_name:i,handle_type:c,event_type:t}),r[1]=(0,a.wrapFlow)(()=>u,s,h,m,_)}catch(e){n.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 n.HudNoEventTypeInSqsConsumerEmit;let r,o;if("message_processed"===t&&(r=1),["error","timeout_error","processing_error"].includes(t)&&(o=1,r=2),void 0===r)return;const a=e[r];if(!a)throw new n.HudNoMessageInSqsConsumerEmit;let c;if(void 0!==o){const t=e[o];if(!(t&&t instanceof Error))throw new n.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[n.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,n.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,n.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){n.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),n.instrument_logger.info("Patched sqs-consumer successfully",{isDapulse:n.hudConfig.userConfig.enableDapulse?.value}),e}}t.default=l;let d=!1,f=!1;function g(e){const t=e.split("/").pop();if(!t)throw new n.HudFailExtractSqsQueueName(`Url: ${e}`);return t}function p(e,t,r){const o=c.SqsMetric.createUsableMetric(e);o.start();const s=r[0];if(!s)return n.instrument_logger.warn("No messages pass to sqs handler",{flowId:e}),void(t.flowMetric=o);if(Array.isArray(s)){if(o.msgCount=s.length,s.forEach(e=>{e[n.hudConfig.metricSymbol]=o}),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?o.e2eEpocStartTimeMS=t:n.instrument_logger.warn("No valid SentTimestamp found eventhough the first element had SentTimestamp",{flowId:e})}}else o.msgCount=1,s[n.hudConfig.metricSymbol]=o,s?.Attributes?.SentTimestamp&&(o.e2eEpocStartTimeMS=s.Attributes.SentTimestamp);t.flowMetric=o,(0,i.createNewInvestigation)()}function h(e,t,r){const o=c.SqsMetric.createUsableMetric(e);o.start(),t.flowMetric=o}function m(e,t){const r=t.flowMetric;r?r.end():n.instrument_logger.warn("No flowMetric found for message during catch",{flowId:e})}function _(e,t,r){const o=t.flowMetric;o?(o.addError((0,s.extractName)(r)),o.end()):n.instrument_logger.warn("No flowMetric found for message during catch",{flowId:e})}},5459:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const o=r(2546),n=r(2822),s=r(8949),i=r(8901),a=r(714);class c extends a.FrameworkPatcher{_patch(e){return this._patchEmit(e),o.instrument_logger.info("Patched http successfully"),e}_patchEmit(e){const t=e.Server.prototype.emit;e.Server.prototype.emit=function(e,...r){if("request"!==e)return t.apply(this,[e,...r]);try{const e=r[0],t=r[1],s=i.HttpEndpointMetric.createUsableMetric();s.start(),(0,n.createNewInvestigation)(),s.setRequestAttributes(e),t.once("finish",function(){try{(0,n.finishHttpInvestigation)(e,t,s),s.setResponseAttributes(t),s.end()}catch(e){o.instrument_logger.error("Failed to set response attributes",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}),e[o.hudConfig.metricSymbol]=s}catch(e){o.instrument_logger.error("Failed to patch http.Server.prototype.emit",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t.apply(this,[e,...r])},(0,s.copyPropertiesToTarget)(t,e.Server.prototype.emit)}}t.default=c},5673:e=>{"use strict";e.exports=require("array-flatten")},5688:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.registerHook=t.safeLog=t.hudRITM=void 0;const o=r(8269),n=r(2546),s=r(7166);function i(){n.instrument_logger.warn("Init timeout disabling hud!"),n.customer_logger.log(n.UserErrorLogs.InitTimeout(globalThis.hudIsRunningFromSetup)),(0,o.detachHud)(!1)}t.hudRITM=s.onRequireFn,t.safeLog=function(e){try{n.app_logger.debug(e)}catch(e){return}},t.registerHook=function(){if(n.app_logger.info("HUD is required"),process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE){if(n.app_logger.info("Running in Lambda environment"),parseInt(process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE)<n.hudConfig.lambdaMinimunMemory){const e=process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE;return n.app_logger.warn("Lambda function memory size is less than required, Hud will not run",{memorySize:e}),n.customer_logger.log(n.UserErrorLogs.UnsupportedLambdaMemory()),!1}globalThis.hudRuningInsideLambda=!0}return(0,o.initGlobals)(),n.app_logger.debug("InitGlobals done"),!(globalThis.hudStartFromAutoInit&&!(0,o.validateAndGetUserInput)()||(n.instrument_logger.isValid()?globalThis.hudRanOnRequire?(n.instrument_logger.warn("Already ran onRequire!"),1):(globalThis.hudRanOnRequire=!0,n.instrument_logger.info("Using module",{name:n.SDK_MODULE_NAME}),(0,s.onRequire)(),n.instrument_logger.debug("onRequire done"),globalThis.hudInitGuard=setTimeout(i,n.hudConfig.userConfig.maxTimeUntilInitSessionMs?.value??0),globalThis.hudInitGuard.unref(),0):((0,o.detachHud)(!1),1)))}},5946:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const o=r(2546),n=r(6730),s=r(4815),i=r(714);class a extends i.FrameworkPatcher{_patch(e){return(0,s.patchUse)(e.prototype,"router"),(0,n.patchMethods)(e.prototype,"router"),o.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 o=r(9873);class n extends o.FlowMetric{constructor(e){super(e)}_createUsableMetric(e){return this}toRaw(){return{flow_id:this.flowId,type:"GraphQLMetric",duration:this.duration}}}t.GraphQLMetric=n},6730:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Obje