hud-sdk 1.8.7 → 1.8.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(global,()=>(()=>{"use strict";var e={290:e=>{e.exports=require("async_hooks")},395:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.addReingestValue=function(e){n.add(e)},t.getAndClearReingestValues=function(){const e=new Set;for(const t of n)o.has(t)||e.add(t);for(const t of e)o.add(t);return n=new Set,e};let n=new Set;const o=new Set},523:e=>{e.exports=require("./logger")},754:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.storeEndpointDeclaration=function(e){n.push(e)},t.getEndpointDeclarationsFromStorage=function(){const e=n;return n=[],e};let n=[]},820:function(e,t,n){var o=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,r)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||o(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),r(n(3165),t),r(n(7764),t),r(n(4583),t),r(n(2314),t),r(n(3025),t),r(n(8714),t),r(n(4988),t),r(n(2525),t),r(n(3973),t),r(n(1757),t),r(n(1364),t),r(n(7398),t),r(n(8708),t),r(n(7918),t),r(n(395),t)},1364:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.initGlobals=function(){globalThis.hudGlobalInitGuard||(globalThis.hudGlobalInitGuard=!0,globalThis.hudRunMutex=!1,globalThis.hudRanOnRequire=!1,globalThis.hudRanOnImport=!1,globalThis.hudInitGuard=void 0,globalThis.hudInstrumentationIndicator=void 0,globalThis.hudMetricsIndicator=void 0,globalThis.hudInstrumentationOccured=!1,globalThis.hudNextJsPluginIndicator=void 0,globalThis.hudStartTime=new Date,globalThis.hudRunningMode=r.HudRunningMode.enabled,globalThis.hudExecutionFlowMaxLength=o.hudConfig.dynamicConfig.investigationRateLimits.executionFlowMaxLength,globalThis.hudExceptionMaxLength=o.hudConfig.dynamicConfig.investigationRateLimits.exceptionMaxLength,globalThis.hudEnableInvestigation=o.hudConfig.dynamicConfig.enableInvestigation,globalThis.hudEnableInvestigationArgsSending=o.hudConfig.dynamicConfig.enableInvestigationArgsSending,(0,a.setInvestigationStorage)(new u.AsyncLocalStorage),(0,a.setFlowStateStorage)(new u.AsyncLocalStorage),function(){globalThis.hudSampleTable=[];const e=[[10,1],[30,2],[100,3],[500,11],[1e3,23],[5e3,53]];let t=0;for(const[n,o]of e){for(let e=t;e<n;e++)globalThis.hudSampleTable.push(e%o===0);t=n}}(),l())},t.resetGlobals=l,t.hookMessageChannel=function(){const{port1:e,port2:t}=new c.MessageChannel;return e.on("message",e=>{"HudModulePatch"===e.key?(globalThis.hudPatched.add(e.hudPatched),globalThis.hudProcessedFiles.push(e.hudProcessedFiles)):"HudRetrieveFileCache"===e.key&&globalThis.HudSourceMapCache.set(e.filename,e.content)}),e.unref(),globalThis.hudHookPort=e,t},t.clearInitGuard=h,t.clearMetricsIndicator=g,t.clearInstrumentationIndicator=f,t.clearUserIndicatorsTimeouts=function(){h(),g(),f()},t.detachHud=p,t.forceHudEnable=function(){globalThis.forceHudEnable=!0},t.saveHudRunningFromSetup=function(){globalThis.hudIsRunningFromSetup=!0},t.saveInstrumentationIndicator=function(e){globalThis.hudInstrumentationIndicator=e,globalThis.hudInstrumentationIndicator.unref()},t.validateAndGetUserInput=function(){return o.hudConfig.userConfig.key||o.hudConfig.userConfig.service?o.hudConfig.userConfig.key?(0,o.isValidParam)(o.hudConfig.userConfig.key.value)?o.hudConfig.userConfig.service?(0,o.isValidParam)(o.hudConfig.userConfig.service.value)?{apiKey:o.hudConfig.userConfig.key.value,service:o.hudConfig.userConfig.service.value}:(s.app_logger.critical("Service name is invalid - SDK cannot initialize",{source:o.hudConfig.userConfig.service.source}),o.hudConfig.disableOnBadServiceName&&p(!1),void s.customer_logger.logEntry(i.UserErrorLogs.HudServiceInvalid(o.hudConfig.userConfig.service.source))):(s.app_logger.critical("Service name is missing - SDK cannot initialize"),o.hudConfig.disableOnBadServiceName&&p(!1),void s.customer_logger.logEntry(i.UserErrorLogs.HudServiceNotSet(globalThis.hudStartFromAutoInit))):(s.app_logger.critical("API key is invalid - SDK cannot initialize",{source:o.hudConfig.userConfig.key.source}),o.hudConfig.disableOnBadApiKey&&p(!1),void s.customer_logger.logEntry(i.UserErrorLogs.HudApiKeyInvalid(o.hudConfig.userConfig.key.source))):(s.app_logger.critical("API key is missing - SDK cannot initialize"),o.hudConfig.disableOnBadApiKey&&p(!1),void s.customer_logger.logEntry(i.UserErrorLogs.HudApiKeyNotSet(globalThis.hudStartFromAutoInit))):(s.app_logger.critical("Both API key and service name are missing - SDK cannot initialize"),(o.hudConfig.disableOnBadApiKey||o.hudConfig.disableOnBadServiceName)&&p(!1),void s.customer_logger.logEntry(i.UserErrorLogs.BothApiKeyAndServiceNotSet(globalThis.hudStartFromAutoInit)))};const o=n(5809),r=n(8528),i=n(2546),s=n(523),a=n(7131),u=n(290),c=n(8167),d=n(3165);function l(){globalThis.hudProcessedFiles=[],globalThis.hudStack=new Array(1e3).fill(""),globalThis.hudStackIndex={value:0},globalThis.hudStackPop=!1,globalThis.hudLoadedModules=[],globalThis.hudPatched=new Set,globalThis.HudSourceMapCache=new Map,globalThis.hudExpressState=[],globalThis.hudCalls={}}function h(){clearTimeout(globalThis.hudInitGuard),globalThis.hudInitGuard=void 0}function g(){clearTimeout(globalThis.hudMetricsIndicator),globalThis.hudMetricsIndicator=void 0}function f(){clearTimeout(globalThis.hudInstrumentationIndicator),globalThis.hudInstrumentationIndicator=void 0,globalThis.hudInstrumentationOccured=!0}function p(e=!0,t=!1){if(s.app_logger.warning("Detaching hud"),(0,d.getAsyncHook)()?.disable(),t||e&&hudRunningMode!==r.HudRunningMode.detached){const e=(0,i.getFirstError)();s.customer_logger.logEntry(i.UserErrorLogs.ShutdownGracefully(e))}globalThis.hudRunningMode=r.HudRunningMode.detached}},1757:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.markShouldFlushOnInit=function(e){r=e},t.storeCredentials=function(e,t){n=e,o=t},t.storeSessionInfo=function(e){i=e},t.getSessionInfo=function(){return i},t.getStoredApiKey=function(){return n},t.getStoredService=function(){return o},t.getShouldFlushOnInit=function(){return r};let n,o,r=!1,i=null},2314:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.fullEndpointFlowIdMap=void 0,t.getLinkedConsistentFlowId=u,t.getFlowIdFromMappings=c,t.linkTemporaryToConsistenFlowId=d,t.clearFlowIdMappings=function(){t.fullEndpointFlowIdMap.clear(),a.clear()},t.swapTempToConstFlowId=function(e){e.forEach(e=>{"express"===e.framework&&(e.flow_id=u(e.flow_id,!0)??e.flow_id)})};const o=n(2546),r=n(523),i=n(7930),s=n(8590);t.fullEndpointFlowIdMap=new Map;const a=new Map;function u(e,t){let n=c(e,!1);return n?n.flowId:(d(t),n=c(e,!0),n?(n.isPartial&&!t&&r.app_logger.warning("Found partial endpoint for flow id even though partial aren't allowd",{flowId:e,consistentFlowId:n.flowId}),n.flowId):void 0)}function c(e,n){let o=t.fullEndpointFlowIdMap.get(e);return o?{flowId:o,isPartial:!1}:n?(o=a.get(e),o?{flowId:o,isPartial:!0}:void 0):void 0}function d(e){const n=[];globalThis.hudExpressState.forEach(e=>{try{n.push(...(0,i.extractEndpointsFromRouter)("",e))}catch(e){r.app_logger.error("Failed to extract endpoints from express",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}),n.forEach(e=>{if(e.partial_path)return;const n=e.flow_id;let r=t.fullEndpointFlowIdMap.get(n);r||(r=(0,o.generateEndpointFlowId)(e.path,e.methods),t.fullEndpointFlowIdMap.set(n,r))}),(0,s.getPartialEndpointDeclarationsFromStorage)().forEach(n=>{const r=n.flow_id;let i=t.fullEndpointFlowIdMap.get(r);i||(i=a.get(r),i||(i=(0,o.generateEndpointFlowId)(n.partial_path,n.methods),e?a.set(r,i):t.fullEndpointFlowIdMap.set(r,i)))})}},2525:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getSqsQueues=function(){const e=n;return n=[],e},t.storeSqsQueueDeclaration=function(e){n.push(e)};let n=[]},2546:e=>{e.exports=require("./lib")},2987:e=>{e.exports=require("perf_hooks")},3025:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGraphQLOperations=function(){const e=n;return n={},e},t.storeGraphQLOperation=function(e){n[e.flow_id]||(n[e.flow_id]=e)};let n={}},3165:(e,t)=>{let n;Object.defineProperty(t,"__esModule",{value:!0}),t.getAsyncHook=function(){return n},t.setAsyncHook=function(e){n=e}},3973:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getFlowMetrics=function(e){const t=(new Date).toISOString(),n={};for(const o in a){const i=[];let s;for(const n in a[o]){const r=a[o][n];s||(s=r.getEventVersion()),i.push(r.finalize(u,t,e))}delete a[o],s?n[o]={eventVersion:s,metrics:i}:r.app_logger.error("No event version found for metric type",o)}return n},t.storeFlowMetric=function(e){const t=function(e){if(void 0!==e.flow_id)switch(e.type){case"EndpointMetric":{const t=e;return`${e.flow_id}|${t.method}|${t.status_code}`}case"KafkaJSMetric":{const t=e;return`${e.flow_id}|${t.partition}`}case"GraphQLMetric":{const t=e;return`${e.flow_id}|${t.status_code}`}default:return e.flow_id}}(e);if(!t)return;a[e.type]||(a[e.type]={});const n=a[e.type][t];if(n)n.update(e,u);else{const n=s.MetricFactory.createMetric(e,u);a[e.type][t]=n}};const o=n(5809),r=n(523),i=n(7131),s=n(7859),a={},u=new i.SketchManager(o.hudConfig.huddBinWidth)},4583:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getExpressEndpointDeclarations=function(){let e=[];globalThis.hudExpressState.forEach(t=>{try{e=e.concat((0,i.extractEndpointsFromRouter)("",t))}catch(e){o.app_logger.error("Failed to extract endpoints from express",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}),e=e.concat((0,s.getRouterlessEndpointDeclarationsFromStorage)());const t=new Set;e.forEach(e=>{e.partial_path||t.add(e.flow_id)});const n=e.filter(e=>!e.partial_path||!t.has(e.flow_id)&&(o.app_logger.info("Partial endpoint without full endpoint",{endpoint:e}),!0)),a=new Map;for(const e of n){const t=`${e.path||e.partial_path||""}|${[...e.methods].sort().join(",")}`;a.has(t)||a.set(t,e)}const u=Array.from(a.values());return(0,r.swapTempToConstFlowId)(u),u};const o=n(523),r=n(2314),i=n(7930),s=n(8590)},4988:function(e,t,n){var o,r=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,r)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),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||(o=function(e){return o=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},o(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n=o(e),s=0;s<n.length;s++)"default"!==n[s]&&r(t,e,n[s]);return i(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.pageManifest=t.apiManifest=void 0,t.setNextConfig=function(e){h=e,g=!0},t.getNextConfig=function(){return h},t.isNextConfigExtracted=function(){return g},t.extractNextEndpointDeclarations=async function(e){const n=[];if(!e)return n;d.worker_logger.info("Extracting next.js endpoint declarations in worker");const o=e.distDir,r=a.join(o,t.apiManifest),i=await(0,c.readFile)(r);if(i){const e=JSON.parse(i),t=await async function(e,t){const n=[];for(const o of Object.keys(t))if(o.endsWith("/route")){const r=a.join(e,"server",t[o]),i=await m(r),s=_(o,"/route");for(const e of i){const t=(0,c.generateEndpointFlowId)(s,[e]);n.push(new u.EndpointDeclaration(t,[e],"nextjs","",s))}}else if(o.endsWith("/page")){const e=["GET"],t=_(o,"/page"),r=(0,c.generateEndpointFlowId)(t,e);n.push(new u.EndpointDeclaration(r,e,"nextjs","",t))}else d.worker_logger.warning("Unknown Next.js manifest key type",{key:o});return n}(o,e);n.push(...t)}const s=a.join(o,t.pageManifest),h=await(0,c.readFile)(s);if(h){const e=JSON.parse(h),t=await async function(e,t){const n=[];for(const e of Object.keys(t))if(e.startsWith("/api/")){const t=(0,c.generateEndpointFlowId)(e,l);n.push(new u.EndpointDeclaration(t,l,"nextjs","",e))}else{const t=["GET"],o=(0,c.generateEndpointFlowId)(e,t);n.push(new u.EndpointDeclaration(o,t,"nextjs","",e))}return n}(0,e);n.push(...t)}return n};const a=s(n(6928)),u=n(8528),c=n(2546),d=n(523),l=["GET","POST","PUT","DELETE","PATCH","OPTIONS","HEAD"];let h;t.apiManifest="server/app-paths-manifest.json",t.pageManifest="server/pages-manifest.json";let g=!1;const f=new RegExp(`\\b(${l.join("|")})\\b`,"g");function p(e){const t=e.matchAll(f),n=Array.from(t,e=>e[1]);return Array.from(new Set(n))}async function m(e){const t=await(0,c.readFile)(e);return t?(n=t).includes('require("../../chunks/[turbopack]_runtime.js")')&&n.includes("R.c(")&&n.includes("R.m(")?async function(e,t){const n=function(e){if(!e.match(/R\.m\(\d+\)/))return null;const t=e.matchAll(/R\.c\("([^"]+)"\)/g);return{chunkPaths:Array.from(t,e=>e[1])}}(t);if(!n||0===n.chunkPaths.length)return[];const o=a.resolve(e,"..","..",".."),r=a.resolve(o,"..");let i="";for(const e of n.chunkPaths){const t=a.join(r,e),n=await(0,c.readFile)(t);n&&(i+=n)}return p(i)}(e,t):p(t):[];var n}function _(e,t){return e.length===t.length?"/":e.length>t.length?e.slice(0,0-t.length):e}},5809:e=>{e.exports=require("./config")},6928:e=>{e.exports=require("path")},7131:e=>{e.exports=require("./wrap")},7398:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.globalInvestigationTracking=void 0,t.getClosedInvestigations=function(){const e=i;return i=[],e},t.storeClosedInvestigation=function(e){globalThis.hudEnableInvestigation&&i.push(e)},t.setGlobalInvestigationTracking=function(e){t.globalInvestigationTracking=e},t.increaseGlobalInvestigationTracking=function(){t.globalInvestigationTracking++},t.getGlobalInvestigationTracking=function(){return t.globalInvestigationTracking},t.increaseInvestigationDedupingCache=function(e,t){const n=s.get(e)??new Map,o=(n.get(t)??0)+1;n.set(t,o),s.set(e,n)},t.resetInvestigationDedupingCache=function(){s.clear()},t.getInvestigationDedupingCache=function(e){return s.get(e)??new Map},t.saveMachineMetric=function(){const e=process.cpuUsage(),t=r.performance.eventLoopUtilization();a.push({cpuUsage:e,elu:t,timestamp:Date.now()}),a.length>o.hudConfig.machineMetricsSavedLength&&a.shift()},t.getLastMetrics=function(){return a[0]},t.setInvestigationDurationThresholds=function(e){u=e},t.getFlowIdDurationThresholdAndCount=function(e){return u[e]},t.increaseInvestigationDurationCount=function(e){const t=c.get(e)??0;c.set(e,t+1)},t.getInvestigationDurationCount=function(e){return c.get(e)??0},t.resetInvestigationDurationCounts=function(){c.clear()},t.increaseTotalInvestigationsErrorBased=function(){d++},t.getTotalInvestigationsErrorBased=function(){return d},t.resetTotalInvestigationsErrorBased=function(){d=0},t.increaseTotalInvestigationsDurationBased=function(){l++},t.getTotalInvestigationsDurationBased=function(){return l},t.resetTotalInvestigationsDurationBased=function(){l=0},t.getUniqueSetFailureErrors=function(){return h};const o=n(5809),r=n(2987);let i=[];t.globalInvestigationTracking=0;const s=new Map,a=[];let u={};const c=new Map;let d=0,l=0;const h=new Set},7764:function(e,t,n){var o=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,r)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||o(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),r(n(754),t),r(n(3025),t),r(n(8714),t),r(n(4988),t),r(n(4583),t),r(n(8590),t)},7859:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MetricFactory=t.BaseMetric=void 0;class n{}class o extends n{flowId;count;sumDuration;sumSquaredDuration;sketchBuilder;errorBreakdown;constructor(e,t){super(),this.flowId=e.flow_id,this.count=1,this.sumDuration=e.duration,this.sumSquaredDuration=e.duration**2,this.sketchBuilder=t.newSketchDataWithValue(e.duration),this.errorBreakdown=new Map,e.error_breakdown&&this.updateErrorBreakdown(e.error_breakdown)}getEventVersion(){return"1.0.0"}updateErrorBreakdown(e){let t=this.errorBreakdown.get(e.key);void 0===t&&(t={errors:e.errors,count:0,caught:e.caught,key:e.key,framework_result:e.framework_result,user_error:e.user_error},this.errorBreakdown.set(e.key,t)),t.count+=1}update(e,t){this.sumDuration+=e.duration,this.sumSquaredDuration+=e.duration**2,this.count+=1,t.add(this.sketchBuilder,e.duration),void 0!==e.error_breakdown&&this.updateErrorBreakdown(e.error_breakdown)}finalize(e,t,n){return{flow_id:this.flowId,count:this.count,sum_duration:this.sumDuration,sum_squared_duration:this.sumSquaredDuration,timestamp:t,timeslice:n,sketch:e.encode(this.sketchBuilder),error_breakdown:Array.from(this.errorBreakdown.values()).map(e=>({errors:e.errors,count:e.count,caught:e.caught,framework_result:e.framework_result,user_error:e.user_error}))}}}t.BaseMetric=o;class r{static registry={};static registerMetric(e,t){r.registry[e]=t}static createMetric(e,t){const n=r.registry[e.type];if(!n)throw new Error(`Unknown metric type: ${e.type}`);return new n(e,t)}}t.MetricFactory=r,r.registerMetric("EndpointMetric",class extends o{method;statusCode;errors;constructor(e,t){super(e,t),this.method=e.method,this.statusCode=e.status_code,this.errors={},e.error&&(this.errors[e.error]=(this.errors[e.error]??0)+1)}update(e,t){super.update(e,t),e.error&&(this.errors[e.error]=(this.errors[e.error]??0)+1)}getEventVersion(){return"2.0.0"}finalize(e,t,n){return{...super.finalize(e,t,n),method:this.method,status_code:this.statusCode,errors:this.errors}}}),r.registerMetric("GraphQLMetric",class extends o{statusCode;errorsCount;constructor(e,t){super(e,t),this.statusCode=e.status_code,this.errorsCount=e.error_occurred?1:0}update(e,t){super.update(e,t),this.errorsCount+=e.error_occurred?1:0}getEventVersion(){return"2.0.0"}finalize(e,t,n){return{...super.finalize(e,t,n),status_code:this.statusCode,errors_count:this.errorsCount}}}),r.registerMetric("KafkaJSMetric",class extends o{partition;errors;ConsumeSketchBuilder;sumConsumedDuration;sumSquaredConsumedDuration;constructor(e,t){super(e,t),this.partition=e.partition,this.errors={},e.error&&(this.errors[e.error]=(this.errors[e.error]??0)+1),e.total_consume_duration&&(this.ConsumeSketchBuilder=t.newSketchDataWithValue(e.total_consume_duration)),this.sumConsumedDuration=e.total_consume_duration??0,this.sumSquaredConsumedDuration=(e.total_consume_duration??0)**2}update(e,t){super.update(e,t),e.error&&(this.errors[e.error]=(this.errors[e.error]??0)+1),e.total_consume_duration&&(this.sumConsumedDuration+=e.total_consume_duration,this.sumSquaredConsumedDuration+=e.total_consume_duration**2,this.ConsumeSketchBuilder?t.add(this.ConsumeSketchBuilder,e.total_consume_duration):this.ConsumeSketchBuilder=t.newSketchDataWithValue(e.total_consume_duration))}getEventVersion(){return"2.0.0"}finalize(e,t,n){return{...super.finalize(e,t,n),partition:this.partition,errors:this.errors,sum_consumed_duration:this.sumConsumedDuration,sum_squared_consumed_duration:this.sumSquaredConsumedDuration,sketch_consume:e.encode(this.ConsumeSketchBuilder)}}}),r.registerMetric("SqsMetric",class extends o{msgCount;errors;e2eData;constructor(e,t){super(e,t),this.msgCount=e.msg_count,this.errors=e.errors,e.e2e_duration&&(this.e2eData={duration:e.e2e_duration,squaredDuration:e.e2e_duration**2,sketchBuilder:t.newSketchDataWithValue(e.e2e_duration)})}update(e,t){super.update(e,t),this.msgCount&&e.msg_count&&(this.msgCount+=e.msg_count),Object.entries(e.errors).forEach(([e,t])=>{this.errors[e]=(this.errors[e]??0)+t}),this.e2eData&&e.e2e_duration&&(this.e2eData.duration+=e.e2e_duration,this.e2eData.squaredDuration+=e.e2e_duration**2,t.add(this.e2eData.sketchBuilder,e.e2e_duration))}getEventVersion(){return"2.0.0"}finalize(e,t,n){return{...super.finalize(e,t,n),errors:this.errors,msg_count:this.msgCount,...this.e2eData?{e2e_sum_duration:this.e2eData.duration,e2e_sum_squared_duration:this.e2eData.squaredDuration,e2e_sketch:e.encode(this.e2eData.sketchBuilder)}:{}}}})},7918:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.storeLoadedOutbound=function(e){n.push(e)},t.getLoadedOutboundsFromStorage=function(){const e=n;return n=[],e},t.getIoredisFunctionId=function(e){return o.get(e)},t.storeIoredisCommand=function(e,t){o.has(e)||r.add(e),o.set(e,t)},t.getIoredisCommandsFromStorage=function(){const e=Array.from(r);return r=new Set,e};let n=[];const o=new Map;let r=new Set},7930:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.extractEndpointsFromRouter=function e(t,n){let r=[];const u="true"===process.env.HUD_LOG_EXPRESS;if(!n.stack)return i.app_logger.error("Router without stack - bad OTEL version",{router:n}),r;for(const c of n.stack)if("router"===c.name){if(!c[o.hudConfig.express.routeNamesSymbol]){i.app_logger.error("Router layer without routes",{layer:c});continue}const n=t+c[o.hudConfig.express.routeNamesSymbol];r=r.concat(e(n,c.handle))}else c.route&&c.route[o.hudConfig.express.layerStateSymbol]?r=r.concat(s(c,t)):u&&!a.has(c.name)&&(a.add(c.name),i.app_logger.warning("Found unknown layer name when extracting endpoints",{layer:c.name}));return r};const o=n(5809),r=n(8528),i=n(523);function s(e,t){const n=[];for(const[i,s]of Object.entries(e.route[o.hudConfig.express.layerStateSymbol]))n.push(new r.EndpointDeclaration(i,s.methods,"express",t,s.layerPath));return Array.from(n.values())}const a=new Set(["query","expressInit","mounted_app"])},8167:e=>{e.exports=require("worker_threads")},8528:e=>{e.exports=require("./dto")},8590:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getRouterlessEndpointDeclarationsFromStorage=function(){const e=i;return i=[],e},t.storePartialEndpointDeclaration=function(e){s.push(e)},t.getPartialEndpointDeclarationsFromStorage=function(){const e=s;return s=[],e},t.storeExpressEndpointDeclaration=function(e){if(!r.fullEndpointFlowIdMap.has(e.flow_id)){if(e.path){const t=(0,o.generateEndpointFlowId)(e.path,e.methods);r.fullEndpointFlowIdMap.set(e.flow_id,t)}i.push(e)}};const o=n(2546),r=n(2314);let i=[],s=[]},8708:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.setLambdaExtensionId=function(e){r&&o.app_logger.warning("Lambda extension id already set"),r=e},t.getLambdaExtensionId=function(){return r};const o=n(523);let r},8714:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getKafkaJSTopics=function(){const e=n;return n=[],e},t.storeKafkaJSTopicDeclaration=function(e){n.push(e)};let n=[]}},t={};return function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,n),i.exports}(820)})());
1
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(global,()=>(()=>{"use strict";var e={290:e=>{e.exports=require("async_hooks")},395:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.addReingestValue=function(e){n.add(e)},t.getAndClearReingestValues=function(){const e=new Set;for(const t of n)o.has(t)||e.add(t);for(const t of e)o.add(t);return n=new Set,e};let n=new Set;const o=new Set},523:e=>{e.exports=require("./logger")},754:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.storeEndpointDeclaration=function(e){n.push(e)},t.getEndpointDeclarationsFromStorage=function(){const e=n;return n=[],e};let n=[]},820:function(e,t,n){var o=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,r)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||o(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),r(n(3165),t),r(n(7764),t),r(n(4583),t),r(n(2314),t),r(n(3025),t),r(n(8714),t),r(n(4988),t),r(n(2525),t),r(n(3973),t),r(n(1757),t),r(n(1364),t),r(n(7398),t),r(n(8708),t),r(n(7918),t),r(n(395),t)},1364:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.initGlobals=function(){globalThis.hudGlobalInitGuard||(globalThis.hudGlobalInitGuard=!0,globalThis.hudRunMutex=!1,globalThis.hudRanOnRequire=!1,globalThis.hudRanOnImport=!1,globalThis.hudInitGuard=void 0,globalThis.hudInstrumentationIndicator=void 0,globalThis.hudMetricsIndicator=void 0,globalThis.hudInstrumentationOccured=!1,globalThis.hudNextJsPluginIndicator=void 0,globalThis.hudStartTime=new Date,globalThis.hudRunningMode=r.HudRunningMode.enabled,globalThis.hudExecutionFlowMaxLength=o.hudConfig.dynamicConfig.investigationRateLimits.executionFlowMaxLength,globalThis.hudExceptionMaxLength=o.hudConfig.dynamicConfig.investigationRateLimits.exceptionMaxLength,globalThis.hudEnableInvestigation=o.hudConfig.dynamicConfig.enableInvestigation,globalThis.hudEnableInvestigationArgsSending=o.hudConfig.dynamicConfig.enableInvestigationArgsSending,(0,a.setInvestigationStorage)(new u.AsyncLocalStorage),(0,a.setFlowStateStorage)(new u.AsyncLocalStorage),function(){globalThis.hudSampleTable=[];const e=[[10,1],[30,2],[100,3],[500,11],[1e3,23],[5e3,53]];let t=0;for(const[n,o]of e){for(let e=t;e<n;e++)globalThis.hudSampleTable.push(e%o===0);t=n}}(),l())},t.resetGlobals=l,t.hookMessageChannel=function(){const{port1:e,port2:t}=new c.MessageChannel;return e.on("message",e=>{"HudModulePatch"===e.key?(globalThis.hudPatched.add(e.hudPatched),globalThis.hudProcessedFiles.push(e.hudProcessedFiles)):"HudRetrieveFileCache"===e.key&&globalThis.HudSourceMapCache.set(e.filename,e.content)}),e.unref(),globalThis.hudHookPort=e,t},t.clearInitGuard=h,t.clearMetricsIndicator=g,t.clearInstrumentationIndicator=f,t.clearUserIndicatorsTimeouts=function(){h(),g(),f()},t.detachHud=p,t.forceHudEnable=function(){globalThis.forceHudEnable=!0},t.saveHudRunningFromSetup=function(){globalThis.hudIsRunningFromSetup=!0},t.saveInstrumentationIndicator=function(e){globalThis.hudInstrumentationIndicator=e,globalThis.hudInstrumentationIndicator.unref()},t.validateAndGetUserInput=function(){return o.hudConfig.userConfig.key||o.hudConfig.userConfig.service?o.hudConfig.userConfig.key?(0,o.isValidParam)(o.hudConfig.userConfig.key.value)?o.hudConfig.userConfig.service?(0,o.isValidParam)(o.hudConfig.userConfig.service.value)?{apiKey:o.hudConfig.userConfig.key.value,service:o.hudConfig.userConfig.service.value}:(s.app_logger.critical("Service name is invalid - SDK cannot initialize",{source:o.hudConfig.userConfig.service.source}),o.hudConfig.disableOnBadServiceName&&p(!1),void s.customer_logger.logEntry(i.UserErrorLogs.HudServiceInvalid(o.hudConfig.userConfig.service.source))):(s.app_logger.critical("Service name is missing - SDK cannot initialize"),o.hudConfig.disableOnBadServiceName&&p(!1),void s.customer_logger.logEntry(i.UserErrorLogs.HudServiceNotSet(globalThis.hudStartFromAutoInit))):(s.app_logger.critical("API key is invalid - SDK cannot initialize",{source:o.hudConfig.userConfig.key.source}),o.hudConfig.disableOnBadApiKey&&p(!1),void s.customer_logger.logEntry(i.UserErrorLogs.HudApiKeyInvalid(o.hudConfig.userConfig.key.source))):(s.app_logger.critical("API key is missing - SDK cannot initialize"),o.hudConfig.disableOnBadApiKey&&p(!1),void s.customer_logger.logEntry(i.UserErrorLogs.HudApiKeyNotSet(globalThis.hudStartFromAutoInit))):(s.app_logger.critical("Both API key and service name are missing - SDK cannot initialize"),(o.hudConfig.disableOnBadApiKey||o.hudConfig.disableOnBadServiceName)&&p(!1),void s.customer_logger.logEntry(i.UserErrorLogs.BothApiKeyAndServiceNotSet(globalThis.hudStartFromAutoInit)))};const o=n(5809),r=n(8528),i=n(2546),s=n(523),a=n(7131),u=n(290),c=n(8167),d=n(3165);function l(){globalThis.hudProcessedFiles=[],globalThis.hudStack=new Array(1e3).fill(""),globalThis.hudStackIndex={value:0},globalThis.hudStackPop=!1,globalThis.hudLoadedModules=[],globalThis.hudPatched=new Set,globalThis.HudSourceMapCache=new Map,globalThis.hudExpressState=[],globalThis.hudCalls={}}function h(){clearTimeout(globalThis.hudInitGuard),globalThis.hudInitGuard=void 0}function g(){clearTimeout(globalThis.hudMetricsIndicator),globalThis.hudMetricsIndicator=void 0}function f(){clearTimeout(globalThis.hudInstrumentationIndicator),globalThis.hudInstrumentationIndicator=void 0,globalThis.hudInstrumentationOccured=!0}function p(e=!0,t=!1){if(s.app_logger.warning("Detaching hud"),(0,d.getAsyncHook)()?.disable(),t||e&&hudRunningMode!==r.HudRunningMode.detached){const e=(0,i.getFirstError)();s.customer_logger.logEntry(i.UserErrorLogs.ShutdownGracefully(e))}globalThis.hudRunningMode=r.HudRunningMode.detached}},1757:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.markShouldFlushOnInit=function(e){r=e},t.storeCredentials=function(e,t){n=e,o=t},t.storeSessionInfo=function(e){i=e},t.getSessionInfo=function(){return i},t.getStoredApiKey=function(){return n},t.getStoredService=function(){return o},t.getShouldFlushOnInit=function(){return r};let n,o,r=!1,i=null},2314:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.fullEndpointFlowIdMap=void 0,t.getLinkedConsistentFlowId=u,t.getFlowIdFromMappings=c,t.linkTemporaryToConsistenFlowId=d,t.clearFlowIdMappings=function(){t.fullEndpointFlowIdMap.clear(),a.clear()},t.swapTempToConstFlowId=function(e){e.forEach(e=>{"express"===e.framework&&(e.flow_id=u(e.flow_id,!0)??e.flow_id)})};const o=n(2546),r=n(523),i=n(7930),s=n(8590);t.fullEndpointFlowIdMap=new Map;const a=new Map;function u(e,t){let n=c(e,!1);return n?n.flowId:(d(t),n=c(e,!0),n?(n.isPartial&&!t&&r.app_logger.warning("Found partial endpoint for flow id even though partial aren't allowd",{flowId:e,consistentFlowId:n.flowId}),n.flowId):void 0)}function c(e,n){let o=t.fullEndpointFlowIdMap.get(e);return o?{flowId:o,isPartial:!1}:n?(o=a.get(e),o?{flowId:o,isPartial:!0}:void 0):void 0}function d(e){const n=[];globalThis.hudExpressState.forEach(e=>{try{n.push(...(0,i.extractEndpointsFromRouter)("",e))}catch(e){r.app_logger.error("Failed to extract endpoints from express",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}),n.forEach(e=>{if(e.partial_path)return;const n=e.flow_id;let r=t.fullEndpointFlowIdMap.get(n);r||(r=(0,o.generateEndpointFlowId)(e.path,e.methods),t.fullEndpointFlowIdMap.set(n,r))}),(0,s.getPartialEndpointDeclarationsFromStorage)().forEach(n=>{const r=n.flow_id;let i=t.fullEndpointFlowIdMap.get(r);i||(i=a.get(r),i||(i=(0,o.generateEndpointFlowId)(n.partial_path,n.methods),e?a.set(r,i):t.fullEndpointFlowIdMap.set(r,i)))})}},2525:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getSqsQueues=function(){const e=n;return n=[],e},t.storeSqsQueueDeclaration=function(e){n.push(e)};let n=[]},2546:e=>{e.exports=require("./lib")},2987:e=>{e.exports=require("perf_hooks")},3025:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGraphQLOperations=function(){const e=n;return n={},e},t.storeGraphQLOperation=function(e){n[e.flow_id]||(n[e.flow_id]=e)};let n={}},3165:(e,t)=>{let n;Object.defineProperty(t,"__esModule",{value:!0}),t.getAsyncHook=function(){return n},t.setAsyncHook=function(e){n=e}},3973:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getFlowMetrics=function(e){const t=(new Date).toISOString(),n={};for(const o in a){const i=[];let s;for(const n in a[o]){const r=a[o][n];s||(s=r.getEventVersion()),i.push(r.finalize(u,t,e))}delete a[o],s?n[o]={eventVersion:s,metrics:i}:r.app_logger.error("No event version found for metric type",o)}return n},t.storeFlowMetric=function(e){const t=function(e){if(void 0!==e.flow_id)switch(e.type){case"EndpointMetric":{const t=e;return`${e.flow_id}|${t.method}|${t.status_code??""}|${t.end_reason??""}`}case"KafkaJSMetric":{const t=e;return`${e.flow_id}|${t.partition}`}case"GraphQLMetric":{const t=e;return`${e.flow_id}|${t.status_code}`}default:return e.flow_id}}(e);if(!t)return;a[e.type]||(a[e.type]={});const n=a[e.type][t];if(n)n.update(e,u);else{const n=s.MetricFactory.createMetric(e,u);a[e.type][t]=n}};const o=n(5809),r=n(523),i=n(7131),s=n(7859),a={},u=new i.SketchManager(o.hudConfig.huddBinWidth)},4583:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getExpressEndpointDeclarations=function(){let e=[];globalThis.hudExpressState.forEach(t=>{try{e=e.concat((0,i.extractEndpointsFromRouter)("",t))}catch(e){o.app_logger.error("Failed to extract endpoints from express",{msg:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}),e=e.concat((0,s.getRouterlessEndpointDeclarationsFromStorage)());const t=new Set;e.forEach(e=>{e.partial_path||t.add(e.flow_id)});const n=e.filter(e=>!e.partial_path||!t.has(e.flow_id)&&(o.app_logger.info("Partial endpoint without full endpoint",{endpoint:e}),!0)),a=new Map;for(const e of n){const t=`${e.path||e.partial_path||""}|${[...e.methods].sort().join(",")}`;a.has(t)||a.set(t,e)}const u=Array.from(a.values());return(0,r.swapTempToConstFlowId)(u),u};const o=n(523),r=n(2314),i=n(7930),s=n(8590)},4988:function(e,t,n){var o,r=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,r)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),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||(o=function(e){return o=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},o(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n=o(e),s=0;s<n.length;s++)"default"!==n[s]&&r(t,e,n[s]);return i(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.pageManifest=t.apiManifest=void 0,t.setNextConfig=function(e){h=e,g=!0},t.getNextConfig=function(){return h},t.isNextConfigExtracted=function(){return g},t.extractNextEndpointDeclarations=async function(e){const n=[];if(!e)return n;d.worker_logger.info("Extracting next.js endpoint declarations in worker");const o=e.distDir,r=a.join(o,t.apiManifest),i=await(0,c.readFile)(r);if(i){const e=JSON.parse(i),t=await async function(e,t){const n=[];for(const o of Object.keys(t))if(o.endsWith("/route")){const r=a.join(e,"server",t[o]),i=await m(r),s=_(o,"/route");for(const e of i){const t=(0,c.generateEndpointFlowId)(s,[e]);n.push(new u.EndpointDeclaration(t,[e],"nextjs","",s))}}else if(o.endsWith("/page")){const e=["GET"],t=_(o,"/page"),r=(0,c.generateEndpointFlowId)(t,e);n.push(new u.EndpointDeclaration(r,e,"nextjs","",t))}else d.worker_logger.warning("Unknown Next.js manifest key type",{key:o});return n}(o,e);n.push(...t)}const s=a.join(o,t.pageManifest),h=await(0,c.readFile)(s);if(h){const e=JSON.parse(h),t=await async function(e,t){const n=[];for(const e of Object.keys(t))if(e.startsWith("/api/")){const t=(0,c.generateEndpointFlowId)(e,l);n.push(new u.EndpointDeclaration(t,l,"nextjs","",e))}else{const t=["GET"],o=(0,c.generateEndpointFlowId)(e,t);n.push(new u.EndpointDeclaration(o,t,"nextjs","",e))}return n}(0,e);n.push(...t)}return n};const a=s(n(6928)),u=n(8528),c=n(2546),d=n(523),l=["GET","POST","PUT","DELETE","PATCH","OPTIONS","HEAD"];let h;t.apiManifest="server/app-paths-manifest.json",t.pageManifest="server/pages-manifest.json";let g=!1;const f=new RegExp(`\\b(${l.join("|")})\\b`,"g");function p(e){const t=e.matchAll(f),n=Array.from(t,e=>e[1]);return Array.from(new Set(n))}async function m(e){const t=await(0,c.readFile)(e);return t?(n=t).includes('require("../../chunks/[turbopack]_runtime.js")')&&n.includes("R.c(")&&n.includes("R.m(")?async function(e,t){const n=function(e){if(!e.match(/R\.m\(\d+\)/))return null;const t=e.matchAll(/R\.c\("([^"]+)"\)/g);return{chunkPaths:Array.from(t,e=>e[1])}}(t);if(!n||0===n.chunkPaths.length)return[];const o=a.resolve(e,"..","..",".."),r=a.resolve(o,"..");let i="";for(const e of n.chunkPaths){const t=a.join(r,e),n=await(0,c.readFile)(t);n&&(i+=n)}return p(i)}(e,t):p(t):[];var n}function _(e,t){return e.length===t.length?"/":e.length>t.length?e.slice(0,0-t.length):e}},5809:e=>{e.exports=require("./config")},6928:e=>{e.exports=require("path")},7131:e=>{e.exports=require("./wrap")},7398:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.globalInvestigationTracking=void 0,t.getClosedInvestigations=function(){const e=i;return i=[],e},t.storeClosedInvestigation=function(e){globalThis.hudEnableInvestigation&&i.push(e)},t.setGlobalInvestigationTracking=function(e){t.globalInvestigationTracking=e},t.increaseGlobalInvestigationTracking=function(){t.globalInvestigationTracking++},t.getGlobalInvestigationTracking=function(){return t.globalInvestigationTracking},t.increaseInvestigationDedupingCache=function(e,t){const n=s.get(e)??new Map,o=(n.get(t)??0)+1;n.set(t,o),s.set(e,n)},t.resetInvestigationDedupingCache=function(){s.clear()},t.getInvestigationDedupingCache=function(e){return s.get(e)??new Map},t.saveMachineMetric=function(){const e=process.cpuUsage(),t=r.performance.eventLoopUtilization();a.push({cpuUsage:e,elu:t,timestamp:Date.now()}),a.length>o.hudConfig.machineMetricsSavedLength&&a.shift()},t.getLastMetrics=function(){return a[0]},t.setInvestigationDurationThresholds=function(e){u=e},t.getFlowIdDurationThresholdAndCount=function(e){return u[e]},t.increaseInvestigationDurationCount=function(e){const t=c.get(e)??0;c.set(e,t+1)},t.getInvestigationDurationCount=function(e){return c.get(e)??0},t.resetInvestigationDurationCounts=function(){c.clear()},t.increaseTotalInvestigationsErrorBased=function(){d++},t.getTotalInvestigationsErrorBased=function(){return d},t.resetTotalInvestigationsErrorBased=function(){d=0},t.increaseTotalInvestigationsDurationBased=function(){l++},t.getTotalInvestigationsDurationBased=function(){return l},t.resetTotalInvestigationsDurationBased=function(){l=0},t.getUniqueSetFailureErrors=function(){return h};const o=n(5809),r=n(2987);let i=[];t.globalInvestigationTracking=0;const s=new Map,a=[];let u={};const c=new Map;let d=0,l=0;const h=new Set},7764:function(e,t,n){var o=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,r)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||o(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),r(n(754),t),r(n(3025),t),r(n(8714),t),r(n(4988),t),r(n(4583),t),r(n(8590),t)},7859:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MetricFactory=t.BaseMetric=void 0;class n{}class o extends n{flowId;count;sumDuration;sumSquaredDuration;sketchBuilder;errorBreakdown;constructor(e,t){super(),this.flowId=e.flow_id,this.count=1,this.sumDuration=e.duration,this.sumSquaredDuration=e.duration**2,this.sketchBuilder=t.newSketchDataWithValue(e.duration),this.errorBreakdown=new Map,e.error_breakdown&&this.updateErrorBreakdown(e.error_breakdown)}getEventVersion(){return"1.0.0"}updateErrorBreakdown(e){let t=this.errorBreakdown.get(e.key);void 0===t&&(t={errors:e.errors,count:0,caught:e.caught,key:e.key,framework_result:e.framework_result,user_error:e.user_error},this.errorBreakdown.set(e.key,t)),t.count+=1}update(e,t){this.sumDuration+=e.duration,this.sumSquaredDuration+=e.duration**2,this.count+=1,t.add(this.sketchBuilder,e.duration),void 0!==e.error_breakdown&&this.updateErrorBreakdown(e.error_breakdown)}finalize(e,t,n){return{flow_id:this.flowId,count:this.count,sum_duration:this.sumDuration,sum_squared_duration:this.sumSquaredDuration,timestamp:t,timeslice:n,sketch:e.encode(this.sketchBuilder),error_breakdown:Array.from(this.errorBreakdown.values()).map(e=>({errors:e.errors,count:e.count,caught:e.caught,framework_result:e.framework_result,user_error:e.user_error}))}}}t.BaseMetric=o;class r{static registry={};static registerMetric(e,t){r.registry[e]=t}static createMetric(e,t){const n=r.registry[e.type];if(!n)throw new Error(`Unknown metric type: ${e.type}`);return new n(e,t)}}t.MetricFactory=r,r.registerMetric("EndpointMetric",class extends o{method;statusCode;errors;endReason;constructor(e,t){super(e,t),this.method=e.method,this.statusCode=e.status_code,this.endReason=e.end_reason,this.errors={},e.error&&(this.errors[e.error]=(this.errors[e.error]??0)+1)}update(e,t){super.update(e,t),e.error&&(this.errors[e.error]=(this.errors[e.error]??0)+1)}getEventVersion(){return"2.0.1"}finalize(e,t,n){return{...super.finalize(e,t,n),method:this.method,...void 0!==this.statusCode?{status_code:this.statusCode}:{},errors:this.errors,...void 0!==this.endReason?{end_reason:this.endReason}:{}}}}),r.registerMetric("GraphQLMetric",class extends o{statusCode;errorsCount;constructor(e,t){super(e,t),this.statusCode=e.status_code,this.errorsCount=e.error_occurred?1:0}update(e,t){super.update(e,t),this.errorsCount+=e.error_occurred?1:0}getEventVersion(){return"2.0.0"}finalize(e,t,n){return{...super.finalize(e,t,n),status_code:this.statusCode,errors_count:this.errorsCount}}}),r.registerMetric("KafkaJSMetric",class extends o{partition;errors;ConsumeSketchBuilder;sumConsumedDuration;sumSquaredConsumedDuration;constructor(e,t){super(e,t),this.partition=e.partition,this.errors={},e.error&&(this.errors[e.error]=(this.errors[e.error]??0)+1),e.total_consume_duration&&(this.ConsumeSketchBuilder=t.newSketchDataWithValue(e.total_consume_duration)),this.sumConsumedDuration=e.total_consume_duration??0,this.sumSquaredConsumedDuration=(e.total_consume_duration??0)**2}update(e,t){super.update(e,t),e.error&&(this.errors[e.error]=(this.errors[e.error]??0)+1),e.total_consume_duration&&(this.sumConsumedDuration+=e.total_consume_duration,this.sumSquaredConsumedDuration+=e.total_consume_duration**2,this.ConsumeSketchBuilder?t.add(this.ConsumeSketchBuilder,e.total_consume_duration):this.ConsumeSketchBuilder=t.newSketchDataWithValue(e.total_consume_duration))}getEventVersion(){return"2.0.0"}finalize(e,t,n){return{...super.finalize(e,t,n),partition:this.partition,errors:this.errors,sum_consumed_duration:this.sumConsumedDuration,sum_squared_consumed_duration:this.sumSquaredConsumedDuration,sketch_consume:e.encode(this.ConsumeSketchBuilder)}}}),r.registerMetric("SqsMetric",class extends o{msgCount;errors;e2eData;constructor(e,t){super(e,t),this.msgCount=e.msg_count,this.errors=e.errors,e.e2e_duration&&(this.e2eData={duration:e.e2e_duration,squaredDuration:e.e2e_duration**2,sketchBuilder:t.newSketchDataWithValue(e.e2e_duration)})}update(e,t){super.update(e,t),this.msgCount&&e.msg_count&&(this.msgCount+=e.msg_count),Object.entries(e.errors).forEach(([e,t])=>{this.errors[e]=(this.errors[e]??0)+t}),this.e2eData&&e.e2e_duration&&(this.e2eData.duration+=e.e2e_duration,this.e2eData.squaredDuration+=e.e2e_duration**2,t.add(this.e2eData.sketchBuilder,e.e2e_duration))}getEventVersion(){return"2.0.0"}finalize(e,t,n){return{...super.finalize(e,t,n),errors:this.errors,msg_count:this.msgCount,...this.e2eData?{e2e_sum_duration:this.e2eData.duration,e2e_sum_squared_duration:this.e2eData.squaredDuration,e2e_sketch:e.encode(this.e2eData.sketchBuilder)}:{}}}})},7918:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.storeLoadedOutbound=function(e){n.push(e)},t.getLoadedOutboundsFromStorage=function(){const e=n;return n=[],e},t.getIoredisFunctionId=function(e){return o.get(e)},t.storeIoredisCommand=function(e,t){o.has(e)||r.add(e),o.set(e,t)},t.getIoredisCommandsFromStorage=function(){const e=Array.from(r);return r=new Set,e};let n=[];const o=new Map;let r=new Set},7930:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.extractEndpointsFromRouter=function e(t,n){let r=[];const u="true"===process.env.HUD_LOG_EXPRESS;if(!n.stack)return i.app_logger.error("Router without stack - bad OTEL version",{router:n}),r;for(const c of n.stack)if("router"===c.name){if(!c[o.hudConfig.express.routeNamesSymbol]){i.app_logger.error("Router layer without routes",{layer:c});continue}const n=t+c[o.hudConfig.express.routeNamesSymbol];r=r.concat(e(n,c.handle))}else c.route&&c.route[o.hudConfig.express.layerStateSymbol]?r=r.concat(s(c,t)):u&&!a.has(c.name)&&(a.add(c.name),i.app_logger.warning("Found unknown layer name when extracting endpoints",{layer:c.name}));return r};const o=n(5809),r=n(8528),i=n(523);function s(e,t){const n=[];for(const[i,s]of Object.entries(e.route[o.hudConfig.express.layerStateSymbol]))n.push(new r.EndpointDeclaration(i,s.methods,"express",t,s.layerPath));return Array.from(n.values())}const a=new Set(["query","expressInit","mounted_app"])},8167:e=>{e.exports=require("worker_threads")},8528:e=>{e.exports=require("./dto")},8590:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getRouterlessEndpointDeclarationsFromStorage=function(){const e=i;return i=[],e},t.storePartialEndpointDeclaration=function(e){s.push(e)},t.getPartialEndpointDeclarationsFromStorage=function(){const e=s;return s=[],e},t.storeExpressEndpointDeclaration=function(e){if(!r.fullEndpointFlowIdMap.has(e.flow_id)){if(e.path){const t=(0,o.generateEndpointFlowId)(e.path,e.methods);r.fullEndpointFlowIdMap.set(e.flow_id,t)}i.push(e)}};const o=n(2546),r=n(2314);let i=[],s=[]},8708:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.setLambdaExtensionId=function(e){r&&o.app_logger.warning("Lambda extension id already set"),r=e},t.getLambdaExtensionId=function(){return r};const o=n(523);let r},8714:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getKafkaJSTopics=function(){const e=n;return n=[],e},t.storeKafkaJSTopicDeclaration=function(e){n.push(e)};let n=[]}},t={};return function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,n),i.exports}(820)})());
2
2
  //# sourceMappingURL=globalstate.js.map