toto-agent
Version:
Chatbot agent and reusable components for Toto platform
103 lines (102 loc) • 2.77 kB
TypeScript
/**
* Simplified Monitoring Service for toto-agent
* Provides basic logging, performance tracking, and error handling
*/
export interface MonitoringConfig {
environment: string;
release: string;
enablePerformanceMonitoring: boolean;
enableErrorTracking: boolean;
logLevel: 'debug' | 'info' | 'warn' | 'error';
}
export interface PerformanceMetrics {
requestId: string;
startTime: number;
endTime: number;
duration: number;
operation: string;
success: boolean;
error?: string;
metadata?: Record<string, any>;
}
export interface BusinessMetrics {
sessionId: string;
userId?: string;
caseId?: string;
intent: string;
agentType: string;
responseTime: number;
userSatisfaction?: number;
conversion?: boolean;
dropoff?: boolean;
}
export declare class SimpleMonitoringService {
private config;
private isInitialized;
private performanceLogs;
private businessLogs;
private errorLogs;
constructor(config: MonitoringConfig);
private initialize;
/**
* Track performance metrics
*/
trackPerformance(metrics: PerformanceMetrics): void;
/**
* Track business metrics
*/
trackBusinessMetrics(metrics: BusinessMetrics): void;
/**
* Capture and report errors
*/
captureError(error: Error, context?: Record<string, any>): void;
/**
* Add breadcrumb for debugging
*/
addBreadcrumb(message: string, category: string, data?: Record<string, any>): void;
/**
* Start performance transaction
*/
startTransaction(operation: string, requestId: string): PerformanceMetrics;
/**
* End performance transaction
*/
endTransaction(metrics: PerformanceMetrics, success: boolean, error?: string): void;
/**
* Structured logging with different levels
*/
log(level: 'debug' | 'info' | 'warn' | 'error', message: string, data?: Record<string, any>): void;
/**
* Health check for monitoring service
*/
getHealthStatus(): {
status: 'healthy' | 'unhealthy';
details: Record<string, any>;
};
/**
* Get performance analytics
*/
getPerformanceAnalytics(): {
totalRequests: number;
averageResponseTime: number;
successRate: number;
topOperations: Array<{
operation: string;
count: number;
avgDuration: number;
}>;
};
/**
* Get business analytics
*/
getBusinessAnalytics(): {
totalInteractions: number;
conversionRate: number;
dropoffRate: number;
averageSatisfaction: number;
topIntents: Array<{
intent: string;
count: number;
}>;
};
}