/** * HTTP Middleware - 요청 컨텍스트 관리 * * HTTP 요청마다 TraceID를 생성하고 AsyncLocalStorage 컨텍스트를 * 시작하여 요청 전체에서 동일한 TraceID를 공유할 수 있게 합니다. */ import { ContextManager } from './context'; import { IngestHttpRequestLog } from '@ologstream/types'; /** * 요청 정보 */ export interface RequestInfo { traceId: string; method: string; url: string; path?: string; timestamp: number; } /** * 응답 정보 */ export interface ResponseInfo { traceId: string; method: string; url: string; path?: string; duration: number; timestamp: number; } /** * Middleware 옵션 */ export interface MiddlewareOptions { /** Context Manager */ contextManager: ContextManager; /** TraceID를 읽어올 헤더 이름 (기본값: 'x-trace-id') */ traceIdHeader?: string; /** 요청 시작 시 콜백 */ onRequest?: (info: RequestInfo) => void; /** 응답 완료 시 콜백 */ onResponse?: (info: ResponseInfo) => void; /** Inbound HTTP 로깅 활성화 여부 */ enableInboundHttpLogging?: boolean; /** Inbound HTTP 요청 캡처 콜백 */ onHttpRequest?: (request: IngestHttpRequestLog) => void; /** Inbound HTTP 응답 캡처 콜백 */ onHttpResponse?: (request: IngestHttpRequestLog) => void; } /** * UUID v4 형식의 TraceID를 생성합니다. */ export declare function generateTraceId(): string; /** * Express/Connect 호환 미들웨어 함수 타입 */ export type MiddlewareFunction = (req: unknown, res: unknown, next: (err?: unknown) => void) => void; /** * 함수 로깅을 위한 미들웨어를 생성합니다. * * @param options 미들웨어 옵션 * @returns Express/Connect 호환 미들웨어 */ export declare function createFunctionLogMiddleware(options: MiddlewareOptions): MiddlewareFunction; /** * HTTP 서버용 간단한 미들웨어 래퍼를 생성합니다. * Express 없이 Node.js http 모듈과 직접 사용할 수 있습니다. */ export declare function createHttpMiddleware(options: MiddlewareOptions): (req: unknown, res: unknown, handler: () => void | Promise) => void;