UNPKG

hud-sdk

Version:

Hud's Node SDK

2 lines 13.3 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 n=t();for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(global,(()=>(()=>{"use strict";var e={1569:e=>{e.exports=require("zod")},2602:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.updateInvestigationRateLimitGlobals=t.hudConfig=t.isValidUserInput=t.updateUserConfigFromInit=t.updateUserConfigFromFile=t.updateUserConfigFromInitOptions=t.updateUserConfigFromEnv=t.getModulesToTraceFromEnv=t.RawUserConfigSchema=t.HudDynamicConfigSchema=void 0;const i=n(1569),o=n(7182),r=n(2826);t.HudDynamicConfigSchema=i.z.object({aggregationInterval:i.z.number(),flowMetricInterval:i.z.number(),graphqlInterval:i.z.number(),aggregationFirstSendTimeout:i.z.number(),flowMetricFirstSendTimeout:i.z.number(),enableInvestigation:i.z.boolean(),investigationRateLimits:i.z.object({maxSameInvestigations:i.z.number().int().positive(),sameInvestigationTimeWindowMs:i.z.number().int().positive(),maxTotalInvestigations:i.z.number().int().positive(),totalInvestigationTimeWindowMs:i.z.number().int().positive()})});const s=i.z.object({includeModules:i.z.array(i.z.string()).optional(),maxMappedFunctions:i.z.number().optional(),minPodMemoryLimit:i.z.number().optional(),verbose:i.z.boolean().optional(),disableSourceMapsResolution:i.z.boolean().optional(),customOptions:i.z.record(i.z.string(),i.z.string()).optional()});function a(){const e=process.env.HUD_MONITOR_MODULES||process.env.HUD_INCLUDE_MODULES;if(e)return e.split(",")}function u(e,n){e.includeModules&&Array.isArray(e.includeModules)&&(t.hudConfig.userConfig.includeModules={value:e.includeModules,source:n}),e.customOptions&&e.customOptions.dapulseSqsConsumer&&(t.hudConfig.userConfig.enableDapulse={value:"true"===e.customOptions.dapulseSqsConsumer,source:n}),e.maxMappedFunctions&&"number"==typeof e.maxMappedFunctions&&(t.hudConfig.userConfig.maxMappedFunctions={value:e.maxMappedFunctions,source:n})}function c(e){return null!=e&&""!==e&&"string"==typeof e}t.RawUserConfigSchema=s.omit({customOptions:!0}).extend({key:i.z.string().optional(),service:i.z.string().optional(),enable:i.z.boolean().optional(),enableDapulse:i.z.boolean().optional()}),t.getModulesToTraceFromEnv=a,t.updateUserConfigFromEnv=function(){const e=process.env.HUD_KEY,n=process.env.HUD_SERVICE,i=process.env.HUD_ENABLE_DAPULSE,o=a(),r=process.env.HUD_MAX_INSTRUMENTED_FUNCTIONS,s=process.env.HUD_MIN_POD_MEMORY_LIMIT;e&&(t.hudConfig.userConfig.key={value:e,source:"ENV"}),n&&(t.hudConfig.userConfig.service={value:n,source:"ENV"}),i&&(t.hudConfig.userConfig.enableDapulse={value:"true"===i,source:"ENV"}),o&&(t.hudConfig.userConfig.includeModules={value:o,source:"ENV"}),r&&(t.hudConfig.userConfig.maxMappedFunctions={value:parseInt(r),source:"ENV"}),s&&(t.hudConfig.userConfig.minPodMemoryLimit={value:parseInt(s),source:"ENV"})},t.updateUserConfigFromInitOptions=u,t.updateUserConfigFromFile=function(e,n,o){let s;try{s=(0,r.getConfigContent)()}catch(e){throw e instanceof r.HudFailedReadConfigError&&"EACCES"===e.code&&o(e.path),e}if(s)try{const e=t.RawUserConfigSchema.partial().parse(JSON.parse(s.content));Object.entries(e).forEach((([e,n])=>{!function(e,t,n){e[t]=n}(t.hudConfig.userConfig,e,{value:n,source:"HUD_CONFIG"===s.source?"CONFIG_ENV":"CONFIG_FILE"})}))}catch(t){throw t instanceof i.ZodError?t.errors.forEach((t=>{const n=t.path.join(".");e(s.source,n)})):n(s.source,t.message),t}},t.updateUserConfigFromInit=function(e,n,i){void 0!==e&&(t.hudConfig.userConfig.key={value:e,source:"INIT"}),void 0!==n&&(t.hudConfig.userConfig.service={value:n,source:"INIT"}),void 0!==i&&u(i,"INIT")},t.isValidUserInput=function(){const{key:e,service:n}=t.hudConfig.userConfig;return void 0!==e&&void 0!==n&&c(e.value)&&c(n.value)};const d=process.env.HUD_ENABLE_INVESTIGATION,l=process.env.HUD_HOST||"https://api-prod.hud.io",p=process.env.HUD_LOG_DIR,m="_HUD",g=process.env.HUD_LOG_TO_FILE,f={sink:{url:l,timeout:5e3,session_attr:"X-Session-ID"},endpoints:{init:"sink/init",send:"sink/send",batch:"sink/batch",logs:"sink/logs",fatalError:"sink/redline",getMode:"sink/getMode",getRemoteConfig:"sink/remote-config/get",fileDeclarations:"sink/file-declarations",sourceMap:"sink/sourcemap",storeObject:"sink/objects/store"},logger:{default:{levels:{app:"warn",worker:"warn",instrument:"warn"}},debug:{levels:{app:"debug",worker:"debug",instrument:"debug"}}},investigation:{objectVersion:"1.0.0",store:{type:"s3"},limits:{executionFlowMaxLength:100,exceptionMaxLength:100},blacklistParams:["password","passwd","pwd","secret","token","apiKey","accessKey","auth","authorization","credentials","jwt","sessionId","sessionToken","clientSecret","oauth","oauthToken","ssoToken","api_secret","api_secret_key","ssn","sin","passport","passportNumber","driverLicense","dlNumber","user_id","userid","email","emailAddress","phone","phoneNumber","address","homeAddress","dob","birthDate","dateOfBirth","creditCard","credit_card","ccn","cardNumber","cvv","cvc","iban","bic","swift","bankAccount","bank_account","fingerprint","faceId","voicePrint","medicalRecord","healthId","authToken","auth_code","authCode","pin","userPin","user_secret"],censorshipRegexes:[{regex:/\b[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+\b/g,replacement:"[REDACTED-EMAIL]"},{regex:/[\b+][+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,6}\b/g,replacement:"[REDACTED-PHONE-NUMBER]"},{regex:/\b(?:\d{1,3}\.){3}\d{1,3}\b/g,replacement:"[REDACTED-IP]"},{regex:/\b[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\b/g,replacement:"[REDACTED-JWT]"},{regex:/\b(?:\d[ -]*?){13,16}\b/g,replacement:"[REDACTED-CREDIT-CARD]"}],maxStringLength:1024,maxArrayLength:100,maxObjectDepth:10},userConfig:{maxMappedFunctions:{value:5e4,source:"DEFAULT"},includeModules:{value:[],source:"DEFAULT"}},loggerWorkerPortSizeLimit:1e4,customerLoggerLevel:"info",logDirectory:p,hudModuleName:o.SDK_MODULE_NAME,invocationSampling:new Map([[[300n,null],100],[[200n,300n],50],[[100n,200n],25],[[0n,100n],10]]),callerResetInterval:36e5,modeInterval:3e5,logsSendInterval:6e4,logPerfInterval:3e5,endpointsInterval:18e5,endpointsFirstSendWaitTime:12e4,huddBinWidth:1.2,workerGrace:6e4,workerTimeout:2e4,timeoutOnInit:3e4,timeoutOnRegister:6e4,timeoutOnMetrics:6e4,workerMessageTimeout:1e4,communicationBatchSize:100,writePatched:!1,defaultOff:!0,disableOnBadApiKey:!0,disableOnBadServiceName:!0,cpuTimeCollection:!1,workloadMetadata:{sendInterval:3e5,aws:{imds:{baseURL:"http://169.254.169.254/latest",tokenURI:"/api/token",identityURI:"/dynamic/instance-identity/document",lifeCycleURI:"/meta-data/instance-life-cycle",requestTimeout:5e3},metadataFile:"/run/cloud-init/instance-data.json"},kubernetes:{namespaceFile:"/var/run/secrets/kubernetes.io/serviceaccount/namespace",uuidFile:"/sys/class/dmi/id/product_uuid",podMemoryLimitFile:"/sys/fs/cgroup/memory/memory.stat",podCPULimitFile:"/sys/fs/cgroup/cpuacct/cpu.shares"}},deleteLogsAfterSending:!0,supportSourceMap:!0,editInline:!0,bundlerBuildIdVarName:"hudFileBuildID",bundlerBuildUuidNamespace:"00c1e90b-af75-4d8e-9935-68485877f759",functionUuidNamespace:"94a210f3-861c-4e18-ab27-6b6c19437c9d",wrapVarPrefix:m,functionIdVarName:`${m}_fid`,frameworksToPatch:new Map([["express",{version:"<=5",patcher:"express",enableEsbuild:!0}],["express/lib/application.js",{version:"<=5",patcher:"expressApplication",enableEsbuild:!0}],["router",{version:"^2.0.0",patcher:"router",enableEsbuild:!0}],["koa",{version:"^2.0.0",patcher:"koa"}],["graphql/execution/execute",{version:"14 - 16",patcher:"graphql"}],["http",{version:"*",patcher:"http"}],["https",{version:"*",patcher:"http"}],["@nestjs/core/interceptors/interceptors-consumer",{version:"*",patcher:"nestjsInterceptor"}],["@nestjs/core/router/router-execution-context",{version:"*",patcher:"nestjsRouterExecutionContext"}],["@nestjs/microservices/context/rpc-context-creator",{version:">=7.0.0",patcher:"nestjsRpcContextCreator"}],["kafkajs",{version:">=1.4.0",patcher:"kafkajs"}],["@codegenie/serverless-express/src/frameworks/express.js",{version:"^4.1.0",patcher:"codeGenieServerlessExpress",enableEsbuild:!0}],["@codegenie/serverless-express",{enableEsbuild:!0}],["sqs-consumer",{version:"*",patcher:"sqsConsumer",extraInfo:{mondayVersion:">=6.1.0",bbcVersion:">=7.5.0"}}],["serverless-http",{enableEsbuild:!0}],["serverless-http/lib/framework/get-framework.js",{version:"^2.7.0",patcher:"serverlessHttp",enableEsbuild:!0}]]),communicationKeepalive:!1,communicationKeepaliveGrace:5e3,maxWrappedFileSize:2831155,express:{routeNamesVarName:"hudRoutes",layerStateVarName:"hudState",markedVarName:"hudMarked",wrapAllCallbacks:!0},supportedNodeVersions:["18","20","21","22","24"],hudPatchedName:"hudPatched",hudMetricName:"hudMetric",dynamicConfig:{aggregationInterval:3e5,flowMetricInterval:3e5,graphqlInterval:3e4,aggregationFirstSendTimeout:3e4,flowMetricFirstSendTimeout:3e4,enableInvestigation:"true"===d,investigationRateLimits:{maxSameInvestigations:2,sameInvestigationTimeWindowMs:36e5,maxTotalInvestigations:25,totalInvestigationTimeWindowMs:216e5}},isInvestigationEnabledByEnv:void 0!==d,suppressTraces:!0,lambdaMinimunMemory:1024,lambdaBaseGivenTime:400,lambdaExtraGivenTimePerRequest:50,lambdaMaxGivenTime:700,throttleStatusCode:202,esbuildGlobalVar:"hudSGV",esbuildPluginMessagePrefix:"ESBuild plugin ",esbuildMark:"/*modifiedByHudESBuildPlugin-",esbuildMarkLength:67,esbuildUploadSourceMapTimeout:15e3,esbuildPluginLogsChunkSize:100,esbuildPluginLogsBatchSize:10,pluginsLogEndpoint:"https://yqp37dddrsewm6wdwwpwfraxqm0shdmx.lambda-url.eu-central-1.on.aws/",fileless:"true"!==g,minPodMemoryLimit:250,uninstrumentedFilesLogThreshold:2,tsNodeConfigTimeout:1e4,allowedEditExtensions:[".ts",".cts",".mts",".js",".cjs",".mjs"]};t.hudConfig=function(e={}){return{...f,...e}}({logger:{default:{levels:{app:"info",worker:"info",instrument:"info"}},debug:{levels:{app:"debug",worker:"debug",instrument:"debug"}}},deleteLogsAfterSending:!1,communicationKeepalive:!0}),t.default=t.hudConfig,t.updateInvestigationRateLimitGlobals=function(){globalThis.hudMaxSameInvestigations=t.hudConfig.dynamicConfig.investigationRateLimits.maxSameInvestigations,globalThis.hudMaxTotalInvestigations=t.hudConfig.dynamicConfig.investigationRateLimits.maxTotalInvestigations,globalThis.hudSameInvestigationTimeWindowNs=BigInt(t.hudConfig.dynamicConfig.investigationRateLimits.sameInvestigationTimeWindowMs)*BigInt(1e6),globalThis.hudTotalInvestigationTimeWindowNs=BigInt(t.hudConfig.dynamicConfig.investigationRateLimits.totalInvestigationTimeWindowMs)*BigInt(1e6)}},2826:function(e,t,n){var i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,o)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||i(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),o(n(8841),t)},6928:e=>{e.exports=require("path")},7182:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SDK_MODULE_NAME=void 0,t.SDK_MODULE_NAME="hud-sdk"},8841:function(e,t,n){var i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,o)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),o=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 n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&i(t,e,n);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.noopInit=t.noop=t.getConfigContent=t.HudFailedReadConfigError=t.isHudEnabled=void 0;const s=r(n(9896)),a=r(n(6928));t.isHudEnabled=function(e,t){if("false"===process.env.HUD_ENABLE)return!1;if(globalThis.forceHudEnable)return!0;let n,i;try{if(n=c(),n&&(i=JSON.parse(n.content),!1===i.enable))return!1}catch(i){throw i instanceof u&&"EACCES"===i.code?t(i.path):n&&e(n.source,i instanceof Error?i.message:void 0),i}return"true"===process.env.HUD_ENABLE||!0===i?.enable};class u extends Error{path;code;constructor(e,t){super(),this.path=e,this.code=t}}function c(){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 s.existsSync(e)?e:void 0;let t=__dirname,n=0;for(;"/"!==t&&n<10;){const e=`${t}/hud.config`;if(s.existsSync(e))return e;t=a.dirname(t),n++}}catch(e){return}}();if(e)try{return{content:s.readFileSync(e,"utf8"),source:e}}catch(t){throw new u(e,t.code)}}t.HudFailedReadConfigError=u,t.getConfigContent=c,t.noop=function(...e){},t.noopInit=async function(e,t,n){}},9896:e=>{e.exports=require("fs")}},t={};return function n(i){var o=t[i];if(void 0!==o)return o.exports;var r=t[i]={exports:{}};return e[i].call(r.exports,r,r.exports,n),r.exports}(2602)})())); //# sourceMappingURL=config.js.map