statsOf
How many of the spans where says there are, how many failed, and their p95.
import { percentileOf } from "#codebase/tcmts/cli/traced"; import type { DatabaseSync } from "node:sqlite"; export function statsOf( db: DatabaseSync, where: string, args: (string | number)[], ): { n: number; errors: number; p95: number } { const s = db .prepare(`SELECT count(*) AS n, sum(error IS NOT NULL) AS errors FROM spans WHERE ${where}`) .get(...args) as { n: number; errors: number | null }; return { n: s.n, errors: s.errors ?? 0, p95: s.n ? percentileOf(db, where, args, s.n, 0.95) : 0 }; }