UNPKG

@sonatel-os/juf-xpress-logger-edge

Version:

JUF XPress logger for Node Edge

80 lines (79 loc) 3.76 kB
/** * Observability * @namespace Core\Observable */ export default class Observability { /** * Factory method to create an instance of Observability. * @static * @param {object} options - Configuration options for initializing the observability agent. * @returns {Observability} - An instance of Observability. */ static createObservabilityAgent(options: object): Observability; /** * Creates an instance of Observability with APM configurations. * @constructor * @param {object} options - Configuration options for initializing the APM client. * @param {string} options.serviceName - The name of the service being monitored. * @param {string} options.serverUrl - The URL of the APM server. * @param {boolean} [options.startApmAgent=false] - Whether to start the observability agent. * @param {string} [options.secretToken] - Secret token for the APM server. * @param {string} [options.environment='development'] - The environment in which the service is running. * @param {string} [options.logLevel='info'] - The log level for logging. */ constructor(options: { serviceName: string; serverUrl: string; startApmAgent?: boolean | undefined; secretToken?: string | undefined; environment?: string | undefined; logLevel?: string | undefined; }); /** * Starts the observability agent. */ start(): void; /** * Middleware for capturing APM data and handling transactions. * @param {object} params - Parameters for the middleware. * @param {string} params.path - The path of the request. * @param {string} params.method - The HTTP method of the request. * @param {object} params.headers - The headers of the request. * @param {object} params.routeParams - The route parameters of the request. * @param {object} params.queryParams - The query parameters of the request. * @param {object} [params.payload] - The request payload. * @param {Function} callback - Callback function to be executed after middleware processing. * @param {object} httpListener - HTTP listener object with response handling functions. * @param {Function} httpListener.onFunction - Function that listens to HTTP events (e.g., 'finish'). * @param {Function} httpListener.callback - Callback function to execute after the listener function. * @throws {Error} Throws error if there is an issue with processing. */ middleware({ path, method, headers, routeParams, queryParams, payload }: { path: string; method: string; headers: object; routeParams: object; queryParams: object; payload?: object | undefined; }, callback: Function, httpListener: { onFunction: Function; callback: Function; }): Promise<void>; /** * Starts a new span for an existing transaction, typically for monitoring external requests or operations. * @param {string} spanName - The name of the span to be started. * @param {string} spanType - The type of the span (e.g., 'external', 'db'). * @param {object} payload - The data sent or being treated in your span. * @returns {Object|null} - Returns a dummy span object or null. */ startTransactionSpan(spanName: string, spanType: string | undefined, payload: object): Object | null; /** * Ends a given span and logs its duration for debugging purposes. * @param {object} span - The span object to be ended. * @throws {Error} Throws error if the span cannot be ended. * @example * observability.endTransactionSpan(span); */ endTransactionSpan(span: object): Promise<void>; #private; }