hud-sdk
Version:
Hud's Node SDK
397 lines (393 loc) • 14 kB
TypeScript
// Generated by dts-bundle-generator v9.5.1
import * as winston from 'winston';
import { MessagePort as MessagePort$1 } from 'worker_threads';
import { z } from 'zod';
export declare enum Format {
cjs = "commonjs",
esm = "module",
moduleTypescript = "module-typescript",
commonjsTypescript = "commonjs-typescript"
}
export interface SourceFileMetadata {
code: string;
map: string;
filename: string;
hasInputMap: boolean;
bundlerBuildId: string;
bundlerBuildIdGenerated: boolean;
file_path_checksum: number;
file_checksum: number;
functionIds: string[];
sourceCodeHash: string;
moduleBase: number;
lineOffset?: number;
columnOffset?: number;
transformedLineOffset?: number;
transformedColumnOffset?: number;
mapRelativeToChunk?: string;
indexOffset?: number;
indexOffsetEnd?: number;
}
export declare function initGlobals(): void;
export declare function hookMessageChannel(): MessagePort$1;
declare class SafeLogger {
name: string;
logger?: winston.Logger;
constructor(name: string);
isValid(): boolean;
log(level: string, message: string, ...meta: any): void;
error(message: string, ...meta: any): void;
warn(message: string, ...meta: any): void;
info(message: string, ...meta: any): void;
http(message: string, ...meta: any): void;
verbose(message: string, ...meta: any): void;
debug(message: string, ...meta: any): void;
silly(message: string, ...meta: any): void;
}
export declare const customer_logger: winston.Logger;
export declare const app_logger: SafeLogger;
export declare const instrument_logger: SafeLogger;
export declare function shouldSupportSourceMap(): boolean;
export declare function patch(content: string, filename: string, format: Format, hudAppPort?: MessagePort$1): {
code: string;
map?: SourceFileMetadata[] | undefined;
};
export declare function combineSourceMaps(maps: SourceFileMetadata[], filename: string): string | undefined;
declare function onRequireFn<T>(exports: T, name: string, basedir?: string): T;
export declare function updateModuleChecker(): void;
declare const ObjectStoreConfigSchema: z.ZodUnion<[
z.ZodObject<{
type: z.ZodLiteral<"s3">;
}, "strip", z.ZodTypeAny, {
type: "s3";
}, {
type: "s3";
}>,
z.ZodObject<{
type: z.ZodLiteral<"disk">;
path: z.ZodString;
}, "strip", z.ZodTypeAny, {
type: "disk";
path: string;
}, {
type: "disk";
path: string;
}>
]>;
export type ObjectStoreConfig = z.infer<typeof ObjectStoreConfigSchema>;
export type DurationRange = [
bigint,
bigint | null
];
export type InvocationSampling = Map<DurationRange, number>;
export type FrameworkPatchInfo = {
version?: string;
patcher?: string;
enableEsbuild?: boolean;
extraInfo?: any;
};
export type FrameworkConfig = Map<string, FrameworkPatchInfo>;
declare const HudDynamicConfigSchema: z.ZodObject<{
aggregationInterval: z.ZodNumber;
flowMetricInterval: z.ZodNumber;
graphqlInterval: z.ZodNumber;
aggregationFirstSendTimeout: z.ZodNumber;
flowMetricFirstSendTimeout: z.ZodNumber;
enableInvestigation: z.ZodBoolean;
investigationRateLimits: z.ZodObject<{
maxSameInvestigations: z.ZodNumber;
sameInvestigationTimeWindowMs: z.ZodNumber;
maxTotalInvestigations: z.ZodNumber;
totalInvestigationTimeWindowMs: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
maxSameInvestigations: number;
sameInvestigationTimeWindowMs: number;
maxTotalInvestigations: number;
totalInvestigationTimeWindowMs: number;
}, {
maxSameInvestigations: number;
sameInvestigationTimeWindowMs: number;
maxTotalInvestigations: number;
totalInvestigationTimeWindowMs: number;
}>;
}, "strip", z.ZodTypeAny, {
aggregationInterval: number;
flowMetricInterval: number;
graphqlInterval: number;
aggregationFirstSendTimeout: number;
flowMetricFirstSendTimeout: number;
enableInvestigation: boolean;
investigationRateLimits: {
maxSameInvestigations: number;
sameInvestigationTimeWindowMs: number;
maxTotalInvestigations: number;
totalInvestigationTimeWindowMs: number;
};
}, {
aggregationInterval: number;
flowMetricInterval: number;
graphqlInterval: number;
aggregationFirstSendTimeout: number;
flowMetricFirstSendTimeout: number;
enableInvestigation: boolean;
investigationRateLimits: {
maxSameInvestigations: number;
sameInvestigationTimeWindowMs: number;
maxTotalInvestigations: number;
totalInvestigationTimeWindowMs: number;
};
}>;
export type HudDynamicConfig = z.infer<typeof HudDynamicConfigSchema>;
declare const HudInitOptionsSchema: z.ZodObject<{
includeModules: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
maxMappedFunctions: z.ZodOptional<z.ZodNumber>;
minPodMemoryLimit: z.ZodOptional<z.ZodNumber>;
verbose: z.ZodOptional<z.ZodBoolean>;
disableSourceMapsResolution: z.ZodOptional<z.ZodBoolean>;
customOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
}, "strip", z.ZodTypeAny, {
includeModules?: string[] | undefined;
maxMappedFunctions?: number | undefined;
minPodMemoryLimit?: number | undefined;
verbose?: boolean | undefined;
disableSourceMapsResolution?: boolean | undefined;
customOptions?: Record<string, string> | undefined;
}, {
includeModules?: string[] | undefined;
maxMappedFunctions?: number | undefined;
minPodMemoryLimit?: number | undefined;
verbose?: boolean | undefined;
disableSourceMapsResolution?: boolean | undefined;
customOptions?: Record<string, string> | undefined;
}>;
export type HudOptions = z.infer<typeof HudInitOptionsSchema>;
declare const RawUserConfigSchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
includeModules: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
maxMappedFunctions: z.ZodOptional<z.ZodNumber>;
minPodMemoryLimit: z.ZodOptional<z.ZodNumber>;
verbose: z.ZodOptional<z.ZodBoolean>;
disableSourceMapsResolution: z.ZodOptional<z.ZodBoolean>;
customOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
}, "customOptions">, {
key: z.ZodOptional<z.ZodString>;
service: z.ZodOptional<z.ZodString>;
enable: z.ZodOptional<z.ZodBoolean>;
enableDapulse: z.ZodOptional<z.ZodBoolean>;
}>, "strip", z.ZodTypeAny, {
includeModules?: string[] | undefined;
maxMappedFunctions?: number | undefined;
minPodMemoryLimit?: number | undefined;
verbose?: boolean | undefined;
disableSourceMapsResolution?: boolean | undefined;
key?: string | undefined;
service?: string | undefined;
enable?: boolean | undefined;
enableDapulse?: boolean | undefined;
}, {
includeModules?: string[] | undefined;
maxMappedFunctions?: number | undefined;
minPodMemoryLimit?: number | undefined;
verbose?: boolean | undefined;
disableSourceMapsResolution?: boolean | undefined;
key?: string | undefined;
service?: string | undefined;
enable?: boolean | undefined;
enableDapulse?: boolean | undefined;
}>;
export type RawUserConfig = z.infer<typeof RawUserConfigSchema>;
export type UserConfigSource = "INIT" | "ENV" | "CONFIG_FILE" | "CONFIG_ENV" | "SETUP" | "DEFAULT";
export type UserConfig = {
[K in keyof RawUserConfig]: {
value: RawUserConfig[K];
source: UserConfigSource;
};
};
export declare function updateUserConfigFromEnv(): void;
export declare function updateUserConfigFromFile(OnInvalidZod: (path: string, jsonPath: string) => void, onInvalidJson: (path: string, message: string) => void, onInvalidFileAccesss: (path: string) => void): void;
export declare function isValidUserInput(): boolean;
export interface HudConfig {
sink: {
url: string;
timeout: number;
session_attr: string;
};
endpoints: {
init: string;
send: string;
batch: string;
logs: string;
fatalError: string;
getMode: string;
getRemoteConfig: string;
fileDeclarations: string;
sourceMap: string;
storeObject: string;
};
logger: {
[key: string]: {
levels: {
[key: string]: string;
};
};
};
investigation: {
objectVersion: string;
store: ObjectStoreConfig;
blacklistParams: string[];
censorshipRegexes: {
regex: RegExp;
replacement: string;
}[];
maxStringLength: number;
maxArrayLength: number;
maxObjectDepth: number;
limits: {
executionFlowMaxLength: number;
exceptionMaxLength: number;
};
};
userConfig: UserConfig;
loggerWorkerPortSizeLimit: number;
customerLoggerLevel: string;
logDirectory?: string;
hudModuleName: string;
invocationSampling: InvocationSampling;
modeInterval: number;
callerResetInterval: number;
logsSendInterval: number;
logPerfInterval: number;
endpointsInterval: number;
endpointsFirstSendWaitTime: number;
huddBinWidth: number;
workerGrace: number;
workerTimeout: number;
timeoutOnInit: number;
timeoutOnRegister: number;
timeoutOnMetrics: number;
workerMessageTimeout: number;
communicationBatchSize: number;
writePatched: boolean;
defaultOff: boolean;
disableOnBadApiKey: boolean;
disableOnBadServiceName: boolean;
cpuTimeCollection: boolean;
workloadMetadata: {
sendInterval: number;
aws: {
imds: {
baseURL: string;
tokenURI: string;
identityURI: string;
lifeCycleURI: string;
requestTimeout: number;
};
metadataFile: string;
};
kubernetes: {
namespaceFile: string;
uuidFile: string;
podMemoryLimitFile: string;
podCPULimitFile: string;
};
};
deleteLogsAfterSending: boolean;
supportSourceMap: boolean;
editInline: boolean;
bundlerBuildIdVarName: string;
bundlerBuildUuidNamespace: string;
functionUuidNamespace: string;
wrapVarPrefix: string;
functionIdVarName: string;
frameworksToPatch: FrameworkConfig;
communicationKeepalive: boolean;
communicationKeepaliveGrace: number;
maxWrappedFileSize: number;
express: {
layerStateVarName: string;
routeNamesVarName: string;
markedVarName: string;
wrapAllCallbacks: boolean;
};
supportedNodeVersions: string[];
hudPatchedName: string;
hudMetricName: string;
dynamicConfig: HudDynamicConfig;
isInvestigationEnabledByEnv: boolean;
suppressTraces: boolean;
lambdaMinimunMemory: number;
lambdaBaseGivenTime: number;
lambdaExtraGivenTimePerRequest: number;
lambdaMaxGivenTime: number;
throttleStatusCode: number;
esbuildPluginMessagePrefix: string;
esbuildGlobalVar: string;
esbuildMark: string;
esbuildMarkLength: number;
esbuildUploadSourceMapTimeout: number;
esbuildPluginLogsChunkSize: number;
esbuildPluginLogsBatchSize: number;
pluginsLogEndpoint: string;
fileless: boolean;
minPodMemoryLimit: number;
uninstrumentedFilesLogThreshold: number;
tsNodeConfigTimeout: number;
allowedEditExtensions: string[];
}
export declare const hudConfig: HudConfig;
export function init(apiKey?: string, service?: string, options?: HudOptions): Promise<void>;
export declare function isValidParam<T>(p: T | null | undefined): p is Exclude<T, null | undefined>;
export declare function _detachHud(shouldLogToUser?: boolean, forceLogToUser?: boolean): void;
export declare function onRequire(): void;
export type LogLevel = "error" | "warn" | "info" | "debug";
export type UserLog = {
level: LogLevel;
message: string;
errCode?: string;
moreInfo?: boolean;
};
export declare class HudError extends Error {
code: number;
name: string;
constructor(message?: string);
}
export type UserErrorTypes = "HudEnableNotSet" | "HudApiKeyNotSet" | "HudApiKeyInvalid" | "HudServiceNotSet" | "HudServiceInvalid" | "BothApiKeyAndServiceNotSet" | "InvalidTag" | "TagWithDots" | "TagsInvalidJson" | "ShutdownGracefully" | "UnsupportedNodeVersion" | "UnsupportedSyntax" | "ApiKeyDenied" | "UnsupportedLambdaMemory" | "JSONErrorInUserConfig" | "ZodErrorInUserConfig" | "ConfigInaccessible" | "InstrumentedFunctionCountExceeded" | "PodMemoryLimitTooLow" | "DebuggerAttached" | "LambdaNotViaLayer" | "TsNodeNotTranspileOnly" | "TsNodeNotFoundEvenThoughRunWithTsNode" | "EsbuildMissingKey" | "EsbuildFailedProcessingFile" | "EsbuildFailedBundling" | "EsbuildFailedParsingSourcemap" | "EsbuildFailedUploadingSourcemap" | "EsbuildFailedUploadingSourcemapUnauthorized" | "EsbuildUnsupportedPlatform" | "SetupCalledWithoutKey" | "SetupCalledWithoutService" | "InitSessionBeforeRegister" | "HudEnableIsFalse" | "UninstrumentedFilesLogThresholdExceeded" | "UninstrumentedFrameworks" | "UnsupportedFrameworkVersion" | "RegisterMisplacedNoDeclarations" | "YesDeclarationsNoMetrics" | "InitTimeout" | "RunningInBun" | "RunningOnWindows" | "UnsupportedNativeBuild" | "InitFailedDueGenericNetworkError" | "InitFailedDueNetworkTimeout" | "InitFailedDueNetworkRST" | "InitFailedDueSelfSignedCert" | "InitFailedDueDnsFailed" | "InitFailedDueBackendError";
export declare const UserErrorLogs: Record<UserErrorTypes, (...args: any[]) => UserLog>;
export interface MemoryInfo {
podMemoryLimitMB: number | null;
source: string | null;
}
export declare function getMemoryLimitInfo(): MemoryInfo;
export declare function isMemoryLimitBigEnough(memoryInfo: MemoryInfo): boolean;
export declare function isSupportedNative(): boolean;
export declare function shouldRunHud(): {
shouldRun: true;
} | {
shouldRun: false;
error: UserLog;
};
export interface CallContext {
wrappedCaller: string;
sample_flag?: boolean;
start: bigint;
end: bigint;
currentFlowId: string;
fixFlag?: boolean;
}
declare function _hudWrapperInitial(functionId: string, callContext: CallContext): void;
declare function _hudWrapperCatch(functionId: string, callContext: any, e: unknown): void;
declare function _hudWrapperFinally(functionId: string, callContext: any): void;
declare function _hudFixStack(functionId: string, callContext: any): void;
export declare function asyncIteratorWrapper(iter: Iterable<any> | AsyncIterable<any>): AsyncIterator<any, any, any>;
export declare const wrapperInitial: typeof _hudWrapperInitial;
export declare const wrapperCatch: typeof _hudWrapperCatch;
export declare const wrapperFinally: typeof _hudWrapperFinally;
export declare const fixStack: typeof _hudFixStack;
export declare function getUserTsNodeConfig(logToUser?: boolean): {
cwd?: string;
project?: string;
projectSearchDir?: string;
} | undefined;
export declare const hudRITM: typeof onRequireFn;
export declare function infoSafeLog(message: string): void;
export declare function errorSafeLog(message: string): void;
export {};