/** * Metrics Collector * * Generic metrics collection system for tracking performance and latency. * Stores metrics in memory (for fast access) and optionally persists to a configured backend. * * Works with any persistence backend by implementing the MetricsPersistence interface. */ import type { AgentMetrics, ToolMetrics, LatencyMetrics, RequestTimingMetrics, MetricsSnapshot, MetricsSummary } from './types'; import type { MetricsPersistence } from './persistence'; import type { MetricsFilter } from './query'; /** * Logger interface - allows projects to use their own logging system */ export interface MetricsLogger { info(message: string, data?: Record): void; debug(message: string, data?: Record): void; warn(message: string, data?: Record): void; error(message: string, data?: Record): void; } /** * No-op logger (silent by default) */ export declare class NoOpLogger implements MetricsLogger { info(): void; debug(): void; warn(): void; error(): void; } /** * Event callbacks for metrics recording */ export interface MetricsEventCallbacks { /** * Called when an agent metric is recorded */ onAgentRecorded?: (metrics: AgentMetrics) => void; /** * Called when a tool metric is recorded */ onToolRecorded?: (metrics: ToolMetrics) => void; /** * Called when a latency metric is recorded */ onLatencyRecorded?: (metrics: LatencyMetrics) => void; /** * Called when a request timing metric is recorded */ onRequestTimingRecorded?: (metrics: RequestTimingMetrics) => void; } /** * Configuration options for MetricsCollector */ export interface MetricsCollectorConfig { /** * Maximum number of metrics to keep in memory (default: 1000) * Oldest metrics are removed when limit is reached (FIFO) */ maxMetrics?: number; /** * Whether to validate metrics before recording (default: true) */ validateMetrics?: boolean; /** * Whether to throw errors on validation failure (default: false) * If false, invalid metrics are logged but not recorded */ throwOnValidationError?: boolean; /** * Event callbacks for metrics recording */ callbacks?: MetricsEventCallbacks; /** * Timeline analysis configuration * Automatically generates timeline breakdowns when client timing is available */ timelineAnalysis?: { /** * Enable automatic timeline analysis and logging (default: false) */ enabled?: boolean; /** * Custom duration formatter function */ formatDuration?: (ms: number) => string; /** * Log level for timeline analysis (default: 'info') */ logLevel?: 'info' | 'debug' | 'warn'; }; } declare class MetricsCollector { private agents; private tools; private latency; private requestTimings; private maxMetrics; private validateMetrics; private throwOnValidationError; private persistence; private logger; private callbacks; private timelineConfig; constructor(persistence?: MetricsPersistence, logger?: MetricsLogger, config?: MetricsCollectorConfig); /** * Configure persistence backend */ setPersistence(persistence: MetricsPersistence): void; /** * Configure logger */ setLogger(logger: MetricsLogger): void; /** * Update configuration */ configure(config: Partial): void; /** * Set event callbacks */ setCallbacks(callbacks: MetricsEventCallbacks): void; /** * Record multiple agent metrics in batch * More efficient than calling recordAgent() multiple times */ recordAgents(metricsArray: AgentMetrics[]): void; /** * Record agent execution metrics * Stores in memory and persists to database asynchronously */ recordAgent(metrics: AgentMetrics): void; /** * Record multiple tool metrics in batch * More efficient than calling recordTool() multiple times */ recordTools(metricsArray: ToolMetrics[]): void; /** * Record tool execution metrics * Stores in memory and persists to database asynchronously */ recordTool(metrics: ToolMetrics): void; /** * Record multiple latency metrics in batch * More efficient than calling recordLatency() multiple times */ recordLatencies(metricsArray: LatencyMetrics[]): void; /** * Record latency metrics * Stores in memory and persists to database asynchronously */ recordLatency(metrics: LatencyMetrics): void; /** * Record multiple request timing metrics in batch * More efficient than calling recordRequestTiming() multiple times */ recordRequestTimings(metricsArray: RequestTimingMetrics[]): void; /** * Record request timing metrics (client vs server) * Stores in memory and persists to database asynchronously */ recordRequestTiming(metrics: RequestTimingMetrics): void; /** * Get current snapshot of all metrics */ getSnapshot(): MetricsSnapshot & { requestTimings: RequestTimingMetrics[]; }; /** * Get summary statistics */ getSummary(timeRangeMs?: number): MetricsSummary; /** * Clear all metrics */ clear(): void; /** * Query metrics with flexible filter criteria */ queryMetrics(filter: MetricsFilter): { agents: AgentMetrics[]; tools: ToolMetrics[]; latency: LatencyMetrics[]; requestTimings: RequestTimingMetrics[]; }; /** * Get metrics for a specific context * Loads from memory first, then from persistence backend if needed */ getContextMetrics(contextId: string): Promise<{ agents: AgentMetrics[]; tools: ToolMetrics[]; latency: LatencyMetrics[]; requestTimings: RequestTimingMetrics[]; }>; /** * @deprecated Use getContextMetrics instead * Backward compatibility method for HYPATIA */ getConversationMetrics(conversationId: string): Promise<{ agents: AgentMetrics[]; tools: ToolMetrics[]; latency: LatencyMetrics[]; }>; } export declare const metricsCollector: MetricsCollector; export { MetricsCollector }; //# sourceMappingURL=collector.d.ts.map