peppa/apps/web/instrumentation.ts
peppa-bot ec7345f483
Some checks failed
peppa/lint lint: success за 3с
peppa/typecheck typecheck: success за 51с
peppa/build build: success за 36с
peppa/bundle bundle: success за 0с
peppa/test test: failure за 1591с
peppa-ci / ci (pull_request) Failing after 28m44s
PEP-317: страница «Gitea» не ждёт Git-сервер — список из памяти при любом возрасте, переживает перезапуск
Последний список отдаётся сразу (старше минуты — обновление в фоне), хранится в settings
`gitea.overview` и прогревается при старте веба; без списка — «загружается». Ждёт Gitea
только «Получить заново» и «Сделать закрытым».

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 10:13:36 +00:00

43 lines
2.4 KiB
TypeScript

// Runs once when the Next server starts: the web's heartbeat for service monitoring (PEP-20)
// and the runner-client mode (PEP-21): the web enqueues runner commands, the watchdog runs them.
export async function register() {
if (process.env.NEXT_RUNTIME !== "nodejs") return;
const { beat, installCrashReporting, installServiceLog } = await import("@peppa/core");
// PEP-291: the log also goes to $PEPPA_HOME/logs/web.log — it survives a redeploy.
installServiceLog("web");
const { db } = await import("@/lib/db");
// PEP-91: a crash of the web goes to Bugsink before launchd restarts it.
installCrashReporting(db, "web");
// PEP-213: page and server action timing, slow ones → Bugsink, the day's numbers → /observability.
const { installRequestTiming } = await import("@peppa/core");
const { Server } = await import("node:http");
installRequestTiming(db, Server.prototype as never);
const { setRunnerClient } = await import("@peppa/runner");
setRunnerClient(true, db);
// PEP-225: the tab's WebSocket (/api/ws) — served by apps/web/server.ts in this process.
const { registerLiveWs } = await import("@/lib/live-server");
registerLiveWs();
// PEP-317: the «Gitea» page's list is ready before the first visit (never waits, never throws).
const { warmGiteaOverview } = await import("@peppa/core");
void warmGiteaOverview(db);
const version = process.env.NEXT_PUBLIC_PEPPA_VERSION;
const tick = () => beat(db, "web", { version }).catch((e) => console.error(`heartbeat: ${(e as Error).message}`));
void tick();
setInterval(tick, 60_000).unref();
}
/** PEP-91: an error while rendering or handling a request → Bugsink (PEP-api). */
export async function onRequestError(err: unknown, request: { path: string; method: string; headers: Record<string, string | string[] | undefined> }, context: { routerKind: string; routePath: string; routeType: string }) {
if (process.env.NEXT_RUNTIME !== "nodejs") return;
const { reportRequestError } = await import("@peppa/core");
const { db } = await import("@/lib/db");
const ua = request.headers["user-agent"];
// PEP-309: a refusal shown to the person (`PeppaError`) is not reported.
await reportRequestError(db, err, {
service: "web",
where: `${request.method} ${context.routePath}`,
request: { url: request.path, method: request.method, userAgent: typeof ua === "string" ? ua : undefined },
tags: { route_type: context.routeType },
});
}