/** * Prometheus Metrics Collector * * Why: Observability for production deployments * * Tracks: * - HTTP requests (status, method, path) * - Session lifecycle (active, created, destroyed) * - MCP operations (tool calls, duration, errors) * - API calls to backend (operation, status, duration) */ import { Registry } from 'prom-client'; export interface MetricsCollectorConfig { enabled: boolean; prefix?: string; } export interface MetricsContextLabels { profileId?: string | null; tenantId?: string | null; } export declare class MetricsCollector { private registry; private enabled; private httpRequestsTotal; private httpRequestDuration; private sessionsActive; private sessionsCreatedTotal; private sessionsDestroyedTotal; private mcpToolCallsTotal; private mcpToolCallDuration; private mcpToolCallErrors; private toolsTotal; private toolsFiltered; private toolsSession; private toolFilterRejections; private toolFilterPatterns; private apiCallsTotal; private apiCallDuration; private apiCallErrors; private apiCacheEventsTotal; constructor(config: MetricsCollectorConfig); /** * Record HTTP request */ recordHttpRequest(method: string, path: string, status: number, durationSeconds: number, context?: MetricsContextLabels): void; /** * Record session created */ recordSessionCreated(context?: MetricsContextLabels): void; /** * Record session destroyed */ recordSessionDestroyed(context?: MetricsContextLabels): void; /** * Record MCP tool call */ recordToolCall(tool: string, status: 'success' | 'error', durationSeconds: number, context?: MetricsContextLabels): void; /** * Record MCP tool call error */ recordToolCallError(tool: string, errorType: string, context?: MetricsContextLabels): void; recordToolsTotal(source: string, count: number): void; recordToolsFiltered(source: string, action: string, count: number): void; recordToolsSession(sessionId: string, count: number): void; clearToolsSession(sessionId: string): void; recordToolFilterRejection(tool: string, source: string): void; recordToolFilterPatternCount(type: string, count: number): void; /** * Record API call to backend */ recordApiCall(operation: string, status: number, durationSeconds: number, context?: MetricsContextLabels): void; /** * Record API call error */ recordApiCallError(operation: string, errorType: string, context?: MetricsContextLabels): void; recordApiCacheEvent(operation: string, event: string, context?: MetricsContextLabels): void; /** * Get metrics in Prometheus format */ getMetrics(): Promise; /** * Get registry (for testing) */ getRegistry(): Registry; /** * Normalize path for metrics (remove dynamic segments) * * Why: Avoid high cardinality in metrics labels * * Examples: * - /mcp?sessionId=abc123 -> /mcp * - /metrics -> /metrics * - /health -> /health */ private normalizePath; /** * Get status label (2xx, 4xx, 5xx) * * Why: Group similar statuses to reduce cardinality */ private getStatusLabel; private resolveContextLabels; } //# sourceMappingURL=metrics.d.ts.map