export async function measureFlow(operation, record, clock = performance) { let start; try { start = clock.now(); } catch { // A missing timer must not prevent the operation. } let outcome = "error"; try { const result = await operation(); outcome = "ok"; return result; } finally { try { const durationMs = clock.now() - start; if (Number.isFinite(durationMs) && durationMs >= 0) { // Do not wait for telemetry delivery; handle rejected collectors. Promise.resolve(record({ durationMs, outcome })).catch(() => {}); } } catch { // Timer and collector failures must not replace the result or error. } } }