UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio

118 lines (117 loc) 3.97 kB
/** * Abstract base class for all observability exporters * Follows NeuroLink's factory pattern with a unified exporter interface */ import type { ExporterConfig, ExporterHealthStatus, ExportResult, SpanData } from "../../types/index.js"; /** * Abstract base class for all observability exporters * Provides common functionality: buffering, flush intervals, health checks, retry logic */ export declare abstract class BaseExporter { protected readonly name: string; protected readonly config: ExporterConfig; protected initialized: boolean; protected buffer: SpanData[]; protected readonly maxBufferSize: number; protected readonly retries: number; protected flushInterval: ReturnType<typeof setInterval> | null; protected lastExportTime: number; constructor(name: string, config: ExporterConfig); /** * Initialize the exporter connection * Must be called before exporting spans */ abstract initialize(): Promise<void>; /** * Export a single span * @param span - The span data to export */ abstract exportSpan(span: SpanData): Promise<ExportResult>; /** * Export multiple spans in batch * @param spans - Array of span data to export */ abstract exportBatch(spans: SpanData[]): Promise<ExportResult>; /** * Flush all buffered spans */ abstract flush(): Promise<void>; /** * Shutdown the exporter gracefully * Should flush remaining spans before closing */ abstract shutdown(): Promise<void>; /** * Check exporter health status * Implementations should make an actual API call to verify connectivity */ abstract healthCheck(): Promise<ExporterHealthStatus>; /** * Ping the exporter's backend to verify connectivity * Override this in subclasses to provide backend-specific health check */ protected ping(): Promise<void>; /** * Buffer a span for batch export * Triggers flush if buffer is full */ protected bufferSpan(span: SpanData): void; /** * Start automatic flush interval * @param intervalMs - Interval in milliseconds between flushes */ protected startFlushInterval(intervalMs: number): void; /** * Stop the automatic flush interval */ protected stopFlushInterval(): void; /** * Get exporter name */ getName(): string; /** * Check if exporter is initialized */ isInitialized(): boolean; /** * Get number of pending spans in buffer */ getPendingCount(): number; /** * Get last export timestamp */ getLastExportTime(): number; /** * Create a standard export result for success */ protected createSuccessResult(exportedCount: number, durationMs: number): ExportResult; /** * Create a standard export result for failure */ protected createFailureResult(spanIds: string[], error: string, durationMs: number, retryable?: boolean): ExportResult; /** * Create a standard health status */ protected createHealthStatus(healthy: boolean, errors?: string[]): ExporterHealthStatus; /** * Execute an operation with exponential backoff retry * @param operation - The async operation to execute * @param operationName - Name for logging purposes * @returns The result of the operation * @throws The last error if all retries fail */ protected withRetry<T>(operation: () => Promise<T>, operationName: string): Promise<T>; } /** * No-op exporter for when observability is disabled * Provides zero-overhead behavior */ export declare class NoOpExporter extends BaseExporter { constructor(); initialize(): Promise<void>; exportSpan(_span: SpanData): Promise<ExportResult>; exportBatch(_spans: SpanData[]): Promise<ExportResult>; flush(): Promise<void>; shutdown(): Promise<void>; healthCheck(): Promise<ExporterHealthStatus>; }