@ahmedhegazee/nestjs-telescope
Version:
Advanced observability and monitoring solution for NestJS applications with ML-powered analytics, enterprise features, and production-ready scaling
122 lines (121 loc) • 3.51 kB
TypeScript
/// <reference types="node" />
import { ExceptionFilter, ArgumentsHost } from '@nestjs/common';
import { ExceptionWatcherService } from './exception-watcher.service';
import { ExceptionWatcherConfig } from './exception-watcher.config';
export interface ExceptionContext {
id: string;
timestamp: Date;
error: Error;
errorType: string;
errorMessage: string;
errorCode?: string | number;
statusCode?: number;
stackTrace?: string;
stackFrames?: StackFrame[];
request?: {
id?: string;
method?: string;
url?: string;
path?: string;
headers?: Record<string, any>;
body?: any;
params?: Record<string, any>;
query?: Record<string, any>;
userAgent?: string;
ip?: string;
userId?: string;
sessionId?: string;
};
response?: {
statusCode?: number;
headers?: Record<string, any>;
body?: any;
duration?: number;
};
environment?: {
nodeVersion?: string;
platform?: string;
hostname?: string;
memory?: NodeJS.MemoryUsage;
uptime?: number;
};
traceId?: string;
requestId?: string;
userId?: string;
sessionId?: string;
classification?: {
type: ErrorClassificationType;
category: ErrorCategory;
severity: ErrorSeverity;
fingerprint: string;
groupId: string;
};
performance?: {
responseTime?: number;
memoryUsage?: number;
cpuUsage?: number;
activeConnections?: number;
};
}
export interface StackFrame {
function?: string;
file?: string;
line?: number;
column?: number;
source?: string;
context?: string[];
}
export declare enum ErrorClassificationType {
HTTP = "http",
VALIDATION = "validation",
AUTHENTICATION = "authentication",
AUTHORIZATION = "authorization",
DATABASE = "database",
NETWORK = "network",
BUSINESS_LOGIC = "business_logic",
SYSTEM = "system",
UNKNOWN = "unknown"
}
export declare enum ErrorCategory {
CLIENT_ERROR = "client_error",
SERVER_ERROR = "server_error",
NETWORK_ERROR = "network_error",
DATABASE_ERROR = "database_error",
VALIDATION_ERROR = "validation_error",
AUTHENTICATION_ERROR = "authentication_error",
AUTHORIZATION_ERROR = "authorization_error",
BUSINESS_ERROR = "business_error",
SYSTEM_ERROR = "system_error"
}
export declare enum ErrorSeverity {
LOW = "low",
MEDIUM = "medium",
HIGH = "high",
CRITICAL = "critical"
}
export declare class ExceptionWatcherFilter implements ExceptionFilter {
private readonly exceptionWatcherService;
private readonly config;
private readonly logger;
constructor(exceptionWatcherService: ExceptionWatcherService, config: ExceptionWatcherConfig);
catch(exception: any, host: ArgumentsHost): void;
private extractContext;
private extractHttpContext;
private extractEnvironmentContext;
private extractPerformanceContext;
private parseStackTrace;
private parseStackFrame;
private classifyError;
private classifyErrorType;
private classifyErrorCategory;
private classifyErrorSeverity;
private generateErrorFingerprint;
private generateGroupId;
private normalizeErrorMessage;
private shouldExcludeError;
private sanitizeHeaders;
private sanitizeBody;
private sendHttpResponse;
private generateExceptionId;
private hash;
}