feat(devops): separate public page server timing diagnostics
CI / check (push) Successful in 2m23s
CI / deploy (push) Successful in 1m13s
CI / publish-container (push) Successful in 44s

This commit is contained in:
Simo committed 2026-09-11 10:49:08 +02:00
1 parent d5091d1a73
commit baeb54aeb5
15 files changed
+315 -29

No files matched your search

+16 -5
View File
@@ -7,17 +7,28 @@ export type PerformanceMetrics = Record<Dependency, Measurement> & {
};
const context = new AsyncLocalStorage<PerformanceMetrics>();
export async function collectPerformance<T>(work: () => Promise<T>) {
export async function collectPerformance<T>(
work: () => Promise<T>,
onComplete?: (metrics: PerformanceMetrics) => void,
) {
const metrics: PerformanceMetrics = {
durationMs: 0,
database: { count: 0, durationMs: 0, errors: 0 },
external: { count: 0, durationMs: 0, errors: 0 },
};
const start = performance.now();
const value = await context.run(metrics, work);
metrics.durationMs = performance.now() - start;
// Background work may keep the async context: return a detached snapshot.
return { value, metrics: structuredClone(metrics) };
try {
const value = await context.run(metrics, work);
metrics.durationMs = performance.now() - start;
return { value, metrics: structuredClone(metrics) };
} finally {
metrics.durationMs = performance.now() - start;
try {
onComplete?.(structuredClone(metrics));
} catch {
/* Diagnostics must not change application outcomes. */
}
}
}
export async function measureDependency<T>(