UNPKG

hud-sdk

Version:

Hud's Node SDK

2 lines 18.5 kB
!function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var o=r();for(var t in o)("object"==typeof exports?exports:e)[t]=o[t]}}(global,(()=>(()=>{"use strict";var e={523:e=>{e.exports=require("./logger")},1019:function(e,r,o){var t=this&&this.__createBinding||(Object.create?function(e,r,o,t){void 0===t&&(t=o);var n=Object.getOwnPropertyDescriptor(r,o);n&&!("get"in n?!r.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return r[o]}}),Object.defineProperty(e,t,n)}:function(e,r,o,t){void 0===t&&(t=o),e[t]=r[o]}),n=this&&this.__exportStar||function(e,r){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(r,o)||t(r,e,o)},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0});const a=i(o(5809));n(o(5809),r),r.default=a.default},1377:function(e,r,o){var t=this&&this.__createBinding||(Object.create?function(e,r,o,t){void 0===t&&(t=o);var n=Object.getOwnPropertyDescriptor(r,o);n&&!("get"in n?!r.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return r[o]}}),Object.defineProperty(e,t,n)}:function(e,r,o,t){void 0===t&&(t=o),e[t]=r[o]}),n=this&&this.__exportStar||function(e,r){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(r,o)||t(r,e,o)};Object.defineProperty(r,"__esModule",{value:!0}),n(o(523),r)},2826:function(e,r,o){var t=this&&this.__createBinding||(Object.create?function(e,r,o,t){void 0===t&&(t=o);var n=Object.getOwnPropertyDescriptor(r,o);n&&!("get"in n?!r.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return r[o]}}),Object.defineProperty(e,t,n)}:function(e,r,o,t){void 0===t&&(t=o),e[t]=r[o]}),n=this&&this.__exportStar||function(e,r){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(r,o)||t(r,e,o)};Object.defineProperty(r,"__esModule",{value:!0}),n(o(8841),r)},5809:e=>{e.exports=require("./config")},6928:e=>{e.exports=require("path")},7669:e=>{e.exports=require("./index")},8167:e=>{e.exports=require("worker_threads")},8841:function(e,r,o){var t=this&&this.__createBinding||(Object.create?function(e,r,o,t){void 0===t&&(t=o);var n=Object.getOwnPropertyDescriptor(r,o);n&&!("get"in n?!r.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return r[o]}}),Object.defineProperty(e,t,n)}:function(e,r,o,t){void 0===t&&(t=o),e[t]=r[o]}),n=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var o in e)"default"!==o&&Object.prototype.hasOwnProperty.call(e,o)&&t(r,e,o);return n(r,e),r};Object.defineProperty(r,"__esModule",{value:!0}),r.noopInit=r.noop=r.getConfigContent=r.HudFailedReadConfigError=r.isHudEnabled=void 0;const a=i(o(9896)),s=i(o(6928));r.isHudEnabled=function(e,r){if("false"===process.env.HUD_ENABLE)return!1;if(globalThis.forceHudEnable)return!0;let o,t;try{if(o=l(),o&&(t=JSON.parse(o.content),!1===t.enable))return!1}catch(t){throw t instanceof d&&"EACCES"===t.code?r(t.path):o&&e(o.source,t instanceof Error?t.message:void 0),t}return"true"===process.env.HUD_ENABLE||!0===t?.enable};class d extends Error{path;code;constructor(e,r){super(),this.path=e,this.code=r}}function l(){if(process.env.HUD_CONFIG)return{content:process.env.HUD_CONFIG,source:"HUD_CONFIG"};const e=function(){try{const e=process.env.HUD_CONFIG_PATH;if(e)return a.existsSync(e)?e:void 0;let r=__dirname,o=0;for(;"/"!==r&&o<10;){const e=`${r}/hud.config`;if(a.existsSync(e))return e;r=s.dirname(r),o++}}catch(e){return}}();if(e)try{return{content:a.readFileSync(e,"utf8"),source:e}}catch(r){throw new d(e,r.code)}}r.HudFailedReadConfigError=d,r.getConfigContent=l,r.noop=function(...e){},r.noopInit=async function(e,r,o){}},9514:function(e,r,o){var t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0}),r.getNetworkError=r.UserErrorLogs=r.setFirstError=r.getFirstError=r.isAbortError=r.HudFailExtractSqsQueueName=r.HudNoCallbackInSqsConsumerOn=r.HudNoEventTypeInSqsConsumerOn=r.HudNoQueueUrlInSqsConsumer=r.HudSqsError=r.HudExtensionNextFailedError=r.HudExtensionRegisterError=r.HudExtnensionError=r.HudBadLoggerError=r.HudInitNetworkError=r.HudTsNodeNotFoundButUsed=r.HudSessionThrottle=r.HudNoTranspileOnlyError=r.HudClientExceededMaxRetries=r.HudClientUnauthorizedError=r.HudTimeoutError=r.HudWorkloadCollectorError=r.HudAssert=r.HudUnsupportedError=r.HudEditError=r.HudWorkerError=r.HudClientError=r.HudInitError=r.HudError=void 0;const n=t(o(1019));class i extends Error{code=9e3;name=this.constructor.name;constructor(e){super(e)}}r.HudError=i;class a extends i{code=9001}r.HudInitError=a,r.HudClientError=class extends i{code=9002;originalAxiosErrorCode;constructor(e,r){super(e),this.originalAxiosErrorCode=r}},r.HudWorkerError=class extends i{code=9003};class s extends i{code=9004}r.HudEditError=s,r.HudUnsupportedError=class extends s{code=9005},r.HudAssert=class extends s{code=9006},r.HudWorkloadCollectorError=class extends i{code=9007},r.HudTimeoutError=class extends i{code=9008},r.HudClientUnauthorizedError=class extends i{code=9009},r.HudClientExceededMaxRetries=class extends i{code=9010},r.HudNoTranspileOnlyError=class extends i{code=9011},r.HudSessionThrottle=class extends a{code=9012},r.HudTsNodeNotFoundButUsed=class extends i{code=9013},r.HudInitNetworkError=class extends i{code=9014;originalAxiosErrorCode;constructor(e,r){super(e),this.originalAxiosErrorCode=r}},r.HudBadLoggerError=class extends i{code=9101};class d extends i{code=9200}r.HudExtnensionError=d,r.HudExtensionRegisterError=class extends d{code=9201},r.HudExtensionNextFailedError=class extends d{code=9202};class l extends i{code=9250}r.HudSqsError=l,r.HudNoQueueUrlInSqsConsumer=class extends l{code=9251},r.HudNoEventTypeInSqsConsumerOn=class extends l{code=9252},r.HudNoCallbackInSqsConsumerOn=class extends l{code=9253},r.HudFailExtractSqsQueueName=class extends l{code=9254},r.isAbortError=function(e){return e instanceof Error&&"AbortError"===e.name};let u=9999;r.getFirstError=function(){return u},r.setFirstError=function(e){e&&9999===u&&(u=e)},r.UserErrorLogs={HudServiceNotSet:()=>({level:"error",errCode:"E1001",moreInfo:!0,message:"Can't load Hud, HUD_SERVICE was not set. Please set service name using the environment variable HUD_SERVICE."}),HudServiceInvalid:()=>({level:"error",errCode:"E1002",moreInfo:!0,message:"Can't load Hud, HUD_SERVICE value has invalid service name. Please set service name using the environment variable HUD_SERVICE."}),HudApiKeyNotSet:()=>({level:"error",errCode:"E1004",moreInfo:!0,message:"Can't load Hud, HUD_KEY was not set. Please set API key using the environment variable HUD_KEY."}),HudApiKeyInvalid:()=>({level:"error",errCode:"E1005",moreInfo:!0,message:"Can't load Hud, HUD_KEY value has invalid API key. Please set a valid key in environment variable HUD_KEY."}),BothApiKeyAndServiceNotSet:()=>({level:"error",errCode:"E1007",moreInfo:!0,message:"Can't load Hud, HUD_KEY and HUD_SERVICE were not set. Please set API key using the environment variable HUD_KEY and service name using the environment variable HUD_SERVICE."}),InvalidTag:()=>({level:"warn",errCode:"E1008",moreInfo:!0,message:"HUD_TAGS should be of type Key-Value Object, defaulting to empty tags. Please set valid tags in environment variable HUD_TAGS."}),TagWithDots:()=>({level:"warn",errCode:"E1009",moreInfo:!0,message:"HUD_TAGS keys can't contain dots; they have been replaced with underscores."}),TagsInvalidJson:()=>({level:"warn",errCode:"E1010",moreInfo:!0,message:"Can't load Hud, HUD_TAGS is not a valid JSON, defaulting to empty tags. Please set valid tags in environment variable HUD_TAGS."}),ApiKeyDenied:e=>({level:"error",errCode:"E1011",moreInfo:!0,message:`Can't load Hud, the provided key is invalid. Please provide a valid HUD_KEY in your ${{ENV:"environment variable",CONFIG_FILE:"file",CONFIG_ENV:"HUD_CONFIG",INIT:"init function",SETUP:"setup function"}[e]}.`}),ShutdownGracefully:e=>({level:"error",errCode:`E${e}`,message:"SDK has initiated a graceful shutdown. Your application remains unaffected"}),UnsupportedNodeVersion:()=>({level:"error",errCode:"E1012",moreInfo:!0,message:"Can't load Hud due to an unsupported node version."}),UnsupportedSyntax:()=>({level:"error",errCode:"E1014",moreInfo:!0,message:"Can't load Hud due to an unsupported syntax version."}),UnsupportedLambdaMemory:()=>({level:"error",errCode:"E1015",moreInfo:!0,message:`Can't load Hud as lambda function memory size is less than ${n.default.lambdaMinimunMemory}MB.`}),JSONErrorInUserConfig:(e,r)=>({level:"error",errCode:"E1016",moreInfo:!0,message:`Can't load Hud, the config file contains an invalid JSON. Please set a valid json in Hud's config ${e}`+(r?`, Error: ${r}.`:".")}),ZodErrorInUserConfig:(e,r)=>({level:"error",errCode:"E1017",moreInfo:!0,message:`Can't load Hud, the config file contains an invalid value for field: ${r}. Please set a valid value for ${r} in the config ${e}.`}),ConfigInaccessible:e=>({level:"error",errCode:"E1018",moreInfo:!0,message:`Can't load Hud, the config file is inaccessible. Please make sure your node application has read permissions to the Hud config file, ${e}.`}),SetupCalledWithoutKey:()=>({level:"error",errCode:"E1019",moreInfo:!0,message:"API key not found or invalid. SDK has initiated a graceful shutdown. Your application remains unaffected."}),SetupCalledWithoutService:()=>({level:"error",errCode:"E1020",moreInfo:!0,message:"Service name parameter not found or invalid. SDK has initiated a graceful shutdown. Your application remains unaffected."}),HudEnableIsFalse:()=>({level:"warn",errCode:"E1021",moreInfo:!0,message:"HUD_ENABLE is set to false. SDK has initiated a graceful shutdown. Your application remains unaffected."}),InstrumentedFunctionCountExceeded:e=>({level:"error",errCode:"E1022",moreInfo:!0,message:`SDK limit of ${e} instrumented functions exceeded. SDK has initiated a graceful shutdown. Your application remains unaffected.`}),PodMemoryLimitTooLow:e=>({level:"error",errCode:"E1023",moreInfo:!0,message:`Insufficient memory available. Minimum required:(${e}MB). SDK has initiated a graceful shutdown. Your application remains unaffected.`}),DebuggerAttached:()=>({level:"error",errCode:"E1024",message:"Did not load as debugger is attached."}),InitSessionBeforeRegister:()=>({level:"error",errCode:"E1025",moreInfo:!0,message:"register() was not called, or called after initSession() - please call register() before initSession() and run again. Your application continues normally without Hud."}),RegisterMisplacedNoDeclarations:()=>({level:"warn",errCode:"E1026",moreInfo:!0,message:"Warning - No code has been mapped so far. This probably means register() was called too late — after your code was already loaded. Move it to the top of your entry file to enable proper mapping. Your application continues normally without Hud data."}),UnsupportedFrameworkVersion:e=>({level:"warn",errCode:"E1029",message:`Warning - Unsupported version of ${e} framework(s). This means Hud won't track your framework invocations. Your application continues normally, but with partial Hud data. See the compatibility matrix for details: https://docs.hud.io/docs/hud-sdk-compatibility-matrix-for-node#/`}),UninstrumentedFilesLogThresholdExceeded:e=>({level:"warn",errCode:"E1027",message:`Warning - ${e} of your code files were imported before register(). This means Hud won't track all of your functions. Please move register() call to an earlier location. To view the list of files use register({verbose: true}). Your application continues normally, but with partial Hud data.`,moreInfo:!0}),UninstrumentedFrameworks:e=>({level:"warn",errCode:"E1028",message:`Warning - The framework(s): ${e.map((e=>`"${e}"`)).join(", ")} was imported before register(). This means Hud won't track your framework invocations. Please move register() call to an earlier location. Your application continues normally, but with partial Hud data.`}),YesDeclarationsNoMetrics:()=>({level:"warn",errCode:"E1032",moreInfo:!0,message:"Warning - Code mapped successfully, but no function activity was tracked. Make sure your service is running and actively handling requests."}),HudEnableNotSet:e=>({level:"error",moreInfo:!0,message:`Did not load as HUD_ENABLE is ${void 0===e?"undefined":"set to a non-true value"}. Please set HUD_ENABLE=true to run Hud.`}),LambdaNotViaLayer:()=>({level:"error",errCode:"E1034",message:"Can't load Hud, lambda support is currently in beta. Contact Hud to get early access."}),RunningInBun:()=>({level:"error",errCode:"E1035",message:"Hud does not support Bun yet. The SDK has initiated a graceful shutdown. Your application remains unaffected. See the compatibility matrix for details: https://docs.hud.io/docs/hud-sdk-compatibility-matrix-for-node"}),RunningOnWindows:()=>({level:"error",errCode:"E1036",message:"Hud does not support Windows yet. The SDK has initiated a graceful shutdown. Your application remains unaffected. See the compatibility matrix for details: https://docs.hud.io/docs/hud-sdk-compatibility-matrix-for-node"}),UnsupportedNativeBuild:()=>({level:"error",errCode:"E1037",message:"Hud does not support this platform yet. The SDK has initiated a graceful shutdown. Your application remains unaffected. See the compatibility matrix for details: https://docs.hud.io/docs/hud-sdk-compatibility-matrix-for-node"}),TsNodeNotTranspileOnly:()=>({level:"error",errCode:"E1038",message:"detected ts-node is used without the transpileOnly flag, which is not supported yet. SDK has initiated a graceful shutdown. Your application remains unaffected.",moreInfo:!0}),TsNodeNotFoundEvenThoughRunWithTsNode:()=>({level:"error",errCode:"E1039",message:"'ts-node' was detected but could not be resolved by Hud. This may happen if 'ts-node' is installed globally. Try installing it locally in your project. The SDK has initiated a graceful shutdown. Your application remains unaffected.",moreInfo:!0}),InitFailedDueGenericNetworkError:()=>({level:"error",moreInfo:!0,errCode:"E1040",message:"A network error occurred during SDK initialization. Please check your internet connection and try again. SDK has initiated a graceful shutdown. Your application remains unaffected."}),InitFailedDueNetworkTimeout:()=>({level:"error",moreInfo:!0,errCode:"E1041",message:"The SDK failed to connect to Hud's backend due to a timeout during SDK initialization. Please verify your firewall settings to ensure outbound connections are allowed. SDK has initiated a graceful shutdown. Your application remains unaffected."}),InitFailedDueNetworkRST:()=>({level:"error",moreInfo:!0,errCode:"E1042",message:"The SDK connection to Hud's backend was reset unexpectedly (RST) during SDK initialization. Please check your firewall or network security settings. SDK has initiated a graceful shutdown. Your application remains unaffected."}),InitFailedDueSelfSignedCert:()=>({level:"error",moreInfo:!0,errCode:"E1043",message:"SSL certificate verification failed during SDK initialization. If your organization uses a self-signed certificate, set the NODE_EXTRA_CA_CERTS environment variable to the path of your CA certificate file. SDK has initiated a graceful shutdown. Your application remains unaffected."}),InitFailedDueDnsFailed:()=>({level:"error",moreInfo:!0,errCode:"E1044",message:"The SDK failed to resolve DNS when attempting to connect to Hud's backend during SDK initialization. If the problem persists, please contact support. SDK has initiated a graceful shutdown. Your application remains unaffected."}),InitFailedDueBackendError:()=>({level:"error",moreInfo:!0,errCode:"E1045",message:"Hud: The SDK was unable to complete initialization due to a temporary issue with Hud’s backend. SDK has initiated a graceful shutdown. Your application remains unaffected."}),InitTimeout:e=>({moreInfo:!0,level:"error",message:`SDK imported but not initialized. Please ensure to call '${e?"hud.initSession(KEY, SERVICE)":"hud.init()"}' to initialize the SDK.`}),EsbuildMissingKey:()=>({level:"error",errCode:"ES0001",moreInfo:!0,message:"missing HUD_KEY, skipping Hud plugin, your build is unaffected."}),EsbuildFailedProcessingFile:e=>({level:"error",errCode:"ES0002",moreInfo:!0,message:`failed processing file "${e}", reverting to original loader.`}),EsbuildFailedBundling:()=>({level:"error",errCode:"ES0003",moreInfo:!0,message:"encountered unexpected file bundling, build aborted."}),EsbuildFailedParsingSourcemap:()=>({level:"error",errCode:"ES0004",moreInfo:!0,message:"failed parsing source maps, skipping upload, Hud will run without source maps."}),EsbuildFailedUploadingSourcemap:e=>({level:"error",errCode:"ES0005",moreInfo:!0,message:`failed uploading source map: ${e}, Hud will run without source maps.`}),EsbuildFailedUploadingSourcemapUnauthorized:()=>({level:"error",errCode:"ES0006",moreInfo:!0,message:"failed uploading source map: unauthorized, Hud will run without source maps."}),EsbuildUnsupportedPlatform:()=>({level:"error",errCode:"ES0007",message:'Can\'t load Hud, as our esbuild plugin supports "node" mode only. Your app remains unaffected. For more information visit docs.hud.io/docs/support-matrix'})},r.getNetworkError=function(e){return{ECONNABORTED:r.UserErrorLogs.InitFailedDueNetworkTimeout(),ECONNREFUSED:r.UserErrorLogs.InitFailedDueNetworkRST(),ENOTFOUND:r.UserErrorLogs.InitFailedDueDnsFailed(),SELF_SIGNED_CERT_IN_CHAIN:r.UserErrorLogs.InitFailedDueSelfSignedCert(),ERR_BAD_RESPONSE:r.UserErrorLogs.InitFailedDueBackendError()}[e]??r.UserErrorLogs.InitFailedDueGenericNetworkError()}},9896:e=>{e.exports=require("fs")}},r={};function o(t){var n=r[t];if(void 0!==n)return n.exports;var i=r[t]={exports:{}};return e[t].call(i.exports,i,i.exports,o),i.exports}var t={};return(()=>{var e=t;Object.defineProperty(e,"__esModule",{value:!0});const r=o(8167);!function(){try{if(!r.isMainThread)return;const{isHudEnabled:e}=o(2826),{UserErrorLogs:t}=o(9514),{customer_logger:n}=o(1377);if(!e(((e,r)=>n.log(t.JSONErrorInUserConfig(e,r))),(e=>n.log(t.ConfigInaccessible(e)))))return void n.log(t.HudEnableNotSet(process.env.HUD_ENABLE));globalThis.hudStartFromAutoInit=!0;const i=o(7669);i.safeLog("Auto initializing Hud from --require"),i.init()}catch(e){}}()})(),t})())); //# sourceMappingURL=init.js.map