UNPKG

hud-sdk

Version:

Hud's Node SDK

2 lines 14.1 kB
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var o=t();for(var n in o)("object"==typeof exports?exports:e)[n]=o[n]}}(global,()=>(()=>{"use strict";var e={820:function(e,t,o){var n=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var i=Object.getOwnPropertyDescriptor(t,o);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,i)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),i=this&&this.__exportStar||function(e,t){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(t,o)||n(t,e,o)};Object.defineProperty(t,"__esModule",{value:!0}),i(o(7764),t),i(o(4583),t),i(o(2314),t),i(o(1321),t),i(o(3764),t),i(o(2207),t),i(o(8714),t),i(o(2525),t),i(o(3973),t),i(o(1364),t),i(o(7398),t)},1321:function(e,t,o){var n=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var i=Object.getOwnPropertyDescriptor(t,o);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,i)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)"default"!==o&&Object.prototype.hasOwnProperty.call(e,o)&&n(t,e,o);return i(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.GraphQLDocumentMetadata=t.getDocumentsMetadata=void 0;const a=r(o(6982));t.getDocumentsMetadata=function(){const e=s;return s=[],e};let s=[];t.GraphQLDocumentMetadata=class{name;timeTook;hash;selectionNames;constructor(e,t){this.name=e.definitions[0]?.name?.value,this.hash=a.createHash("sha256").update(e.loc?.source?.body).digest("hex"),this.selectionNames=e.definitions.flatMap(e=>e.selectionSet.selections.map(e=>e.name.value)),this.timeTook=t}save(){s.push(this)}}},1364:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.validateAndGetUserInput=t.saveInstrumentationIndicator=t.saveHudRunningFromSetup=t.forceHudEnable=t.detachHud=t.clearUserIndicatorsTimeouts=t.clearInstrumentationIndicator=t.clearMetricsIndicator=t.clearInitGuard=t.hookMessageChannel=t.resetGlobals=t.initGlobals=void 0;const n=o(8528),i=o(2546),r=o(8167);function a(){globalThis.hudProcessedFiles=[],globalThis.huddBinWidth=i.hudConfig.huddBinWidth,globalThis._hud_S=new Array(1e3).fill(""),globalThis._hud_SI={value:0},globalThis.hudLoadedModules=[],globalThis.hudPatched=new Set,globalThis.HudSourceMapCache=new Map,globalThis.hudExpressState=[]}function s(){clearTimeout(globalThis.hudInitGuard),globalThis.hudInitGuard=void 0}function l(){clearTimeout(globalThis.hudMetricsIndicator),globalThis.hudMetricsIndicator=void 0}function u(){clearTimeout(globalThis.hudInstrumentationIndicator),globalThis.hudInstrumentationIndicator=void 0}function d(e=!0,t=!1){if(i.app_logger.warn("Detaching hud"),t||e&&hudRunningMode!==n.HudRunningMode.detached){const e=(0,i.getFirstError)();i.customer_logger.log(i.UserErrorLogs.ShutdownGracefully(e))}globalThis.hudRunningMode=n.HudRunningMode.detached}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.hudDeclarationsFound=!1,globalThis.hudStartTime=new Date,globalThis.hudCalls={},globalThis.hudRunningMode=n.HudRunningMode.enabled,globalThis.hudExtensionId=void 0,globalThis._hud_F="",globalThis.hudShouldLinkFunction=!1,globalThis.hudExecutionFlowMaxLength=i.hudConfig.investigation.limits.executionFlowMaxLength,globalThis.hudExceptionMaxLength=i.hudConfig.investigation.limits.exceptionMaxLength,globalThis.hudEnableInvestigation=i.hudConfig.dynamicConfig.enableInvestigation,function(){globalThis.hudSampleTable=[];const e=[[10,1],[30,2],[100,3],[500,11],[1e3,23],[5e3,53]];let t=0;for(const[o,n]of e){for(let e=t;e<o;e++)globalThis.hudSampleTable.push(e%n===0);t=o}}(),a())},t.resetGlobals=a,t.hookMessageChannel=function(){const{port1:e,port2:t}=new r.MessageChannel;return e.on("message",e=>{"HudModulePatch"===e.key?(globalThis.hudPatched.add(e.hudPatched),globalThis.hudProcessedFiles.push(e.hudProcessedFiles),globalThis.hudInstrumentationIndicator&&(u(),globalThis.hudDeclarationsFound=!0)):"HudRetrieveFileCache"===e.key&&globalThis.HudSourceMapCache.set(e.filename,e.content)}),e.unref(),globalThis.hudHookPort=e,t},t.clearInitGuard=s,t.clearMetricsIndicator=l,t.clearInstrumentationIndicator=u,t.clearUserIndicatorsTimeouts=function(){s(),l(),u()},t.detachHud=d,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 i.hudConfig.userConfig.key||i.hudConfig.userConfig.service?i.hudConfig.userConfig.key?(0,i.isValidParam)(i.hudConfig.userConfig.key.value)?i.hudConfig.userConfig.service?(0,i.isValidParam)(i.hudConfig.userConfig.service.value)?{apiKey:i.hudConfig.userConfig.key.value,service:i.hudConfig.userConfig.service.value}:(i.hudConfig.disableOnBadServiceName&&d(!1),void i.customer_logger.log(i.UserErrorLogs.HudServiceInvalid(i.hudConfig.userConfig.service.source))):(i.hudConfig.disableOnBadServiceName&&d(!1),void i.customer_logger.log(i.UserErrorLogs.HudServiceNotSet(globalThis.hudStartFromAutoInit))):(i.hudConfig.disableOnBadApiKey&&d(!1),void i.customer_logger.log(i.UserErrorLogs.HudApiKeyInvalid(i.hudConfig.userConfig.key.source))):(i.hudConfig.disableOnBadApiKey&&d(!1),void i.customer_logger.log(i.UserErrorLogs.HudApiKeyNotSet(globalThis.hudStartFromAutoInit))):((i.hudConfig.disableOnBadApiKey||i.hudConfig.disableOnBadServiceName)&&d(!1),void i.customer_logger.log(i.UserErrorLogs.BothApiKeyAndServiceNotSet(globalThis.hudStartFromAutoInit)))}},2207:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getResolverIdBySelectionName=t.storeResolverIdBySelectionName=void 0;const o=new Map;t.storeResolverIdBySelectionName=function(e,t){o.set(t,e)},t.getResolverIdBySelectionName=function(e){return o.get(e)}},2314:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.swapTempToConstFlowId=t.clearFlowIdMappings=t.linkTemporaryToConsistenFlowId=t.getFlowIdFromMappings=t.getLinkedConsistentFlowId=t.fullEndpointFlowIdMap=void 0;const n=o(2546),i=o(7930),r=o(8590);t.fullEndpointFlowIdMap=new Map;const a=new Map;function s(e,t){let o=l(e,!1);return o?o.flowId:(u(t),o=l(e,!0),o?(o.isPartial&&!t&&n.app_logger.warn("Found partial endpoint for flow id even though partial aren't allowd",{flowId:e,consistentFlowId:o.flowId}),o.flowId):void 0)}function l(e,o){let n=t.fullEndpointFlowIdMap.get(e);return n?{flowId:n,isPartial:!1}:o?(n=a.get(e),n?{flowId:n,isPartial:!0}:void 0):void 0}function u(e){const o=[];globalThis.hudExpressState.forEach(e=>{try{o.push(...(0,i.extractEndpointsFromRouter)("",e))}catch(e){n.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})}}),o.forEach(e=>{if(e.partial_path)return;const o=e.flow_id;let i=t.fullEndpointFlowIdMap.get(o);i||(i=(0,n.generateEndpointFlowId)(e.path,e.methods),t.fullEndpointFlowIdMap.set(o,i))}),(0,r.getPartialEndpointDeclarationsFromStorage)().forEach(o=>{const i=o.flow_id;let r=t.fullEndpointFlowIdMap.get(i);r||(r=a.get(i),r||(r=(0,n.generateEndpointFlowId)(o.partial_path,o.methods),e?a.set(i,r):t.fullEndpointFlowIdMap.set(i,r)))})}t.getLinkedConsistentFlowId=s,t.getFlowIdFromMappings=l,t.linkTemporaryToConsistenFlowId=u,t.clearFlowIdMappings=function(){t.fullEndpointFlowIdMap.clear(),a.clear()},t.swapTempToConstFlowId=function(e){e.forEach(e=>{"express"===e.framework&&(e.flow_id=s(e.flow_id,!0)??e.flow_id)})}},2433:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getKoaEndpointDeclarationsFromStorage=t.storeKoaEndpointDeclaration=void 0;let o=[];t.storeKoaEndpointDeclaration=function(e){o.push(e)},t.getKoaEndpointDeclarationsFromStorage=function(){const e=o;return o=[],e}},2525:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.storeSqsQueueDeclaration=t.getSqsQueues=void 0;let o=[];t.getSqsQueues=function(){const e=o;return o=[],e},t.storeSqsQueueDeclaration=function(e){o.push(e)}},2546:e=>{e.exports=require("./lib")},2987:e=>{e.exports=require("perf_hooks")},3764:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.storeResolverDeclaration=t.getResolversDeclarations=void 0;let o=[];t.getResolversDeclarations=function(){const e=o;return o=[],e},t.storeResolverDeclaration=function(e){o.push(e)}},3973:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.storeFlowMetric=t.getFlowMetrics=void 0;let o=[];t.getFlowMetrics=function(){const e=o;return o=[],e},t.storeFlowMetric=function(e){o.push(e)}},4583:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getExpressEndpointDeclarations=void 0;const n=o(2546),i=o(2314),r=o(7930),a=o(8590);t.getExpressEndpointDeclarations=function(){let e=[];globalThis.hudExpressState.forEach(t=>{try{e=e.concat((0,r.extractEndpointsFromRouter)("",t))}catch(e){n.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,a.getRouterlessEndpointDeclarationsFromStorage)());const t=new Set;e.forEach(e=>{e.partial_path||t.add(e.flow_id)});const o=e.filter(e=>!e.partial_path||!t.has(e.flow_id)&&(n.app_logger.info("Partial endpoint without full endpoint",{endpoint:e}),!0));return(0,i.swapTempToConstFlowId)(o),o}},6982:e=>{e.exports=require("crypto")},7398:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getLastMetrics=t.saveMachineMetric=t.getInvestigationDedupingCache=t.resetInvestigationDedupingCache=t.increaseInvestigationDedupingCache=t.increaseGlobalInvestigationTracking=t.setGlobalInvestigationTracking=t.globalInvestigationTracking=t.storeClosedInvestigation=t.getClosedInvestigations=void 0;const n=o(2546),i=o(2987);let r=[];t.getClosedInvestigations=function(){const e=r;return r=[],e},t.storeClosedInvestigation=function(e){r.push(e)},t.globalInvestigationTracking=0,t.setGlobalInvestigationTracking=function(e){t.globalInvestigationTracking=e},t.increaseGlobalInvestigationTracking=function(){t.globalInvestigationTracking++};const a=new Map;t.increaseInvestigationDedupingCache=function(e,t){const o=a.get(e)??new Map,n=(o.get(t)??0)+1;o.set(t,n),a.set(e,o)},t.resetInvestigationDedupingCache=function(){a.clear()},t.getInvestigationDedupingCache=function(e){return a.get(e)??new Map};const s=[];t.saveMachineMetric=function(){const e=process.cpuUsage(),t=i.performance.eventLoopUtilization();s.push({cpuUsage:e,elu:t,timestamp:Date.now()}),s.length>n.hudConfig.machineMetricsSavedLength&&s.shift()},t.getLastMetrics=function(){return s[0]}},7764:function(e,t,o){var n=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var i=Object.getOwnPropertyDescriptor(t,o);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,i)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),i=this&&this.__exportStar||function(e,t){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(t,o)||n(t,e,o)};Object.defineProperty(t,"__esModule",{value:!0}),i(o(8714),t),i(o(2433),t),i(o(1321),t),i(o(3764),t),i(o(2207),t),i(o(4583),t),i(o(8590),t)},7930:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.extractEndpointsFromRouter=void 0;const n=o(8528),i=o(2546);function r(e,t){const o=[];for(const[r,a]of Object.entries(e.route[i.hudConfig.express.layerStateSymbol]))o.push(new n.EndpointDeclaration(r,a.methods,"express",t,a.layerPath));return Array.from(o.values())}t.extractEndpointsFromRouter=function e(t,o){let n=[];const s="true"===process.env.HUD_LOG_EXPRESS;if(!o.stack)return i.app_logger.error("Router without stack - bad OTEL version",{router:o}),n;for(const l of o.stack)if("router"===l.name){if(!l[i.hudConfig.express.routeNamesSymbol]){i.app_logger.error("Router layer without routes",{layer:l});continue}const o=t+l[i.hudConfig.express.routeNamesSymbol];n=n.concat(e(o,l.handle))}else l.route&&l.route[i.hudConfig.express.layerStateSymbol]?n=n.concat(r(l,t)):s&&!a.has(l.name)&&(a.add(l.name),i.app_logger.warn("Found unknown layer name when extracting endpoints",{layer:l.name}));return n};const a=new Set(["query","expressInit","mounted_app"])},8167:e=>{e.exports=require("worker_threads")},8528:e=>{e.exports=require("./dto")},8590:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.storeExpressEndpointDeclaration=t.getPartialEndpointDeclarationsFromStorage=t.storePartialEndpointDeclaration=t.getRouterlessEndpointDeclarationsFromStorage=void 0;const n=o(2546),i=o(2314);let r=[];t.getRouterlessEndpointDeclarationsFromStorage=function(){const e=r;return r=[],e};let a=[];t.storePartialEndpointDeclaration=function(e){a.push(e)},t.getPartialEndpointDeclarationsFromStorage=function(){const e=a;return a=[],e},t.storeExpressEndpointDeclaration=function(e){if(!i.fullEndpointFlowIdMap.has(e.flow_id)){if(e.path){const t=(0,n.generateEndpointFlowId)(e.path,e.methods);i.fullEndpointFlowIdMap.set(e.flow_id,t)}r.push(e)}}},8714:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.storeKafkaJSTopicDeclaration=t.getKafkaJSTopics=void 0;let o=[];t.getKafkaJSTopics=function(){const e=o;return o=[],e},t.storeKafkaJSTopicDeclaration=function(e){o.push(e)}}},t={};return function o(n){var i=t[n];if(void 0!==i)return i.exports;var r=t[n]={exports:{}};return e[n].call(r.exports,r,r.exports,o),r.exports}(820)})()); //# sourceMappingURL=globalstate.js.map