UNPKG

hud-sdk

Version:

Hud's Node SDK

2 lines 18.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 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")},2210:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SDK_MODULE_NAME=void 0,t.SDK_MODULE_NAME="hud-sdk"},2509:function(e,t,n){var i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var a=Object.getOwnPropertyDescriptor(t,n);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,a)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),a=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}),t.SDK_VERSION=t.SDK_MODULE_NAME=void 0,a(n(2887),t),a(n(2570),t);var r=n(2210);Object.defineProperty(t,"SDK_MODULE_NAME",{enumerable:!0,get:function(){return r.SDK_MODULE_NAME}}),a(n(7089),t);var o=n(5453);Object.defineProperty(t,"SDK_VERSION",{enumerable:!0,get:function(){return o.SDK_VERSION}})},2570:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.updateDynamicConfig=function(e,t,n){const r=i.HudDynamicConfigSchema.deepPartial().safeParse(e);if(!r.success)return n.error("Dynamic configuration not updated - Invalid configuration override",{remoteConfigParseResult:r,remoteConfig:e}),t.dynamicConfig;const o=a(t.dynamicConfig,r.data);return void 0!==o.enableInvestigation&&o.enableInvestigation!==t.dynamicConfig.enableInvestigation&&(n.info("Dynamic configuration updated - enableInvestigation",{hudEnableInvestigation:o.enableInvestigation}),t.isInvestigationEnabledByEnv||(globalThis.hudEnableInvestigation=o.enableInvestigation)),void 0!==o.enableInvestigationArgsSending&&o.enableInvestigationArgsSending!==t.dynamicConfig.enableInvestigationArgsSending&&(n.info("Dynamic configuration updated - enableInvestigationArgsSending",{hudEnableInvestigationArgsSending:o.enableInvestigationArgsSending}),globalThis.hudEnableInvestigationArgsSending=o.enableInvestigationArgsSending),void 0!==o?.investigationRateLimits?.executionFlowMaxLength&&o?.investigationRateLimits?.executionFlowMaxLength!==t.dynamicConfig.investigationRateLimits.executionFlowMaxLength&&(globalThis.hudExecutionFlowMaxLength=o.investigationRateLimits.executionFlowMaxLength),void 0!==o?.investigationRateLimits?.exceptionMaxLength&&o?.investigationRateLimits?.exceptionMaxLength!==t.dynamicConfig.investigationRateLimits.exceptionMaxLength&&(globalThis.hudExceptionMaxLength=o.investigationRateLimits.exceptionMaxLength),o};const i=n(2887);function a(e,t){if(null===t||"object"!=typeof t)return t;if(Array.isArray(e)&&Array.isArray(t))return t;const n={...e};for(const i in t){const r=e[i],o=t[i];n[i]=a(r,o)}return n}},2887:function(e,t,n){var i,a=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var a=Object.getOwnPropertyDescriptor(t,n);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,a)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(i=function(e){return i=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},i(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n=i(e),o=0;o<n.length;o++)"default"!==n[o]&&a(t,e,n[o]);return r(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.HudFailedReadConfigError=t.hudConfig=t.HudDynamicConfigSchema=void 0,t.getModulesToTraceFromEnv=function(){const e=process.env.HUD_MONITOR_MODULES||process.env.HUD_INCLUDE_MODULES;if(e)return e.split(",")},t.getFrameworksToEnableFromEnv=function(){const e=process.env.HUD_ENABLE_FRAMEWORKS;let t;if(e)try{t=s.availableFrameworksSchema.parse(JSON.parse(e))}catch{t=new Map}return t},t.isValidParam=function(e){return null!=e&&""!==e&&"string"==typeof e},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)},t.getConfigContent=function(){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 l.existsSync(e)?e:void 0;let t=__dirname,n=0;for(;"/"!==t&&n<10;){const e=`${t}/hud.config`;if(l.existsSync(e))return e;t=u.dirname(t),n++}}catch{return}}();if(e)try{return{content:l.readFileSync(e,"utf8"),source:e}}catch(t){throw new h(e,t.code)}};const s=n(8528),l=o(n(9896)),u=o(n(6928)),d=n(3903),c=n(1569);function m(e){return Buffer.from((0,d.parse)(e)).toString("base64").slice(0,22)}const g="globalThis._hudMark";t.HudDynamicConfigSchema=c.z.object({aggregationInterval:c.z.number(),aggregationFirstSendTimeout:c.z.number(),investigationInterval:c.z.number(),investigationFirstSendTimeout:c.z.number(),enableInvestigation:c.z.boolean(),enableInvestigationArgsSending:c.z.boolean(),investigationRateLimits:c.z.object({maxSameInvestigations:c.z.number().int().positive(),sameInvestigationTimeWindowMs:c.z.number().int().positive(),maxTotalInvestigations:c.z.number().int().positive(),maxTotalInvestigationsErrorBased:c.z.number().int().positive(),maxTotalInvestigationsDurationBased:c.z.number().int().positive(),totalInvestigationTimeWindowMs:c.z.number().int().positive(),maxUniqLogs:c.z.number().int().positive(),maxStringLength:c.z.number().int().positive(),maxArrayLength:c.z.number().int().positive(),maxObjectDepth:c.z.number().int().positive(),maxKeyLength:c.z.number().int().positive(),executionFlowMaxLength:c.z.number().int().positive(),exceptionMaxLength:c.z.number().int().positive()}),machineMetricsInterval:c.z.number().int().positive(),blacklistParams:c.z.array(c.z.string()),forensicsBlacklistFields:c.z.array(c.z.string()),forensicsWhitelistFields:c.z.array(c.z.string()),censorshipRegexes:c.z.array(c.z.object({regex:c.z.string(),replacement:c.z.string()})),reingestInterval:c.z.number().int().positive(),extraHeaders:c.z.array(c.z.string()),performanceMetricsInterval:c.z.number().int().positive(),enableOutboundData:c.z.boolean(),maxTotalOutbounds:c.z.number().int().positive(),maxOutboundCountWithData:c.z.number().int().positive(),maxHTTPRequestBodySize:c.z.number().int().positive(),maxHTTPResponseBodySize:c.z.number().int().positive()});const p=process.env.HUD_ENABLE_INVESTIGATION,v="_HUD",b="94a210f3-861c-4e18-ab27-6b6c19437c9d",f={sink:{url:process.env.HUD_HOST||"https://api-prod.hud.io",timeout:5e3,session_attr:"X-Session-ID"},endpoints:{init:"sink/init",send:"sink/send",batch:"sink/batch",logs:"sink/logs",sessionslessLogs:"sink/sessionless-logs",fatalError:"sink/redline",getMode:"sink/getMode",getRemoteConfig:"sink/remote-config/get",fileDeclarations:"sink/file-declarations",sourceMap:"sink/sourcemap",storeObject:"sink/objects/store",getUploadUrls:"sink/registry/get-upload-urls",triggerReingest:"sink/registry/reingest",validateToken:"sink/registry/validate",fileDeclarationsCi:"sink/registry/file-declarations",completed:"sink/registry/completed",endpointsDurationsInvestigationThresholds:"sink/endpoint-configuration"},logger:{default:{levels:{app:"warning",worker:"warning",instrument:"warning"}},debug:{levels:{app:"debug",worker:"debug",instrument:"debug"}}},investigation:{objectVersion:"1.0.2",store:{type:"s3"}},userConfig:{minPodMemoryMB:{value:250,source:"DEFAULT"},maxMappedFunctions:{value:5e4,source:"DEFAULT"},maxFileSizeBytes:{value:2831155,source:"DEFAULT"},maxTimeUntilInitSessionMs:{value:3e4,source:"DEFAULT"},includeModules:{value:[],source:"DEFAULT"},disableRuntimeInstrumentation:{value:!1,source:"DEFAULT"},disableParametersExtraction:{value:!1,source:"DEFAULT"}},loggerWorkerPortSizeLimit:1e4,customerLoggerLevel:"info",logDirectory:process.env.HUD_LOG_DIR,invocationSampling:new Map([[[300n,null],100],[[200n,300n],50],[[100n,200n],25],[[0n,100n],10]]),callerResetInterval:36e5,modeInterval:3e5,logsSendInterval:6e4,endpointsInterval:3e4,endpointsFirstSendWaitTime:12e4,lazyEndpointsInterval:18e5,staticNextJsEndpointsInterval:1e4,staticNextJsEndpointsMaxAttempts:12,huddBinWidth:1.2,endpointsDurationsInvestigationThresholdsInterval:6e5,workerGrace:6e4,workerTimeout:2e4,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:b,wrapVarPrefix:v,functionInitFunctionName:`${v}i`,functionCatchFunctionName:`${v}c`,functionFinallyFunctionName:`${v}n`,callContextVarName:`${v}x`,fixStackFunctionName:`${v}s`,asyncIteratorWrapperFunctionName:`${v}w`,wrapperUserCatchFunctionName:`${v}u`,beforeYieldFunctionName:`${v}b`,afterYieldFunctionName:`${v}a`,internalBeforeYieldFunctionName:`${v}j`,internalAfterYieldFunctionName:`${v}k`,frameworksToPatch:new Map([["express",{framework:s.availableFrameworks.express,enable:!0,version:"<=5",patcher:"express",enableEsbuild:!0}],[u.join("express","lib","application.js"),{framework:s.availableFrameworks.express,enable:!0,version:"<=5",patcher:"expressApplication",enableEsbuild:!0}],["router",{framework:s.availableFrameworks.express,enable:!0,version:"^2.0.0",patcher:"router",enableEsbuild:!0}],["koa",{framework:s.availableFrameworks.koa,enable:!0,version:"^2.0.0",patcher:"koa"}],["graphql/execution/execute",{framework:s.availableFrameworks.graphql,enable:!1,version:"14 - 16",patcher:"graphql"}],["http",{framework:s.availableFrameworks.http,enable:!0,version:"*",patcher:"http"}],["https",{framework:s.availableFrameworks.https,enable:!0,version:"*",patcher:"http"}],["next/dist/server/base-server",{framework:s.availableFrameworks.nextjs,enable:!1,version:">=13.4.0",patcher:"nextjs"}],["next/dist/server/lib/module-loader/route-module-loader",{framework:s.availableFrameworks.nextjs,enable:!1,version:">=13.4.0",patcher:"nextJsModuleLoader"}],["next/dist/compiled/next-server/pages-api.runtime.prod",{framework:s.availableFrameworks.nextjs,enable:!1,version:">=13.4.0",patcher:"nextJsRouteModule"}],["next/dist/server/config",{framework:s.availableFrameworks.nextjs,enable:!1,version:">=13.4.0",patcher:"nextJsConfig"}],["@nestjs/core/router/router-execution-context",{framework:s.availableFrameworks.nestjs,enable:!0,version:"*",patcher:"nestjsRouterExecutionContext"}],["kafkajs",{framework:s.availableFrameworks.kafkajs,enable:"win32"!==process.platform,version:">=1.4.0",patcher:"kafkajs"}],["@confluentinc/kafka-javascript",{framework:s.availableFrameworks.confluentKafkaJs,enable:!1,version:">=1.4.0",patcher:"confluentKafkaJs"}],["@nestjs/microservices/context/rpc-context-creator",{framework:s.availableFrameworks.nestjs,enable:"win32"!==process.platform,version:">=7.0.0",patcher:"nestjsRpcContextCreator"}],[["@codegenie/serverless-express","src","frameworks","express.js"].join(u.sep),{framework:s.availableFrameworks.codegenieServerlessExpress,enable:!0,version:"^4.1.0",patcher:"codeGenieServerlessExpress",enableEsbuild:!0}],["@codegenie/serverless-express",{framework:s.availableFrameworks.codegenieServerlessExpress,enable:!0,enableEsbuild:!0}],["sqs-consumer",{framework:s.availableFrameworks.sqs,enable:!0,version:"*",patcher:"sqsConsumer",extraInfo:{mondayVersion:">=6.1.0",bbcVersion:">=7.5.0"}}],["serverless-http",{framework:s.availableFrameworks.serverlessHttp,enable:!0,enableEsbuild:!0}],[u.join("serverless-http","lib","framework","get-framework.js"),{framework:s.availableFrameworks.serverlessHttp,enable:!0,version:"^2.7.0",patcher:"serverlessHttp",enableEsbuild:!0}],["axios",{framework:s.availableFrameworks.axios,enable:!0,version:">0.25.0 <1.0.0 || ^1.0.0",patcher:"outbound/axios",mainFilePath:"axios/dist/node/axios.cjs"}],["node-fetch",{framework:s.availableFrameworks.nodeFetch,enable:!0,version:"^2.0.0",patcher:"outbound/nodeFetch",mainFilePath:"node-fetch/lib/index.js"}],["request",{framework:s.availableFrameworks.request,enable:!0,version:"2.88.2",patcher:"outbound/request"}],["pg",{framework:s.availableFrameworks.pg,enable:!0,version:"^8.8.0",patcher:"outbound/pg"}]]),communicationKeepalive:!1,communicationKeepaliveGrace:5e3,express:{routeNamesSymbol:Symbol.for("hudRoutes"),layerStateSymbol:Symbol.for("hudState"),markedSymbol:Symbol.for("hudMarked"),wrapAllCallbacks:!0},supportedNodeVersions:["18","20","21","22","24"],hudPatchedName:"hudPatched",metricSymbol:Symbol.for("hudMetric"),dynamicConfig:{aggregationInterval:3e5,aggregationFirstSendTimeout:3e4,investigationInterval:5e3,investigationFirstSendTimeout:3e4,enableInvestigation:"true"===p,enableInvestigationArgsSending:!0,investigationRateLimits:{maxSameInvestigations:2,sameInvestigationTimeWindowMs:36e5,maxTotalInvestigations:25,maxTotalInvestigationsErrorBased:25,maxTotalInvestigationsDurationBased:20,totalInvestigationTimeWindowMs:216e5,maxUniqLogs:2,executionFlowMaxLength:20,exceptionMaxLength:20,maxStringLength:1024,maxArrayLength:10,maxObjectDepth:3,maxKeyLength:30},machineMetricsInterval:1e4,performanceMetricsInterval:6e4,reingestInterval:3e4,extraHeaders:[],enableOutboundData:"true"===process.env.HUD_ENABLE_OUTBOUND_DATA,maxHTTPRequestBodySize:1024,maxHTTPResponseBodySize:5120,blacklistParams:[],censorshipRegexes:[],forensicsBlacklistFields:[],forensicsWhitelistFields:[],maxOutboundCountWithData:process.env.HUD_MAX_OUTBOUND_WITH_DATA?parseInt(process.env.HUD_MAX_OUTBOUND_WITH_DATA):10,maxTotalOutbounds:20},machineMetricsSavedLength:2,isInvestigationEnabledByEnv:void 0!==p,suppressTraces:!0,lambdaMinimunMemory:1024,lambdaBaseGivenTime:400,lambdaExtraGivenTimePerRequest:50,lambdaMaxGivenTime:700,throttleStatusCode:202,axiosFunctionId:m((0,d.v5)("axios",b)),nodeFetchFunctionId:m((0,d.v5)("node-fetch",b)),nodeFetchBodiesFunctionIds:{json:m((0,d.v5)("node-fetch-body-json",b)),text:m((0,d.v5)("node-fetch-body-text",b)),arrayBuffer:m((0,d.v5)("node-fetch-body-arrayBuffer",b)),blob:m((0,d.v5)("node-fetch-body-blob",b))},requestFunctionId:m((0,d.v5)("request-request",b)),requestMethodFunctionIds:{get:m((0,d.v5)("request-get",b)),head:m((0,d.v5)("request-head",b)),options:m((0,d.v5)("request-options",b)),post:m((0,d.v5)("request-post",b)),put:m((0,d.v5)("request-put",b)),patch:m((0,d.v5)("request-patch",b)),del:m((0,d.v5)("request-del",b)),delete:m((0,d.v5)("request-delete",b))},pgConnectFunctionId:m((0,d.v5)("pg-connect",b)),pgQueryFunctionId:m((0,d.v5)("pg-query",b)),pgEndFunctionId:m((0,d.v5)("pg-end",b)),functionsToInstrument:[{moduleName:"typeorm",fileToFunctionsMapping:{[u.join(u.sep,"typeorm","repository","Repository.js")]:["hasId","getId","create","merge","preload","save","remove","softRemove","recover","insert","update","upsert","delete","softDelete","restore","exist","exists","existsBy","count","countBy","sum","average","minimum","maximum","find","findBy","findAndCount","findAndCountBy","findByIds","findOne","findOneBy","findOneById","findOneOrFail","findOneByOrFail","query","clear","increment","decrement","extend"]}}],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/",uninstrumentedFilesLogThreshold:2,tsNodeConfigTimeout:1e4,allowedEditExtensions:[".ts",".cts",".mts",".js",".cjs",".mjs"],nextJsMarkVarName:g,nextJsMarkStatement:`${g} = "a"`,timeoutOnNextJsPlugin:3e4,logIntervals:{instrumentedFilesCount:5e3,sentEventsCount:12e4},cliBuildIdVarName:"hudCliBuildId",cliSdkVersionVarName:"hudCliSdkVersion"};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;class h extends Error{path;code;constructor(e,t){super(),this.path=e,this.code=t}}t.HudFailedReadConfigError=h},3903:e=>{e.exports=require("uuid")},5453:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SDK_VERSION=void 0,t.SDK_VERSION="1.7.1"},6928:e=>{e.exports=require("path")},7089:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ObjectStoreConfigSchema=void 0;const i=n(1569),a=i.z.object({type:i.z.literal("s3")}),r=i.z.object({type:i.z.literal("disk"),path:i.z.string()});t.ObjectStoreConfigSchema=i.z.union([a,r])},8528:e=>{e.exports=require("./dto")},9896:e=>{e.exports=require("fs")}},t={};return function n(i){var a=t[i];if(void 0!==a)return a.exports;var r=t[i]={exports:{}};return e[i].call(r.exports,r,r.exports,n),r.exports}(2509)})()); //# sourceMappingURL=config.js.map