// src/core/trace-context.ts
// Centralized trace propagation
let currentTrace = null;
function generateId() {
    if (typeof crypto !== 'undefined' && crypto.randomUUID) {
        return crypto.randomUUID();
    }
    return Date.now().toString(36) + Math.random().toString(36).substr(2);
}
export function startTrace(operation, metadata) {
    const trace = {
        traceId: generateId(),
        operation,
        governanceApproved: false,
        startTime: Date.now(),
        metadata: metadata || {}
    };
    currentTrace = trace;
    return trace;
}
export function getCurrentTrace() {
    return currentTrace;
}
export function endTrace(approved = true) {
    if (currentTrace)
        currentTrace.governanceApproved = approved;
    currentTrace = null;
}
export function propagateTrace(childOperation) {
    if (!currentTrace)
        return null;
    return { ...currentTrace, parentId: currentTrace.traceId, operation: childOperation, startTime: Date.now() };
}
