UNPKG

@obarlik/streaming-pipeline-core

Version:

🔄 Memory-efficient circular buffer streaming pipeline with universal processing - by Codechu

58 lines (57 loc) • 1.76 kB
/** * Observability and tracing support */ // Default feature flags export const DEFAULT_FEATURE_FLAGS = { enableDetailedLogging: true, enablePerformanceMetrics: true, enableDebugMode: false, maxContentLength: 1000000, // 1MB processorTimeout: 5000 // 5 seconds }; // Generate trace IDs export function generateTraceId() { return Math.random().toString(36).substring(2) + Date.now().toString(36); } export function generateSpanId() { return Math.random().toString(36).substring(2); } // Observability utilities export class ObservabilityUtils { static createLogContext(traceContext, additionalContext) { return { ...additionalContext, traceId: traceContext?.traceId, spanId: traceContext?.spanId, correlationId: traceContext?.correlationId }; } static createMetricTags(baseTag, traceContext, additionalTags) { const tags = { component: 'streaming-pipeline', operation: baseTag }; if (traceContext?.traceId) { tags.traceId = traceContext.traceId; } if (additionalTags) { Object.assign(tags, additionalTags); } return tags; } static sanitizeForLogging(content, maxLength = 100) { if (content.length <= maxLength) return content; return content.substring(0, maxLength) + '...'; } static calculatePerformanceGrade(duration, contentLength) { const ratio = contentLength / Math.max(duration, 1); // chars per ms if (ratio > 10000) return 'excellent'; if (ratio > 5000) return 'good'; if (ratio > 1000) return 'fair'; return 'poor'; } }