hud-sdk
Version:
Hud's Node SDK
1 lines • 85.2 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 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(5809),o=r(523),s=r(2822),i=r(8949),a=r(8901),c=r(714);class u extends c.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,i;const c=a.HttpEndpointMetric.createUsableMetric();try{if(r=e.request,i=e.response,!r||!i)return t.call(this,e);c.start(),c.setRequestAttributes(r),r[n.hudConfig.metricSymbol]=c}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 u=(0,s.runWithInvestigation)(()=>t.call(this,e));try{i.once("finish",function(){try{(0,s.finishHttpInvestigation)(r,i,c),c.setResponseAttributes(i),c.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 u},(0,i.copyPropertiesToTarget)(t,e.sendRequest)}}t.default=u},486:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(5809),o=r(8269),s=r(2546),i=r(523),a=r(8949),c=r(828),u=r(714);class d extends u.FrameworkPatcher{_patch(e){return this._patchConsumer(e),i.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=[],s=[];!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):i.instrument_logger.warn("No topic found in KafkaJS.Consumer.subscribe",{args:e[0]})}catch(e){i.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,a.copyPropertiesToTarget)(r,e.subscribe)}(r,s),function(e,t,r,o,s){const u=e.run;function d(e,u){const d="eachBatch"===u;for(const e of s)p(e,o,t,r,u);const m=function(e,t,r){return n=>{const o=n[0],s=r?o.batch.topic:o.topic;return function(e,t,r,n){const o=e.get(g(r,n));if(o)return o;for(const e of t)if(e.isBatch===n&&e.pattern.test(r))return e.flowId;i.instrument_logger.warn("No flowId found for topic",{topicName:r,isBatch:n})}(e,t,s,r)}}(t,r,d),h=function(e){return(t,r,o)=>{const s=c.KafkaJSMetric.createUsableMetric();s.start(),s.setFlowId(t);const i=o[0];void 0!==i&&void 0!==i.message&&(i.message[n.hudConfig.metricSymbol]=s);const a=e?i.batch.partition:i.partition,u=e?i.batch.messages[0]?.timestamp:i.message?.timestamp;s.addPartition(a),s.addProducedTimestamp(u),r.flowMetric=s}}(d),_=(0,a.wrapFlow)(m,e[u],!0,h,l,f);e[u]=_}e.run=async function(...e){try{const t=e[0];t.eachMessage&&d(t,"eachMessage"),t.eachBatch&&d(t,"eachBatch")}catch(e){i.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 u.apply(this,e)},(0,a.copyPropertiesToTarget)(u,e.run)}(r,t,o,e[0].groupId,s)}catch(e){i.instrument_logger.error("Error in patching KafkaJS.Consumer",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return r},(0,a.copyPropertiesToTarget)(t,e.Kafka.prototype.consumer)}}function l(e,t){const r=t.flowMetric;r?r.end():i.instrument_logger.warn("No flowMetric found for message",{flowId:e})}function f(e,t,r){const n=t.flowMetric;n?(n.setError(r),n.end()):i.instrument_logger.warn("No flowMetric found for message",{flowId:e})}function g(e,t){return e+"|"+t}function p(e,t,r,n,i){const a=(0,s.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,n,o){"string"==typeof r?e.set(g(r,n),o):t.push({pattern:r,isBatch:n,flowId:o})}(r,n,e,"eachBatch"===i,a)}t.default=d},523:e=>{"use strict";e.exports=require("./logger")},646:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(5809),o=r(523),s=r(8949),i=r(714),a=r(3531);class c extends i.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 i=(0,a.generateKey)(t,r);i&&(e[1]=(0,s.wrapFlow)(()=>{try{const e=(0,a.getRequestByCallback)(i);if(!e)return void o.instrument_logger.error("No request object found for key",{key:i});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 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:i}),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,!0))}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,s.copyPropertiesToTarget)(t,e.RouterExecutionContext.prototype.create)}}t.default=c},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=f,t.extractModuleVersion=g,t.getFrameworkPatcher=function(e){return new(r(2828)(`./${e}`).default)};const a=r(2546),c=r(523),u=r(9896),d=i(r(6928)),l=r(8064);function f(e,t){return""===e||l.satisfies(l.coerce(e),t)}function g(e){try{const t=(0,u.readFileSync)(d.join(e,"package.json"),{encoding:"utf8"}),r=JSON.parse(t).version;return"string"==typeof r?r:""}catch{c.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){c.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=g(e);return!!f(o,r)||(c.instrument_logger.warn("Unsupported version",{framework:t,version:o,supportedVersion:r,basedir:e}),c.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(523),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")},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(523),i=r(8949),a=r(714),c=n(r(9589));class u extends a.FrameworkPatcher{static nextJSHudMarked=Symbol.for("hudNextJSMarked");_patch(e){return(0,o.setIsNextJsApp)(!0),this._pathLoad(e),s.instrument_logger.info("Patched Next.js successfully"),e}_pathLoad(e){try{const t=e.RouteModuleLoader;if(t[u.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[u.nextJSHudMarked]&&(c.default._detectAndPatchSupportedMethods(t,e),t[u.nextJSHudMarked]=!0)}}catch(e){s.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[u.nextJSHudMarked]=!0,(0,i.copyPropertiesToTarget)(r,t.load)}catch(e){s.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=u},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{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{return void(c=i)}}}},1502:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(5809),o=r(8528),s=r(8269),i=r(2546),a=r(523),c=r(8949),u=r(714);class d extends u.FrameworkPatcher{static koaModuleName="koa";static koaPatchedSymbol=Symbol.for(n.hudConfig.hudPatchedName);_patch(e){return this._patchAppUse(e),a.instrument_logger.info("Patched koa successfully"),e}_patchAppUse(e){const t=e.prototype.use;e.prototype.use=function(e){const r=t.apply(this,arguments);try{if(!arguments[0].router)return r;const e=arguments[0].router.stack;for(let t=0;t<e.length;t++)d._wrapRoute(e[t])}catch(e){a.instrument_logger.error("Failed to patch koa.use function",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return r},(0,c.copyPropertiesToTarget)(t,e.prototype.use)}static _wrapRoute(e){if(e.methods&&0===e.methods.length)return;if(!e.stack[0][d.koaPatchedSymbol]){const t=(0,c.wrapFlow)(m,e.stack[0],!0,l);e.stack[0]=t,e.stack[0][d.koaPatchedSymbol]=!0}const t=(0,i.generateEndpointFlowId)(e.path,e.methods);(0,s.storeEndpointDeclaration)(new o.EndpointDeclaration(t,e.methods,"koa",void 0,e.path));for(const r of e.methods)p(t,e.path,r)}}function l(e,t,r){if(!r[0])return void a.instrument_logger.error("No ctx object found in koa");const o=r[0].req;if(!o)return void a.instrument_logger.error("No req found in koa ctx");const s=o[n.hudConfig.metricSymbol];s?s.setFlowId(e):a.instrument_logger.error("No endpoint metric found in koa req")}function f(e,t){return e+"|"+t}t.default=d;const g=new Map;function p(e,t,r){g.set(f(t,r),e)}function m(e){if(0===e.length)return;const t=e[0]._matchedRoute,r=e[0].req?.method;return function(e,t){return g.get(f(e,t))}(t,r)}},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")},2729:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(5809),o=r(523),s=r(2822),i=r(8949),a=r(8901),c=r(714);class u extends c.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 c(e,...t){const i=a.HttpEndpointMetric.createUsableMetric();try{i.start(),i.setRequestAttributes(e),e[n.hudConfig.metricSymbol]=i}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 c=await(0,s.runWithInvestigation)(()=>r.apply(r.this,[e,...t]));return c.once("finish",function(){try{(0,s.finishHttpInvestigation)(e,c,i),i.setResponseAttributes(c),i.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})}}),c}return(0,i.copyPropertiesToTarget)(r,c),c},(0,i.copyPropertiesToTarget)(t,e),e}}t.default=u},2741:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(523),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=m,t.createNewInvestigation=function(){if(!globalThis.hudEnableInvestigation)return;const e=(0,a.getStorage)();void 0!==e&&e.enterWith(m())},t.runWithInvestigation=function(e){if(!globalThis.hudEnableInvestigation)return e();const t=(0,a.getStorage)();return void 0===t?e():t.run(m(),e)},t.closeInvestigation=h,t.storeInvestigation=_,t.getStacktraceUniqString=b,t.finishHttpInvestigation=function(e,t,r){if(t.statusCode<500)return;try{g("http requests headers",{headers:Object.keys(e.headers)})}catch{g("failed to log http requests headers")}const n=k(r);if(void 0===n)return void g("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?_(n,{type:"http",endpoint_uuid:o,route:r.route,method:r.method,timestamp:s,params:e.params,query:e.query,request_body:w(e.body),status_code:t.statusCode,machine_metrics:(0,c.getMachineMetrics)(),observability_identifiers:(0,u.getObservabilityIdentifiers)(e),extra_headers:(0,u.getExtraHeaders)(e),system_info:(0,d.getSystemInfo)()}):g("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=k(t);if(void 0===r)return void g("finishSqsInvestigation: investigation is undefined");const n=t.getFlowId(),o=t.getMsStartTime();void 0!==o&&void 0!==n?_(r,{type:"sqs",timestamp:o,flow_id:n,messages:w(e),machine_metrics:(0,c.getMachineMetrics)(),system_info:(0,d.getSystemInfo)()}):g("reqTimestamp is undefined even though it shouldn't",{flowId:n})};const n=r(5809),o=r(8528),s=r(8269),i=r(523),a=r(7131),c=r(7808),u=r(7603),d=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 f={};function g(e,...t){let r="debug";(void 0===f[e]||f[e]<n.hudConfig.dynamicConfig.investigationRateLimits.maxUniqLogs)&&(r="warn",f[e]=f[e]+1||1),i.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,a.extractNameOptional)(e),message:(0,a.extractMessage)(e),stackTrace:l(e.message,e.stack),executionFlow:t}))??[]),userContext:e.userContext}}function m(){return{status:o.InvestigationStatus.Open}}function h(){if(!globalThis.hudEnableInvestigation)return;const e=(0,a.getStorage)();if(void 0===e)return;const t=e.getStore();return void 0!==t&&t.status===o.InvestigationStatus.Open?(t.status=o.InvestigationStatus.Closed,t):void 0}function _(e,t){e.context=t,(0,s.storeClosedInvestigation)(p(e))}const y=/.*\((.*):(\d+):(\d+)\)/,v=/.*?(\S*):(\d+):(\d+)/;function b(e){const t=Error.prepareStackTrace;if(void 0===t||"function"!=typeof t)return void g("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 g("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(v);return n&&n[1]&&n[2]&&n[3]?`${e.name}@${n[1]}:${n[2]}:${n[3]}`:void g("getStacktraceUniqString: no match found in regex",{stack:o,message:e.message})}if(void 0===r||void 0===n)return void g("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 w(e,t=n.hudConfig.investigation.maxObjectDepth){try{if("string"==typeof e)return e.length>n.hudConfig.investigation.maxStringLength?e.slice(0,n.hudConfig.investigation.maxStringLength)+"...":e;if(Array.isArray(e))return e.slice(0,n.hudConfig.investigation.maxArrayLength).map(e=>w(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]=w(e[n],t-1);return r}}catch{}}function k(e){const t=h();if(void 0===t)return void g("finishBaseInvestigation: investigation is undefined");if(void 0===t.firstException)return void g("finishBaseInvestigation: firstException is undefined");if(s.globalInvestigationTracking>=n.hudConfig.dynamicConfig.investigationRateLimits.maxTotalInvestigations)return void g("finishBaseInvestigation: globalInvestigationTracking is greater than maxTotalInvestigations",{globalInvestigationTracking:s.globalInvestigationTracking,maxTotalInvestigations:n.hudConfig.dynamicConfig.investigationRateLimits.maxTotalInvestigations});const r=e.getFlowId();if(void 0===r)return void g("finishBaseInvestigation: flowId is undefined");const o=b(t.firstException);if(void 0===o)return void g("finishBaseInvestigation: exceptionUniqString is undefined");const i=((0,s.getInvestigationDedupingCache)(r).get(o)??0)+1;if(!(i>n.hudConfig.dynamicConfig.investigationRateLimits.maxSameInvestigations))return(0,s.increaseGlobalInvestigationTracking)(),(0,s.increaseInvestigationDedupingCache)(r,o),t;g("finishBaseInvestigation: investigationCount is greater than maxSameInvestigations",{investigationCount:i,maxSameInvestigations:n.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,g.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][a.hudConfig.express.layerStateSymbol];if(t)return t.flowId}(e);const o=function(e){const t=e[0][a.hudConfig.express.layerStateSymbol];if(t)return t.kind}(e),s=function(e){const t=e[0][a.hudConfig.express.layerStateSymbol];return!!t&&t.allMethod}(e);if(n||(n=[l.randomUUID()]),"application"===o)if(Array.isArray(this.path)){_(e,void 0);for(let e=0;e<this.path.length;e++)h(n[e],s?t:[r],this.path[e])}else _(e,n[0]),h(n[0],s?t:[r],this.path);else if("router"===o)if(Array.isArray(this.path)){_(e,void 0);for(let e=0;e<this.path.length;e++)m(this,n[e],r,this.path[e])}else _(e,n[0]),m(this,n[0],r,this.path);else _(e,n[0]),m(this,n[0],r,this.path)}catch(e){d.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(5809),c=r(8528),u=r(8269),d=r(523),l=i(r(6982)),f=r(8949),g=r(6730),p=r(5673);function m(e,t,r,n){!function(e,t,r,n){e[a.hudConfig.express.layerStateSymbol]||(e[a.hudConfig.express.layerStateSymbol]={}),e[a.hudConfig.express.layerStateSymbol][t]?e[a.hudConfig.express.layerStateSymbol][t].methods.push(r):e[a.hudConfig.express.layerStateSymbol][t]={layerPath:n,methods:[r]}}(e,t,r,n),function(e,t,r){const n=new c.EndpointDeclaration(e,[t],"express",void 0,void 0,r);(0,u.storePartialEndpointDeclaration)(n),(0,u.storeExpressEndpointDeclaration)(n)}(t,r,n)}function h(e,t,r){const n=new c.EndpointDeclaration(e,t,"express",void 0,r,void 0);(0,u.storeExpressEndpointDeclaration)(n)}function _(e,t){if(e&&!(e.length<1)){if(a.hudConfig.express.wrapAllCallbacks)for(let r=0;r<e.length;r++){const n=(0,f.wrapFlow)(v(t),e[r],!0,b);e[r]=n}else{const r=(0,f.wrapFlow)(v(t),e[e.length-1],!0,b);e[e.length-1]=r}return t}}function y(e){return(0,u.getLinkedConsistentFlowId)(e,!1)||(d.instrument_logger.warn("No consistent flowId found, returning temporary flow id",{flowId:e}),e)}function v(e){return e?function(){return y(e)}:function(e){const t=e[0]?.route[a.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)}d.instrument_logger.warn("No flowId found for path",{states:t,url:r.split("?")[0]})}}function b(e,t,r){let n=0;if(4===r.length)n=1;else if(3!==r.length)return void d.instrument_logger.error("Invalid number of arguments in express request",{length:r.length});if(!r[n])return void d.instrument_logger.error("No request object in express request");const o=r[n][a.hudConfig.metricSymbol];o?o.setFlowId(e):d.instrument_logger.error("No endpoint metric found in express request")}},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.getRequestByCallback=function(e){const t=i.get(e);return t&&i.delete(e),t},t.generateKey=a;const n=r(523);r(3702);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;const t=e[1][1];n=t.args&&t.args.length>0?t.args[0]:t.message}else if(n=e[1][0],!n||n.raw)return;if(!n)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},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 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=b,t.splitCode=E,t.editInSplits=I,t.editWithCliBuildId=function(e,t,r,n){let{transformedCode:o,metadatas:s}=F(e,t,r,[],!0);return o+=`\n//# sourceMappingURL=${y.default.basename(t)}.map`,o+=`\n//"${n}";${d.hudConfig.cliSdkVersionVarName}="${d.SDK_VERSION}";${d.hudConfig.cliBuildIdVarName}`,{transformedCode:o,metadatas:s}},t.edit=F,t.incrementInstrumentedFunctionsCount=j;const c=a(r(3176)),u=r(3903),d=r(5809),l=r(2546),f=r(523),g=r(8528),p=r(8269),m=r(2546),h=r(3868),_=i(r(2784)),y=a(r(6928)),v=/([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 b(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===g.Format.cjs?o="require":t===g.Format.esm&&(n.push(`import { createRequire as ${e}_createRequire } from "module";`,`const ${e}_require = ${e}_createRequire(import.meta.url);`),o=`${e}_require`);const s=m.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 w(e,t,r,n=!0,o=!1,s){const i=Error.prepareStackTrace;let a=!1,l=function(e){const t=e.match(`${d.hudConfig.bundlerBuildIdVarName}="${v.source}"`);if(t&&t.length>0)return t[1]}(e);l||(l=function(e){return(0,u.v5)(e,d.hudConfig.bundlerBuildUuidNamespace)}(e),a=!0);const g=(0,u.v5)(e,d.hudConfig.functionUuidNamespace),p=(0,c.default)(t.filename).readUInt32BE(),h=(0,c.default)(e).readUInt32BE(),y=(0,m.isNextJsApp)(),w={data:t,bundlerBuildId:l,prefix:d.hudConfig.wrapVarPrefix,...b(d.hudConfig.wrapVarPrefix,t.format,o),uuidNamespace:d.hudConfig.functionUuidNamespace,fileHash:g,functionsToInstrument:r,useInputSourcemap:n,isNextJsFile:y,markCode:d.hudConfig.nextJsMarkVarName,enableForAwaitInstrumentation:!s},k=_.transform(e,w);return j(k.functionsIds.length,s),y&&k.marksCount!==k.functionsIds.length&&f.instrument_logger.warn("Marks count mismatch while instrumenting functions",{marksCount:k.marksCount,functionsIdsLength:k.functionsIds.length,filename:t.filename}),Error.prepareStackTrace=i,f.instrument_logger.debug(`Successfully transformed ${t.filename}`),{code:k.code,map:k.map,functionIds:k.functionsIds,filename:t.filename,hasInputMap:k.isInputSourcemap,bundlerBuildId:l,bundlerBuildIdGenerated:a,file_path_checksum:p,file_checksum:h,sourceCodeHash:g,moduleBase:k.moduleBase,isNextJsApp:y,marksCount:k.marksCount,detectedForAwaitLoops:k.detectedForAwaitLoops}}class k extends Error{}function S(e,t){if(e&&t)throw new k("Start mark found inside mark");if(!e&&!t)throw new k("End mark found outside mark")}function x(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\\.${d.hudConfig.esbuildGlobalVar}\\s*?=\\s*?"(Start|End):(?<fileName>.*?)"\\);?`,"g");for(const c of e.matchAll(a)){if(o=!0,!c.groups)throw new k("No groups found in match");const{fileName:a}=c.groups,[u,d]=c,l="Start"===d;S(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}=x(f,u,s,i))}if(t)throw new k("End mark found outside mark");o?r<e.length&&(yield{edit:!1,code:e.slice(r)}):yield{edit:!1,code:e}}function M(e,t,r){f.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=w(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,h.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,h.encode)(n),sourcesContent:void 0})}(n.map,e.lineOffset,e.columnOffset),{codeToAppend:o,metadata:{...n,filename:t,lineOffset:e.lineOffset,columnOffset:e.columnOffset}}}function I(e,t,r,n=!1,o=!1,s=()=>!0){const i=e.slice(-1e3);if(!o&&null!==_.getSourceMap(t,i))return f.instrument_logger.error("Source map found for esbuild split",{filename:t}),f.customer_logger.log(l.UserErrorLogs.EsbuildSourceMapFound()),(0,p.detachHud)(!1,!1),{transformedCode:e,metadatas:[],editedChunksSizes:void 0};let a="",c=0,u=0;const g=[];let m=0;const h=n?[]:void 0,y=b(d.hudConfig.wrapVarPrefix,r).initialStatements.join("\n"),v=function(e){return e.slice(d.hudConfig.esbuildMark.length,d.hudConfig.esbuildMark.length+36)}(e);for(const n of E(e)){m++;try{let e="",o=!1;if(n.edit&&(o=s(n.fileName),h&&M(n,o,h)),n.edit&&o){const o=C(n,t,r);e=o.codeToAppend,g.push({...o.metadata,bundlerBuildId:v,transformedLineOffset:c,transformedColumnOffset:u,indexOffset:n.indexOffset,indexOffsetEnd:n.indexOffsetEnd})}else e=0===a.length?P(n.code,y):n.code;({transformedCodeLineOffset:c,transformedCodeColumnOffset:u}=O(e,c,u)),a+=e}catch(r){return f.instrument_logger.error("Failed to patch index",{index:m,filename:t,msg:r instanceof Error?r.message:void 0,stack:r instanceof Error?r.stack:void 0}),{transformedCode:e,metadatas:[],editedChunksSizes:h}}}return{transformedCode:a,metadatas:g,editedChunksSizes:h}}function P(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 O(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,o){if(e.startsWith(d.hudConfig.esbuildMark))return f.instrument_logger.info("Editing in splits"),I(e,t,r,!1);{const s=w(e,{filename:t,format:r},n,d.hudConfig.userConfig.disableSourceMapsResolution?.value??!0,!1,o);return{transformedCode:s.code,metadatas:[s]}}}let N=0;function j(e,t){N+=e;const r=d.hudConfig.userConfig?.maxMappedFunctions?.value??0;N>=r&&(t||f.customer_logger.log(l.UserErrorLogs.InstrumentedFunctionCountExceeded(r)),f.app_logger.error("Instrumented function count exceeded",{instrumentedFunctionsCount:N,maxMappedFunctions:r}),(0,p.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(5809),o=r(523),s=r(8949),i=r(714),a=r(3531);class c extends i.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 i=(0,a.generateKey)(t,r);i&&(e[1]=(0,s.wrapFlow)(()=>{try{const e=(0,a.getRequestByCallback)(i);if(!e)return void o.instrument_logger.error("No msg object found for key",{key:i});const t=function(e){if(e)return e[n.hudConfig.metricSymbol]?e[n.hudConfig.metricSymbol].getFlowId?e[n.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:i}),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,!0))}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,s.copyPropertiesToTarget)(t,e.RpcContextCreator.prototype.create)}}t.default=c},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[f.uuidSymbol];!n&&f.isVerboseLoggingEnabled&&(n=d.randomUUID(),this[f.uuidSymbol]=n,u.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):u.instrument_logger.warn("Express application doesn't have router or _router")),n&&f.isVerboseLoggingEnabled&&u.instrument_logger.info("Express use app",{parent:n,child:t[1]?.[f.uuidSymbol]||"no uuid",path:t[0]})}catch(e){u.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 u.instrument_logger.error("Express router without stack");if(0===e.stack.length)return void u.instrument_logger.warn("Express router with an empty stack");"query"===e.stack[0].name?p(e):f.isVerboseLoggingEnabled&&!f.skipLayerNamesLogs.has(e.stack[0].name)&&(f.skipLayerNamesLogs.add(e.stack[0].name),u.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),c=g(Array.prototype.slice.call(t,i));for(let t=0;t<c.length&&t<e.stack.length;t++){const o=e.stack[e.stack.length-t-1],i=c[c.length-t-1];"router"===o.name?(i&&!i[f.uuidSymbol]&&f.isVerboseLoggingEnabled&&(i[f.uuidSymbol]=d.randomUUID(),u.instrument_logger.info("Express handle router setting uuid",{uuid:i[f.uuidSymbol]})),r&&(o[a.hudConfig.express.routeNamesSymbol]=s)):f.isVerboseLoggingEnabled&&!f.skipLayerNamesLogs.has(o.name)&&(f.skipLayerNamesLogs.add(o.name),u.instrument_logger.warn("Found unknown layer name",{layer:o.name,parent:n,child:i[f.uuidSymbol]||"no uuid",path:s}))}}catch(e){u.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){u.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 u.instrument_logger.error("Router without stack - bad OTEL version",{router:r}),n;for(const o of r.stack)if("router"===o.name){if(!o[a.hudConfig.express.routeNamesSymbol]){u.instrument_logger.error("Router layer without routes",{layer:o});continue}const r=t+o[a.hudConfig.express.routeNamesSymbol];n=n.concat(e(r,o.handle))}else o.route&&o.route[a.hudConfig.express.layerStateSymbol]?n=n.concat(m(o,t)):f.isVerboseLoggingEnabled&&!f.skipLayerNamesLogs.has(o.name)&&(f.skipLayerNamesLogs.add(o.name),u.instrument_logger.warn("Found unknown layer name when extracting endpoints",{layer:o.name}));return n};const a=r(5809),c=r(8528),u=r(523),d=i(r(6982)),l=r(8949),f=r(7225),g=r(5673);function p(e){e[a.hudConfig.express.markedSymbol]||(globalThis.hudExpressState.push(e),e[a.hudConfig.express.markedSymbol]=!0)}function m(e,t){const r=[];for(const[n,o]of Object.entries(e.route[a.hudConfig.express.layerStateSymbol]))r.push(new c.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(5809),o=r(8269),s=r(2546),i=r(523),a=r(7131),c=r(2822),u=r(8949),d=r(2080),l=r(714);class f extends l.FrameworkPatcher{isSupported(e,t,r,o){const a=n.hudConfig.userConfig.enableDapulse?.value?o.mondayVersion:o.bbcVersion,c=(0,l.extractModuleVersion)(e);return!!(0,l.isSupportedVersion)(c,a)||(i.instrument_logger.warn("Unsupported sqs-consumer version",{framework:"SqsConsumer",version:c,supportedVersion:a,basedir:e,isDapulse:n.hudConfig.userConfig.enableDapulse?.value}),i.customer_logger.log(s.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 s.HudNoQueueUrlInSqsConsumer;const r=m(t);if(e.handleMessageBatch&&"function"==typeof e.handleMessageBatch){const t="handleMessageBatch",n=(0,s.generateSqsFlowId)(r,t);(0,o.storeSqsQueueDeclaration)({flow_id:n,queue_name:r,handle_type:t,batch_size:e.batchSize});const i=e.handleMessageBatch,a=(0,u.wrapFlow)(()=>n,i,!0,h);return void(e.handleMessageBatch=a)}if(e.handleMessage&&"function"==typeof e.handleMessage){const t="handleMessage",n=(0,s.generateSqsFlowId)(r,t);(0,o.storeSqsQueueDeclaration)({flow_id:n,queue_name:r,handle_type:t});const i=e.handleMessage,a=(0,u.wrapFlow)(()=>n,i,!0,h);return void(e.handleMessage=a)}i.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 s.HudNoEventTypeInSqsConsumerOn;const n=r[1];if(!n||"function"!=typeof n)throw new s.HudNoCallbackInSqsConsumerOn;const i=m(e.queueUrl),a="event",c=(0,s.generateSqsFlowId)(i,a,t);(0,o.storeSqsQueueDeclaration)({flow_id:c,queue_name:i,handle_type:a,event_type:t}),r[1]=(0,u.wrapFlow)(()=>c,n,!0,_,y,v)}catch(e){i.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,u.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 s.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 u=e[r];if(!u)throw new s.HudNoMessageInSqsConsumerEmit;let d;if(void 0!==o){const t=e[o];if(!(t&&t instanceof Error))throw new s.HudNoErrorInSqsConsumerEmit;d=(0,a.extractName)(t),"StandardError"===d&&t.cause&&t.cause instanceof Error&&(d=(0,a.extractName)(t.cause))}const l=(e,t)=>{const r=e[n.hudConfig.metricSymbol];r?(d&&r.addError(d,t),r.increaseAndShouldEnd(t)&&(r.end(),(0,c.finishSqsInvestigation)(Array.isArray(u)?u:[u],r))):p||(p=!0,i.instrument_logger.warn("No metric found for message"))};Array.isArray(u)&&u.length>=1?l(u[0],u.length):l(u,1)}catch(e){g||(g=!0,i.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,u.copyPropertiesToTarget)(t,e.emit)}(r)}catch(e){i.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,u.copyPropertiesToTarget)(t,e.Consumer.create)}(e),i.instrument_logger.info("Patched sqs-consumer successfully",{isDapulse:n.hudConfig.userConfig.enableDapulse?.value}),e}}t.default=f;let g=!1,p=!1;function m(e){const t=e.split("/").pop();if(!t)throw new s.HudFailExtractSqsQueueName(`Url: ${e}`);return t}function h(e,t,r){const o=d.SqsMetric.createUsableMetric(e);o.start();const s=r[0];if(!s)return i.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:i.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,c.createNewInvestigation)()}function _(e,t,r){const n=d.SqsMetric.createUsableMetric(e);n.start(),t.flowMetric=n}function y(e,t){const r=t.flowMetric;r?r.end():i.instrument_logger.warn("No flowMetric found for message during catch",{flowId:e})}function v(e,t,r){const n=t.flowMetric;n?(n.addError((0,a.extractName)(r)),n.end()):i.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(5809),o=r(523),s=r(2822),i=r(8949),a=r(8901),c=r(714);class u extends c.FrameworkPat