hud-sdk
Version:
Hud's Node SDK
1 lines • 103 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(523),o=r(7131),i=r(2822),s=r(8949),a=r(4393),u=r(714);class c extends u.FrameworkPatcher{_patch(e){return this._patchSendRequest(e),n.instrument_logger.info("Patched @codegenie/serverless-express/src/frameworks/express.js successfully"),e}_patchSendRequest(e){const t=e.sendRequest;e.sendRequest=function(e){const r=e?.request,s=e?.response;if(!r||!s)return t.call(this,e);const u=a.HttpEndpointMetric.createUsableMetric(),c=(0,o.getFlowStateStorage)(),d=()=>{try{u.start(),u.setRequestAttributes(r)}catch(e){n.instrument_logger.error("Failed to start flowMetric during sendRequest patching",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}try{s.once("finish",function(){try{u.calculateDuration(),(0,i.finishHttpInvestigation)(r,s,u),u.setResponseAttributes(s),u.end()}catch(e){n.instrument_logger.error("Failed to end flowMetric during sendRequest patching",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}})}catch(e){n.instrument_logger.error("Failed to end flowMetric during sendRequest patching",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return(0,i.runWithInvestigation)(()=>t.call(this,e))};return c?c.run({httpMetric:u},d):d()},(0,s.copyPropertiesToTarget)(t,e.sendRequest)}}t.default=c},486:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(8544);class o extends n.BaseKafkaJSPatcher{getExportsRoot(e){return e}getGroupId(e){return e[0].groupId}moduleName(){return"KafkaJS"}}t.default=o},523:e=>{"use strict";e.exports=require("./logger")},646:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(523),o=r(8949),i=r(5128),s=r(714);class a extends s.FrameworkPatcher{_patch(e){return this._patchCreate(e),n.instrument_logger.info("Patched NestJS RouterExecutionContext successfully"),e}_patchCreate(e){const t=e.RouterExecutionContext.prototype.create;e.RouterExecutionContext.prototype.create=function(...e){try{const t=e[0],r=e[1];"function"==typeof t.constructor&&"function"==typeof r?e[1]=(0,i.wrapLinkedFunction)(r):n.instrument_logger.error("Invalid args in NestJS RouterExecutionContext.create",{args:e})}catch(e){n.instrument_logger.error("Error in NestJS RouterExecutionContext patcher",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t.apply(this,e)},(0,o.copyPropertiesToTarget)(t,e.RouterExecutionContext.prototype.create)}}t.default=a},714:function(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),i=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||(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),s=0;s<r.length;s++)"default"!==r[s]&&o(t,e,r[s]);return i(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),u=r(523),c=r(9896),d=s(r(6928)),l=r(8064);function f(e,t){return""===e||l.satisfies(l.coerce(e),t)}function g(e){try{const t=(0,c.readFileSync)(d.join(e,"package.json"),{encoding:"utf8"}),r=JSON.parse(t).version;return"string"==typeof r?r:""}catch{u.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){u.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)||(u.instrument_logger.warning("Unsupported version",{framework:t,version:o,supportedVersion:r,basedir:e}),u.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),i=r(9873);class s extends i.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,error_breakdown:this.errorBreakdown};n.instrument_logger.warning("No partition found for message",{flowId:this.flowId})}}t.KafkaJSMetric=s},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),i=r(523),s=r(8949),a=r(714),u=n(r(9589));class c extends a.FrameworkPatcher{static nextJSHudMarked=Symbol.for("hudNextJSMarked");_patch(e){return(0,o.setIsNextJsApp)(!0),this._pathLoad(e),i.instrument_logger.info("Patched Next.js successfully"),e}_pathLoad(e){try{const t=e.RouteModuleLoader;if(t[c.nextJSHudMarked])return e;const r=t.load;t.load=async function(...e){const t=await r.apply(this,e);try{if(t){const e=t.definition?.pathname;e&&!t[c.nextJSHudMarked]&&(u.default._detectAndPatchSupportedMethods(t,e),t[c.nextJSHudMarked]=!0)}}catch(e){i.instrument_logger.error("Failed to patch Next.js route module",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t},t[c.nextJSHudMarked]=!0,(0,s.copyPropertiesToTarget)(r,t.load)}catch(e){i.instrument_logger.error("Failed to patch Next.js base server",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return e}}t.default=c},1427:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getSystemInfo=function(){return{pod_name:c(),node_name:d()}};const o=n(r(9896)),i=n(r(857)),s=Symbol("not found");let a,u;function c(){if(a!==s){if(a)return a;try{return a=i.default.hostname(),a}catch{return void(a=s)}}}function d(){if(u!==s){if(u)return u;try{const e=o.default.readFileSync("/etc/machine-id","utf8").trim();return u=e,u}catch{return void(u=s)}}}},1502:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(5809),o=r(8528),i=r(8269),s=r(2546),a=r(523),u=r(8949),c=r(714);class d extends c.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,u.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,u.wrapFlow)(p,e.stack[0],!0);e.stack[0]=t,e.stack[0][d.koaPatchedSymbol]=!0}const t=(0,s.generateEndpointFlowId)(e.path,e.methods);(0,i.storeEndpointDeclaration)(new o.EndpointDeclaration(t,e.methods,"koa",void 0,e.path));for(const r of e.methods)g(t,e.path,r)}}function l(e,t){return e+"|"+t}t.default=d;const f=new Map;function g(e,t,r){f.set(l(t,r),e)}function p(e,t){if(0===t.length)return;const r=t[0]._matchedRoute,n=t[0].req?.method;return function(e,t){return f.get(l(e,t))}(r,n)}},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,error_breakdown:this.errorBreakdown}}}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]}),i=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)},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),s=0;s<r.length;s++)"default"!==r[s]&&o(t,e,r[s]);return i(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.serializableInvestigation=t.koa=t.express=t.safeLog=t.registerHook=t.hudRITM=void 0;var u=r(5688);Object.defineProperty(t,"hudRITM",{enumerable:!0,get:function(){return u.hudRITM}}),Object.defineProperty(t,"registerHook",{enumerable:!0,get:function(){return u.registerHook}}),Object.defineProperty(t,"safeLog",{enumerable:!0,get:function(){return u.safeLog}}),s(r(3901),t),t.express=a(r(7127)),s(r(714),t),t.koa=a(r(1502)),s(r(7166),t);var c=r(2822);Object.defineProperty(t,"serializableInvestigation",{enumerable:!0,get:function(){return c.serializableInvestigation}})},2546:e=>{"use strict";e.exports=require("./lib")},2729:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(523),o=r(7131),i=r(2822),s=r(8949),a=r(4393),u=r(714);class c extends u.FrameworkPatcher{_patch(e){const t=this._patchGetFramework(e);return n.instrument_logger.info("Patched serverless-http/lib/framework/get-framework.js successfully"),t}_patchGetFramework(e){const t=e;return e=function(...e){const r=t.apply(t.this,e);async function u(e,...t){const s=a.HttpEndpointMetric.createUsableMetric(),u=(0,o.getFlowStateStorage)(),c=async()=>{try{s.start(),s.setRequestAttributes(e)}catch(e){n.instrument_logger.error("Failed to start flowMetric during framework serverless request handler patching",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}const o=await(0,i.runWithInvestigation)(()=>r.apply(r.this,[e,...t]));return o.once("finish",function(){try{s.calculateDuration(),(0,i.finishHttpInvestigation)(e,o,s),s.setResponseAttributes(o),s.end()}catch(e){n.instrument_logger.error("Failed to end flowMetric during framework serverless request handler patching",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}),o};return u?await u.run({httpMetric:s},c):await c()}return(0,s.copyPropertiesToTarget)(r,u),u},(0,s.copyPropertiesToTarget)(t,e),e}}t.default=c},2741:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(523),o=r(6730),i=r(4815),s=r(7225),a=r(714);class u extends a.FrameworkPatcher{_patch(e){return s.isVerboseLoggingEnabled?((0,o.patchMethods)(e,"application_export"),(0,i.patchUse)(e,"application",!1),(0,s.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=u},2784:e=>{"use strict";e.exports=require("../native/_index")},2822:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getStackTraceWithoutMessage=f,t.limitedLogger=p,t.serializableInvestigation=h,t.getBaseInvestigationStorage=m,t.createNewInvestigation=function(){if(!globalThis.hudEnableInvestigation)return;const e=(0,a.getInvestigationStorage)();void 0!==e&&e.enterWith(m())},t.runWithInvestigation=function(e){if(!globalThis.hudEnableInvestigation)return e();const t=(0,a.getInvestigationStorage)();return void 0===t?e():t.run(m(),e)},t.closeInvestigation=y,t.storeInvestigation=b,t.getInvestigationDedupingKey=v,t.minimizeObject=k,t.finishHttpInvestigation=function(e,t,r){try{if(r.apiProtocol===u.ApiProtocol.GraphQL)return void function(e,t,r){const n=function(e,t){const r=t.apiProtocolAttributes;return e.statusCode>=500||r&&r.errorOccurred?"Error":!!x(t,o.InvestigationType.GraphQL)&&"Duration"}(t,r);if(!1===n)return;const i=C(r,n,o.InvestigationType.GraphQL);if(void 0===i)return void p("finishHttpInvestigation: base investigation return undefined");const s=r.getFlowId(),a=r.getMsStartTime();void 0!==s&&void 0!==a?b(i,{type:o.InvestigationType.GraphQL,flow_id:s,timestamp:a,request_body:k(e.body),graphql_errors:k(r.apiProtocolAttributes?.errors),status_code:t.statusCode,machine_metrics:(0,c.getMachineMetrics)(),observability_identifiers:(0,d.getObservabilityIdentifiersHttp)(e),system_info:(0,l.getSystemInfo)()}):p("flowId or reqTimestamp are undefined even though they shouldn't",{flowId:s,reqTimestamp:a})}(e,t,r);!function(e,t,r){const n=function(e,t){return e.statusCode>=500?"Error":!!x(t,o.InvestigationType.HTTP)&&"Duration"}(t,r);if(!1===n)return;const i=C(r,n,o.InvestigationType.HTTP);if(void 0===i)return;try{p("http requests headers",{headers:Object.keys(e.headers)})}catch{p("failed to log http requests headers")}const s=r.getFlowId(),a=r.getMsStartTime(),u=r.apiProtocolAttributes;void 0!==s&&u&&void 0!==u.route&&void 0!==u.method&&void 0!==a?b(i,{type:o.InvestigationType.HTTP,endpoint_uuid:s,route:u.route,method:u.method,timestamp:a,params:k(e.params),query:k(e.query),request_body:k(e.body),status_code:t.statusCode,machine_metrics:(0,c.getMachineMetrics)(),observability_identifiers:(0,d.getObservabilityIdentifiersHttp)(e),extra_headers:(0,d.getExtraHeaders)(e),system_info:(0,l.getSystemInfo)()}):p("route, method, or reqTimestamp are undefined even though they shouldn't",{flowId:s,route:u.route,method:u.method,reqTimestamp:a})}(e,t,r)}catch(e){p("Failed to finish http investigation",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}},t.finishSqsInvestigation=function(e,t){try{const r=function(e){return e.errors.size>0?"Error":!!x(e,o.InvestigationType.SQS)&&"Duration"}(t);if(!1===r)return;const n=C(t,r,o.InvestigationType.SQS);if(void 0===n)return;const i=t.getFlowId(),s=t.getMsStartTime();if(void 0===s||void 0===i)return void p("reqTimestamp is undefined even though it shouldn't",{flowId:i});b(n,{type:o.InvestigationType.SQS,timestamp:s,flow_id:i,messages:k(e),machine_metrics:(0,c.getMachineMetrics)(),system_info:(0,l.getSystemInfo)()})}catch(e){p("Failed to finish sqs investigation",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}},t.finishKafkaJSInvestigation=function(e,t,r,n){try{const i=function(e){return void 0!==e.error?"Error":!!x(e,o.InvestigationType.Kafka)&&"Duration"}(t);if(!1===i)return;const s=C(t,i,o.InvestigationType.Kafka);if(void 0===s)return;const a=t.getFlowId(),u=t.getMsStartTime();if(void 0===u||void 0===a)return void p("reqTimestamp is undefined even though it shouldn't",{flowId:a});const f=e.map(e=>{let t=e.value;t instanceof Buffer&&(t=t.toString());try{t=JSON.parse(t)}catch{}return{key:e.key,value:t,timestamp:e.timestamp,offset:e.offset,headers:e.headers,attributes:e.attributes}});b(s,{type:o.InvestigationType.Kafka,timestamp:u,topic:r,partition:n,flow_id:a,messages:k(f),machine_metrics:(0,c.getMachineMetrics)(),system_info:(0,l.getSystemInfo)(),observability_identifiers:(0,d.getObservabilityIdentifiers)()})}catch(e){p("Failed to finish kafkajs investigation",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}},t.getErrorRecordsFromInvestigation=E;const n=r(5809),o=r(8528),i=r(8269),s=r(523),a=r(7131),u=r(4393),c=r(7808),d=r(7603),l=r(1427);function f(e,t){if(void 0===t)return;const r=function(e){if(void 0===e)return 0;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 g={};function p(e,...t){let r="debug";(void 0===g[e]||g[e]<n.hudConfig.dynamicConfig.investigationRateLimits.maxUniqLogs)&&(r="warning",g[e]=g[e]+1||1),s.app_logger.logLevel(r,e,...t)}function h(e){return{status:e.status,context:e.context,exceptions:Array.from(e.exceptions.values()).map(({exception:e,executionFlow:t,caught:r})=>({name:(0,a.extractName)(e),message:(0,a.extractMessage)(e),stackTrace:e instanceof Error?f(e.message,e.stack):void 0,executionFlow:t.map(e=>({function_id:e.function_id,caller_id:e.caller_id,args:void 0!==e.args?k(e.args,n.hudConfig.dynamicConfig.investigationRateLimits.maxObjectDepth+2):void 0})),caught:r})),userContext:e.userContext,caught:e.caught,triggerType:e.triggerType,duration:e.duration,durationThreshold:e.durationThreshold,outbounds:e.outbounds.map(e=>function(e){try{return{function_id:e.function_id,caller_id:e.caller_id,type:e.type,duration:e.duration?Number(e.duration):void 0,timestamp:e.timestamp,args:k(e.args),result:k(e.result),error:e.error?{type:"string"==typeof e.error?e.error:(0,a.extractName)(e.error),message:(0,a.extractMessage)(e.error)}:void 0,...e.type===o.OutboundType.HTTP?{bodyDuration:e.bodyDuration,bodyError:e.bodyError?{type:"string"==typeof e.bodyError?e.bodyError:(0,a.extractName)(e.bodyError),message:(0,a.extractMessage)(e.bodyError)}:void 0}:{}}}catch(e){return void p("error serializing outbound",e)}}(e)).filter(e=>void 0!==e)}}function m(){return{triggerType:void 0,duration:0,status:o.InvestigationStatus.Open,caught:!0,exceptions:new Map,outbounds:[]}}function y(){if(!globalThis.hudEnableInvestigation)return;const e=(0,a.getInvestigationStorage)();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 b(e,t){e.context=t,(0,i.storeClosedInvestigation)(h(e))}function _(e){for(const t of e)if(!t.is_outbound_function)return t.function_id}function v(e,t){let r="";for(const t of e)r+=`${t.error_type}-${t.function_id}|`;return r+=`${t}`,r}let w=null;function k(e,t=n.hudConfig.dynamicConfig.investigationRateLimits.maxObjectDepth,o=new WeakSet){try{if(null===w&&(w=r(8611).IncomingMessage),null!==e&&"object"==typeof e){if(o.has(e))return"[Circular Reference]";if(w&&e instanceof w)return"[Http Request]";o.add(e)}if(null==e||["number","boolean"].includes(typeof e))return e;if("string"==typeof e)return e.length>n.hudConfig.dynamicConfig.investigationRateLimits.maxStringLength?e.slice(0,n.hudConfig.dynamicConfig.investigationRateLimits.maxStringLength)+"...":e;if(e instanceof Buffer)return e.length>n.hudConfig.dynamicConfig.investigationRateLimits.maxStringLength?e.subarray(0,n.hudConfig.dynamicConfig.investigationRateLimits.maxStringLength).toString()+"...":e.toString();if(e instanceof ArrayBuffer){const t=Buffer.from(e);return t.length>n.hudConfig.dynamicConfig.investigationRateLimits.maxStringLength?t.subarray(0,n.hudConfig.dynamicConfig.investigationRateLimits.maxStringLength).toString()+"...":t.toString()}if(["bigint","symbol"].includes(typeof e))return k(e.toString(),t-1,o);if("function"==typeof e)return`[Function: ${e.name||"anonymous"}]`;if(void 0===e)return;if(Array.isArray(e))return t<=0?"[Array]":e.slice(0,n.hudConfig.dynamicConfig.investigationRateLimits.maxArrayLength).map(e=>k(e,t-1,o));if(e instanceof Map)return t<=0?"[Map]":{"[Map]":Array.from(e.entries()).slice(0,n.hudConfig.dynamicConfig.investigationRateLimits.maxArrayLength).map(([e,r])=>[k(e,t-1,o),k(r,t-1,o)])};if(e instanceof Set)return t<=0?"[Set]":{"[Set]":Array.from(e.values()).slice(0,n.hudConfig.dynamicConfig.investigationRateLimits.maxArrayLength).map(e=>k(e,t-1,o))};if(e instanceof Date){let r;try{r=e.toISOString()}catch{}return k(r,t-1,o)}if(e instanceof RegExp)return k(e.toString(),t-1,o);if(e&&"Proxy"===e[Symbol.toStringTag])return k(e.target||e,t-1,o);if(e&&e[Symbol.toStringTag])return`[${e[Symbol.toStringTag]}]`;if("object"==typeof e){if(t<=0)return"[Object]";const r={},i=Object.getOwnPropertyNames(e),s=Object.getOwnPropertySymbols(e);for(const s of i.slice(0,n.hudConfig.dynamicConfig.investigationRateLimits.maxArrayLength))try{r[s.slice(0,n.hudConfig.dynamicConfig.investigationRateLimits.maxKeyLength)]=k(e[s],t-1,o)}catch{}for(const i of s.slice(0,n.hudConfig.dynamicConfig.investigationRateLimits.maxArrayLength))try{r[i.toString()]=k(e[i],t-1,o)}catch{}return r}}catch{}}function C(e,t,r){let o;if(o="Error"===t?function(e){const t=y();if(void 0===t)return void p("finishErrorInvestigation: investigation is undefined");const r=e.getFlowId();if(void 0===r)return void p("finishErrorInvestigation: flowId is undefined");const o=E(t),s=v(o,t.caught);if(e.setErrorBreakdown({key:s,errors:o,caught:t.caught}),(0,i.getGlobalInvestigationTracking)()>=n.hudConfig.dynamicConfig.investigationRateLimits.maxTotalInvestigations)return void p("finishErrorInvestigation: globalInvestigationTracking is greater than maxTotalInvestigations",{globalInvestigationTracking:(0,i.getGlobalInvestigationTracking)(),maxTotalInvestigations:n.hudConfig.dynamicConfig.investigationRateLimits.maxTotalInvestigations});if((0,i.getTotalInvestigationsErrorBased)()>=n.hudConfig.dynamicConfig.investigationRateLimits.maxTotalInvestigationsErrorBased)return void p("finishErrorInvestigation: currentTotalInvestigationsErrorBased is greater than maxTotalInvestigationsErrorBased");const a=(0,i.getInvestigationDedupingCache)(r).get(s)??0;if(!(a>=n.hudConfig.dynamicConfig.investigationRateLimits.maxSameInvestigations))return(0,i.increaseGlobalInvestigationTracking)(),(0,i.increaseTotalInvestigationsErrorBased)(),(0,i.increaseInvestigationDedupingCache)(r,s),t;p("finishErrorInvestigation: investigationCount is greater than maxSameInvestigations",{investigationCount:a,maxSameInvestigations:n.hudConfig.dynamicConfig.investigationRateLimits.maxSameInvestigations})}(e):function(e,t){const r=e.getFlowId();if(void 0===r)return void p("finishDurationInvestigation: flowId is undefined");if((0,i.getGlobalInvestigationTracking)()>=n.hudConfig.dynamicConfig.investigationRateLimits.maxTotalInvestigations)return void p("finishDurationInvestigation: currentTotalInvestigationsGlobal is greater than maxTotalInvestigations");if((0,i.getTotalInvestigationsDurationBased)()>=n.hudConfig.dynamicConfig.investigationRateLimits.maxTotalInvestigationsDurationBased)return void p("finishDurationInvestigation: currentTotalInvestigationsDurationBased is greater than maxTotalInvestigationsDurationBased");const o=S(r,t);if(void 0!==o)return(0,i.getInvestigationDurationCount)(r)>=o.number_of_dumps?(p("finishDurationInvestigation: currentInvestigationCount is greater than durationThresholdAndCount.count"),void s.app_logger.debug("finishDurationInvestigation: currentInvestigationCount is greater than durationThresholdAndCount.count")):((0,i.increaseInvestigationDurationCount)(r),(0,i.increaseGlobalInvestigationTracking)(),(0,i.increaseTotalInvestigationsDurationBased)(),y());p("finishDurationInvestigation: durationThresholdAndCount is undefined")}(e,r),void 0!==o)return o.triggerType=t,o.duration=e.duration,o.durationThreshold=S(e.getFlowId()??"",r)?.duration,o;p("finishInvestigation: error investigation return undefined")}function S(e,t){const r=(0,i.getFlowIdDurationThresholdAndCount)(e);return void 0===r?(0,i.getFlowIdDurationThresholdAndCount)(`default-${t}`):r}function x(e,t){const r=e.getFlowId();if(void 0===r)return!1;const n=S(r,t);return void 0!==n&&n.duration<e.duration}function E(e){const t=new Set,r=[];for(const n of e.exceptions.values()){const e=(0,a.extractName)(n.exception),o=_(n.executionFlow)??"",i=`${e}-${o}`;if(t.has(i))continue;t.add(i);const s={error_type:e,function_id:o};r.push(s)}return r}},2828:(e,t,r)=>{var n={"./baseKafkaJsPatcher":8544,"./baseKafkaJsPatcher.ts":8544,"./codeGenieServerlessExpress":336,"./codeGenieServerlessExpress.ts":336,"./confluentKafkaJs":7276,"./confluentKafkaJs.ts":7276,"./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/flow":9873,"./flows/flow.ts":9873,"./flows/http":4393,"./flows/http.ts":4393,"./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,"./nestjsRouterExecutionContext":646,"./nestjsRouterExecutionContext.ts":646,"./nestjsRpcContextCreator":4290,"./nestjsRpcContextCreator.ts":4290,"./nextJsConfig":9723,"./nextJsConfig.ts":9723,"./nextJsModuleLoader":1326,"./nextJsModuleLoader.ts":1326,"./nextJsRouteModule":8840,"./nextJsRouteModule.ts":8840,"./nextjs":9589,"./nextjs.ts":9589,"./outbound/axios":5354,"./outbound/axios.ts":5354,"./outbound/nodeFetch":8564,"./outbound/nodeFetch.ts":8564,"./outbound/pg":7427,"./outbound/pg.ts":7427,"./outbound/request":4349,"./outbound/request.ts":4349,"./outbound/wrapOutbound":9938,"./outbound/wrapOutbound.ts":9938,"./router":5946,"./router.ts":5946,"./serverlessHttp":2729,"./serverlessHttp.ts":2729,"./sqsConsumer":5150,"./sqsConsumer.ts":5150};function o(e){var t=i(e);return r(t)}function i(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=i,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]}),i=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||(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),s=0;s<r.length;s++)"default"!==r[s]&&o(t,e,r[s]);return i(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),i=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)){y(e,void 0);for(let e=0;e<this.path.length;e++)m(n[e],i?t:[r],this.path[e])}else y(e,n[0]),m(n[0],i?t:[r],this.path);else if("router"===o)if(Array.isArray(this.path)){y(e,void 0);for(let e=0;e<this.path.length;e++)h(this,n[e],r,this.path[e])}else y(e,n[0]),h(this,n[0],r,this.path);else y(e,n[0]),h(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),u=r(8528),c=r(8269),d=r(523),l=s(r(6982)),f=r(8949),g=r(6730),p=r(5673);function h(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 u.EndpointDeclaration(e,[t],"express",void 0,void 0,r);(0,c.storePartialEndpointDeclaration)(n),(0,c.storeExpressEndpointDeclaration)(n)}(t,r,n)}function m(e,t,r){const n=new u.EndpointDeclaration(e,t,"express",void 0,r,void 0);(0,c.storeExpressEndpointDeclaration)(n)}function y(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)(_(t),e[r],!0);e[r]=n}else{const r=(0,f.wrapFlow)(_(t),e[e.length-1],!0);e[e.length-1]=r}return t}}function b(e){return(0,c.getLinkedConsistentFlowId)(e,!1)||(d.instrument_logger.warning("No consistent flowId found, returning temporary flow id",{flowId:e}),e)}function _(e){return e?function(){return b(e)}:function(e,t){const r=t[0]?.route[a.hudConfig.express.layerStateSymbol],n=t[0]?.url;if(r)for(const[e,t]of Object.entries(r)){if(t.layerPath instanceof RegExp&&t.layerPath.test(n))return b(e);if(n.includes(t.layerPath))return b(e)}d.instrument_logger.warning("No flowId found for path",{states:r,url:n.split("?")[0]})}}},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")},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]}),i=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||(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),s=0;s<r.length;s++)"default"!==r[s]&&o(t,e,r[s]);return i(t,e),t}),a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.destructImportObj=t.defaultImportObj=void 0,t.getFunctionWrapperTemplate=k,t.splitCode=M,t.editInSplits=P,t.editWithCliBuildId=function(e,t,r,n){let{transformedCode:o,metadatas:i}=N(e,t,r,[],!0);return o+=`\n//# sourceMappingURL=${b.default.basename(t)}.map`,o+=`\n//"${n}";${d.hudConfig.cliSdkVersionVarName}="${d.SDK_VERSION}";${d.hudConfig.cliBuildIdVarName}`,{transformedCode:o,metadatas:i}},t.edit=N,t.incrementInstrumentedFunctionsCount=R;const u=a(r(3176)),c=r(3903),d=r(5809),l=r(2546),f=r(523),g=r(8528),p=r(8269),h=r(2546),m=r(3868),y=s(r(2784)),b=a(r(6928)),_=/([0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12})/;function v(){return d.SDK_MODULE_NAME+"/wrap"}function w(e,t){return`\n ${d.hudConfig.internalAfterYieldFunctionName}(\n ${e} ${d.hudConfig.internalBeforeYieldFunctionName}(\n ${t}, ${d.hudConfig.callContextVarName}\n ),\n ${d.hudConfig.callContextVarName}\n )\n `}function k(e,r,n=!1,o=!1,i=!1){const s="BODY_PLACEHOLDER",a="FUNCTION_ID_PLACEHOLDER",u="AWAITABLE_PLACEHOLDER",c="EXCEPTION_VARIABLE_PLACEHOLDER",l="ARGS_ARRAY_PLACEHOLDER",f=function(e,r,n=!1,o=!1){const i=[];if(n)return i;let s;r===g.Format.cjs?s="require":r===g.Format.esm&&(i.push(`import { createRequire as ${e}_createRequire } from "module";`,`const ${e}_require = ${e}_createRequire(import.meta.url);`),s=`${e}_require`);const a=o?`"${v()}"`:`String.raw\`${h.myRequire.resolve(v())}\``;return i.push(`let ${e}_temp = ${t.defaultImportObj};`,`try {\n let ${e}_module = ${s}(${a});\n const ${e}_assert = (x) => {\n if (!x) {\n throw new Error();\n }\n };\n ${e}_assert(${e}_module._hudVersion === "${d.SDK_VERSION}");\n Object.keys(${e}_temp).forEach((key) => {\n ${e}_assert(typeof ${e}_temp[key] === typeof ${e}_module[key]);\n }); \n ${e}_assert(typeof ${e}_module.asyncIteratorWrapper === "function");\n ${e}_temp = ${e}_module;\n } catch {}`,`const ${t.destructImportObj} = ${e}_temp;`),i}(e,r,n,i),p=o?", true":"";return{functionWrapper:`{\n let ${d.hudConfig.callContextVarName}; \n const ${d.hudConfig.internalBeforeYieldFunctionName} = (x, y) => {\n try {\n ${d.hudConfig.beforeYieldFunctionName}(y);\n } catch {}\n return x;\n };\n const ${d.hudConfig.internalAfterYieldFunctionName} = (x, y) => {\n try {\n ${d.hudConfig.afterYieldFunctionName}(y);\n } catch {}\n return x;\n };\n try {\n ${d.hudConfig.callContextVarName} = ${d.hudConfig.functionInitFunctionName}(${a} ${p});\n } catch {}\n\n try {\n ${s}\n } catch (e) {\n try {\n ${d.hudConfig.functionCatchFunctionName}(e, ${d.hudConfig.callContextVarName}, ${l});\n } catch {}\n throw e;\n } finally {\n try {\n ${d.hudConfig.functionFinallyFunctionName}(${d.hudConfig.callContextVarName});\n } catch {}\n }\n }`,awaitWrapper:`(\n ${w("await",u)}\n )`,yieldWrapper:`\n function* ${e}_generatorWrapper() {\n return (\n ${w("yield",u)}\n )\n }`,yieldStarWrapper:`\n function* ${e}_generatorWrapper() {\n return (\n ${w("yield*",u)}\n )\n }`,initialStatements:f,bodyPlaceholder:s,functionIdPlaceholder:a,awaitablePlaceholder:u,argsArrayPlaceholder:l,fixStackFunction:`\n try {\n ${d.hudConfig.fixStackFunctionName}(${d.hudConfig.callContextVarName})\n } catch {}`,exceptionVariablePlaceholder:c,wrapperUserCatch:`\n try {\n ${d.hudConfig.wrapperUserCatchFunctionName}(${c}, ${d.hudConfig.callContextVarName}, ${l});\n } catch {}`,asyncIteratorWrapper:`${d.hudConfig.asyncIteratorWrapperFunctionName}`}}function C(e,t,r,n=!0,o=!1,i){const s=Error.prepareStackTrace;let a=!1,l=function(e){const t=e.match(`${d.hudConfig.bundlerBuildIdVarName}="${_.source}"`);if(t&&t.length>0)return t[1]}(e);l||(l=function(e){return(0,c.v5)(e,d.hudConfig.bundlerBuildUuidNamespace)}(e),a=!0);const g=(0,c.v5)(e,d.hudConfig.functionUuidNamespace),p=(0,u.default)(t.filename).readUInt32BE(),m=(0,u.default)(e).readUInt32BE(),b=(0,h.isNextJsApp)(),v={data:t,bundlerBuildId:l,prefix:d.hudConfig.wrapVarPrefix,...k(d.hudConfig.wrapVarPrefix,t.format,o,r.length>0,i),uuidNamespace:d.hudConfig.functionUuidNamespace,fileHash:g,functionsToInstrument:r,useInputSourcemap:n,isNextJsFile:b,markCode:d.hudConfig.nextJsMarkVarName,enableForAwaitInstrumentation:!i},w=y.transform(e,v);return R(w.functionsIds.length,i),b&&w.marksCount!==w.functionsIds.length&&f.instrument_logger.warning("Marks count mismatch while instrumenting functions",{marksCount:w.marksCount,functionsIdsLength:w.functionsIds.length,filename:t.filename}),Error.prepareStackTrace=s,f.instrument_logger.debug(`Successfully transformed ${t.filename}`),{code:w.code,map:w.map,functionIds:w.functionsIds,totalFunctionsCountIncludeUninstrumented:w.totalFunctionsCountIncludeUninstrumented,filename:t.filename,hasInputMap:w.isInputSourcemap,bundlerBuildId:l,bundlerBuildIdGenerated:a,file_path_checksum:p,file_checksum:m,sourceCodeHash:g,moduleBase:w.moduleBase,isNextJsApp:b,marksCount:w.marksCount,detectedForAwaitLoops:w.detectedForAwaitLoops}}t.defaultImportObj="\n {\n wrapperInitial: () => {\n return {};\n },\n wrapperCatch: () => {},\n wrapperFinally: () => {},\n fixStack: () => {},\n wrapperUserCatch: () => {},\n beforeYield: (x) => x,\n afterYield: (x) => x,\n }\n",t.destructImportObj=`\n {\n wrapperInitial: ${d.hudConfig.functionInitFunctionName},\n wrapperCatch: ${d.hudConfig.functionCatchFunctionName},\n wrapperFinally: ${d.hudConfig.functionFinallyFunctionName},\n fixStack: ${d.hudConfig.fixStackFunctionName},\n asyncIteratorWrapper: ${d.hudConfig.asyncIteratorWrapperFunctionName},\n wrapperUserCatch: ${d.hudConfig.wrapperUserCatchFunctionName},\n beforeYield: ${d.hudConfig.beforeYieldFunctionName},\n afterYield: ${d.hudConfig.afterYieldFunctionName},\n }\n`;class S extends Error{}function x(e,t){if(e&&t)throw new S("Start mark found inside mark");if(!e&&!t)throw new S("End mark found outside mark")}function E(e,t,r,n){const o=e.split("\n");let i=r,s=n;return i+=o.length-1,i+=t.split("\n").length-1,i===r?s+=o.pop()?.length||0:s=o.pop()?.length||0,{lineOffset:i,columnOffset:s}}function*M(e){let t=!1,r=0,n=0,o=!1,i=0,s=0;const a=new RegExp(`globalThis\\s*?&&\\s*?\\(globalThis\\.${d.hudConfig.esbuildGlobalVar}\\s*?=\\s*?"(Start|End):(?<fileName>.*?)"\\);?`,"g");let u="";for(const c of e.matchAll(a)){if(o=!0,!c.groups)throw new S("No groups found in match");const[a,d]=c,l="Start"===d;x(l,t);let f="";if(t){const t=c.index+a.length;f=e.slice(r,t);const o=n+Buffer.byteLength(f,"utf8");yield{edit:!0,code:f,fileName:u,lineOffset:i,columnOffset:s,indexOffset:n,indexOffsetEnd:o},r=t,n=o}else{u=c.groups?.fileName;const t=c.index;f=e.slice(r,t),n+=Buffer.byteLength(f,"utf8"),r=t,yield{edit:!1,code:f}}t=!!l,({lineOffset:i,columnOffset:s}=E(f,a,i,s))}if(t)throw new S("End mark found outside mark");o?r<e.length&&(yield{edit:!1,code:e.slice(r)}):yield{edit:!1,code:e}}function I(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 O(e,t,r){const n=C(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,m.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,m.encode)(n),sourcesContent:void 0})}(n.map,e.lineOffset,e.columnOffset),{codeToAppend:o,metadata:{...n,filename:t,lineOffset:e.lineOffset,columnOffset:e.columnOffset}}}function P(e,t,r,n=!1,o=!1,i=!1,s=()=>!0){const a=e.slice(-1e3);if(!o&&null!==y.getSourceMap(t,a))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 u="",c=0,g=0;const h=[];let m=0;const b=n?[]:void 0,_=k(d.hudConfig.wrapVarPrefix,r,!1,i).initialStatements.join("\n"),v=function(e){return e.slice(d.hudConfig.esbuildMark.length,d.hudConfig.esbuildMark.length+36)}(e);for(const n of M(e)){m++;try{let e="",o=!1;if(n.edit&&(o=s(n.fileName),b&&I(n,o,b)),n.edit&&o){const o=O(n,t,r);e=o.codeToAppend,h.push({...o.metadata,bundlerBuildId:v,transformedLineOffset:c,transformedColumnOffset:g,indexOffset:n.indexOffset,indexOffsetEnd:n.indexOffsetEnd})}else e=0===u.length?T(n.code,_):n.code;({transformedCodeLineOffset:c,transformedCodeColumnOffset:g}=F(e,c,g)),u+=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:b}}}return{transformedCode:u,metadatas:h,editedChunksSizes:b}}function T(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 F(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 N(e,t,r,n,o){if(e.startsWith(d.hudConfig.esbuildMark))return f.instrument_logger.info("Editing in splits"),P(e,t,r,!1,o);{const i=C(e,{filename:t,format:r},n,d.hudConfig.userConfig.disableSourceMapsResolution?.value??!0,!1,o);return{transformedCode:i.code,metadatas:[i]}}}let j=0;function R(e,t){j+=e;const r=d.hudConfig.userConfig?.maxMappedFunctions?.value??0;j>=r&&(t||f.customer_logger.log(l.UserErrorLogs.InstrumentedFunctionCountExceeded(r)),f.app_logger.error("Instrumented function count exceeded",{instrumentedFunctionsCount:j,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(523),o=r(8949),i=r(5128),s=r(714);class a extends s.FrameworkPatcher{_patch(e){return this._patchCreate(e),n.instrument_logger.info("Patched NestJS RpcContextCreator successfully"),e}_patchCreate(e){const t=e.RpcContextCreator.prototype.create;e.RpcContextCreator.prototype.create=function(...e){try{const t=e[0],r=e[1];"function"==typeof t.constructor&&"function"==typeof r?e[1]=(0,i.wrapLinkedFunction)(r):n.instrument_logger.error("Invalid args in NestJS RpcContextCreator.create",{args:e})}catch(e){n.instrument_logger.error("Error in NestJS RpcContextCreator patcher",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return t.apply(this,e)},(0,o.copyPropertiesToTarget)(t,e.RpcContextCreator.prototype.create)}}t.default=a},4349:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(523),o=r(714),i=r(5809),s=r(8528),a=r(8269),u=r(8949),c=r(9938);class d extends o.FrameworkPatcher{_patch(e){return n.instrument_logger.info("Patching request"),e=this._patchRequest(e),this._patchMethods(e),this._createRequestDeclaration(),n.instrument_logger.info("Patched request successfully"),e}_patchRequest(e){return(0,c.wrapOutboundFunction)(e,i.hudConfig.requestFunctionId,l,f,s.OutboundType.HTTP,!0)}_patchMethods(e){for(const[t,r]of Object.entries(i.hudConfig.requestMethodFunctionIds)){const n=e[t];e[t]=(0,c.wrapOutboundFunction)(n,r,(e,r,n)=>l(e,r,n,t),f,s.OutboundType.HTTP,!0)}}_createRequestDeclaration(){(0,a.storeLoadedOutbound)("request")}}function l(e,t,r,n){const o=function(e,t,r){"function"==typeof t&&(r=t);let n={};return n=null!==t&&"object"==typeof t?{...t,uri:e}:"string"==typeof e?{uri:e}:{...e},n.callback=r||n.callback,n}(e[0],e[1],e[2]),i=o.callback;return o.callback=(e,n,o)=>{try{null!=e?e instanceof AggregateError&&e.errors.length>0?t(e.errors[0]):t(e):r({response:n,body:o})}catch{}"function"==typeof i&&i(e,n,o)},(0,u.copyPropertiesToTarget)(i,o.callback),e[0]=o,e[1]=void 0,e[2]=void 0,{url:o.uri,method:n??o.method?.toLowerCase()??"get",body:o.form}}function f(e,t,r){(0,c.reduceRequestArgsIfNeeded)(e,r,e=>Number.parseInt(e?.response?.request?.getHeader("content-length")));const n=Number.parseInt(e.response.headers["content-length"]),o=isNaN(n)||0===n?void 0:n;return{status_code:e.response.statusCode,bodySize:o,body:(0,c.getReducedBody)(e.body,o,i.hudConfig.dynamicConfig.maxHTTPResponseBodySize)}}t.default=d},4393:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HttpEndpointMetric=t.ApiProtocol=void 0;const n=r(9873);var o;!function(e){e.REST="rest",e.GraphQL="graphql"}(o||(t.ApiProtocol=o={}));class i extends n.FlowMetric{statusCode;apiProtocol;apiProtocolAttributes;constructor(e){super(e)}_createUsableMetric(e){return this}setRequestAttributes(e){const t=e.url||e.path;this.apiProtocol=o.REST,this.apiProtocolAttributes={route:t?.split("?")[0],method:e.method}}setGraphQLAttributes(e,t){this.apiProtocol=o.GraphQL,this.apiProtocolAttributes={errorOccurred:e,errors:t}}setResponseAttributes(e){this.statusCode=e.statusCode}toRaw(){if(!this.statusCode)return;if(this.apiProtocol===o.GraphQL){const e=this.apiProtocolAttributes;return{flow_id:this.flowId,type:"GraphQLMetric",duration:this.duration,status_code:this.statusCode,error_occurred:e.errorOccurred,error_breakdown:this.errorBreakdown}}if(this.apiProtocol!==o.REST)return;const e=this.apiProtocolAttributes;return e.route&&e.method?{flow_id:this.flowId,type:"EndpointMetric",duration:this.duration,status_code:this.statusCode,route:e.route,method:e.method,error_breakdown:this.errorBreakdown}:void 0}}t.HttpEndpointMetric=i},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]}),i=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||(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),s=0;s<r.length;s++)"default"!==r[s]&&o(t,e,r[s]);return i(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,c.instrument_logger.info("Express use setting uuid",{kind:t,uuid:n})),"application"===t?function(e,t,r,n){try{r&&(e._router?p(e._router):e.router?p(e.router):c.instrument_logger.warning("Express application doesn't have router or _router")),n&&f.isVerboseLoggingEnabled&&c.instrument_logger.info("Express use app",{parent:n,child:t[1]?.[f.uuidSymbol]||"no uuid",path:t[0]})}catch(e){c.instrument_logger.error("Failed to save express app router",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}(this,arguments,r,n):"router"===t&&function(e,t,r,n,o){try{if(!e.stack)return void c.instrument_logger.error("Express router without stack");if(0===e.stack.length)return void c.instrument_logger.warning("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),c.instrument_logger.warning("Found unknown stack name",{stack:e.stack[0].name}));const{path:i,offset:s}=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),u=g(Array.prototype.slice.call(t,s));for(let t=0;t<u.length&&t<e.stack.length;t++){const o=e.stack[e.stack.length-t-1],s=u[u.length-t-1];"router"===o.name?(s&&!s[f.uuidSymbol]&&f.isVerboseLoggingEnabled&&(s[f.uuidSymbol]=d.randomUUID(),c.instrument_logger.info("Express handle router setting uuid",{uuid:s[f.uuidSymbol]})),r&&(o[a.hudConfig.express.routeNamesSymbol]=i)):f.isVerboseLoggingEnabled&&!f.skipLayerNamesLogs.has(o.name)&&(f.skipLayerNamesLogs.add(o.name),c.instrument_logger.warning("Found unknown layer name",{layer:o.name,parent:n,child:s[f.uuidSymbol]||"no uuid",path:i}))}}catch(e){c.instrument_logger.error("Failed to patch router.use function",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}(this,arguments,r,n,e)}catch(e){c.instrument_logger.error("Failed to patch express.use function",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}return o},(0,l.copyPropertiesToTarget)(n,e.use)},t.extractEndpointsFromRouter=function e(t,r){let n=[];if(!r.stack)return c.instrument_logger.error("Router without stack - bad OTEL version",{router:r}),n;for(const o of r.stack)if("router"===o.name){if(!o[a.hudConfig.express.routeNamesSymbol]){c.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(h(o,t)):f.isVerboseLoggingEnabled&&!f.skipLayerNamesLogs.has(o.name)&&(f.skipLayerNamesLogs.add(o.name),c.instrument_logger.warning("Found unknown layer name when extracting endpoints",{layer:o.name}));return n};const a=r(5809),u=r(8528),c=r(523),d=s(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 h(e,t){const r=[];for(const[n,o]of Object.entries(e.route[a.hudConfig.express.layerStateSymbol]))r.push(new u.EndpointDeclaration(n,o.methods,"express",t,o.layerPath));return Array.from(r.values())}},5128:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isHudLfMarked=void 0,t.wrapLinkedFunction=function(e){if(e[t.isHudLfMarked])return e;let r;e[t.isHudLfMarked]=!0;const a=(0,i.g