/** * Distributed Tracing System * * Implements distributed tracing for tracking requests across services */ export interface Span { traceId: string; spanId: string; parentSpanId?: string; name: string; startTime: number; endTime?: number; duration?: number; tags: Record; logs: Array<{ timestamp: number; message: string; fields?: Record; }>; status: 'ok' | 'error'; error?: { name: string; message: string; stack?: string; }; } export interface Trace { traceId: string; spans: Span[]; startTime: number; endTime?: number; duration?: number; rootSpan?: Span; } export declare class TracingSystem { private activeSpans; private completedTraces; private maxTraces; /** * Start a new trace */ startTrace(name: string, tags?: Record): Span; /** * Start a child span */ startSpan(name: string, parentSpan: Span, tags?: Record): Span; /** * End a span */ endSpan(span: Span, error?: Error): void; /** * Add tag to span */ setTag(span: Span, key: string, value: string | number | boolean): void; /** * Log event in span */ log(span: Span, message: string, fields?: Record): void; /** * Add span to trace */ private addToTrace; /** * Get trace by ID */ getTrace(traceId: string): Trace | undefined; /** * Get all traces */ getAllTraces(): Trace[]; /** * Clear all traces */ clearTraces(): void; /** * Generate unique ID */ private generateId; /** * Export traces in Jaeger format */ exportJaeger(): unknown[]; } /** * Default tracing system */ export declare const tracing: TracingSystem; /** * Trace a function */ export declare function trace(name: string, fn: (span: Span) => Promise, parentSpan?: Span): Promise; /** * Trace synchronous function */ export declare function traceSync(name: string, fn: (span: Span) => T, parentSpan?: Span): T; /** * Extract trace context from headers */ export declare function extractTraceContext(headers: Headers | Record): { traceId?: string; spanId?: string; }; /** * Inject trace context into headers */ export declare function injectTraceContext(span: Span, headers: Headers | Record): void; /** * Create tracing middleware */ export declare function createTracingMiddleware(): (request: TRequest & { headers?: Record; url: string; method: string; }, next: () => Promise; }>) => Promise; }>; /** * Trace database query */ export declare function traceDBQuery(query: string, fn: () => Promise, parentSpan?: Span): Promise; /** * Trace API call */ export declare function traceAPICall(method: string, url: string, fn: () => Promise, parentSpan?: Span): Promise; /** * Trace cache operation */ export declare function traceCacheOperation(operation: string, key: string, fn: () => Promise, parentSpan?: Span): Promise; /** * Get span context for propagation */ export declare function getSpanContext(span: Span): { traceId: string; spanId: string; parentSpanId?: string; }; /** * Create span from context */ export declare function createSpanFromContext(name: string, context: { traceId: string; spanId: string; parentSpanId?: string; }, tags?: Record): Span; //# sourceMappingURL=tracing.d.ts.map