import {APM_ENV, ApmFeatures} from './apm';
import {Env} from './env';
import {ConsoleLog, Log} from './log';
import {Profiler} from './profiling';
import {Providers} from './providers';
import {Supplier} from './util';
export type LogBoostrap = { root: Log };
export type ApmBootstrap = {
features: Partial<Record<ApmFeatures, any>>;
};
export type BootstrapOptions = {
appName: string;
envLoaders?: Supplier<Record<string, string>>[];
log?: LogBoostrap;
apm?: ApmBootstrap;
profiler?: Profiler;
register?: [[any, string | { name: string }]];
}
export function bootstrap(options: BootstrapOptions) {
const providers = Providers.get();
if (options.envLoaders) {
const env = Env.load(options.envLoaders);
providers.register(env, Env);
}
providers.register(options.log?.root || ConsoleLog.create({ name: options.appName }), Log);
if (options.apm) {
for (const feature in options.apm.features) {
providers.register(options.apm.features[feature], APM_ENV[feature].type);
}
}
Iif (options.profiler) {
providers.register(options.profiler, Profiler);
}
Iif (options.register) {
for (const [service, name] of options.register) {
providers.register(service, name);
}
}
}
|