syntropylog
Version:
An instance manager with observability for Node.js applications
41 lines (40 loc) • 1.88 kB
TypeScript
/**
* FILE: src/http/HttpManager.ts
* @description Manages the lifecycle and creation of multiple instrumented HTTP client instances.
*/
import { IContextManager } from '../context';
import { ILogger } from '../logger';
import { InstrumentedHttpClient } from './InstrumentedHttpClient';
import { SyntropyHttpConfig } from '../config';
/**
* @class HttpManager
* @description Manages the creation and retrieval of multiple instrumented HTTP client instances.
* It reads the configuration, creates an `InstrumentedHttpClient` for each defined
* instance by wrapping the user-provided adapter, and provides a way to retrieve them.
*/
export declare class HttpManager {
/** @private A map storing the created instrumented client instances by name. */
private readonly instances;
/** @private The logger instance for the manager itself. */
private readonly logger;
/** @private A reference to the context manager for dependency injection. */
private readonly contextManager;
/** @private The global application configuration. */
private readonly config;
/** @private The name of the default HTTP client instance. */
private defaultInstance?;
constructor(config: SyntropyHttpConfig, logger: ILogger, contextManager: IContextManager);
init(): void;
/**
* Retrieves a managed and instrumented HTTP client instance by its name.
* The returned client has a unified API via its `.request()` method.
* @param {string} name - The name of the HTTP client instance to retrieve.
* @returns {InstrumentedHttpClient} The requested client instance.
* @throws {Error} If no instance with the given name is found.
*/
getInstance(name?: string): InstrumentedHttpClient;
/**
* Clears all managed HTTP client instances. This is a simple cleanup operation.
*/
shutdown(): Promise<void>;
}