diff --git a/admin-ui/app/api/error-monitoring/resolve-by-pattern/route.ts b/admin-ui/app/api/error-monitoring/resolve-by-pattern/route.ts new file mode 100644 index 0000000..064b793 --- /dev/null +++ b/admin-ui/app/api/error-monitoring/resolve-by-pattern/route.ts @@ -0,0 +1,47 @@ +import type { NextRequest } from "next/server"; +import { NextResponse } from "next/server"; + +export const dynamic = "force-dynamic"; + +export async function POST(request: NextRequest) { + const rawBase = process.env.ERROR_REPORTING_ADMIN_API_BASE?.trim(); + if (!rawBase) { + return NextResponse.json( + { + success: false, + message: "ERROR_REPORTING_ADMIN_API_BASE is not configured.", + }, + { status: 503 }, + ); + } + const base = rawBase.replace(/\/$/, ""); + const target = `${base}/api/error-monitoring/resolve-by-pattern`; + const body = await request.text(); + + const headers: Record = { + Accept: "application/json", + "Content-Type": request.headers.get("Content-Type") ?? "application/json", + }; + const cookie = request.headers.get("cookie"); + if (cookie) { + headers.Cookie = cookie; + } + const resolveHdr = request.headers.get("x-error-resolve-key"); + if (resolveHdr) { + headers["X-Error-Resolve-Key"] = resolveHdr; + } + + const upstream = await fetch(target, { + method: "POST", + headers, + body: body || undefined, + cache: "no-store", + }); + + const text = await upstream.text(); + const ct = upstream.headers.get("Content-Type") ?? "application/json; charset=utf-8"; + return new NextResponse(text, { + status: upstream.status, + headers: { "Content-Type": ct }, + }); +} diff --git a/admin-ui/app/api/error-monitoring/resolve-fixed-patterns/route.ts b/admin-ui/app/api/error-monitoring/resolve-fixed-patterns/route.ts new file mode 100644 index 0000000..027e349 --- /dev/null +++ b/admin-ui/app/api/error-monitoring/resolve-fixed-patterns/route.ts @@ -0,0 +1,47 @@ +import type { NextRequest } from "next/server"; +import { NextResponse } from "next/server"; + +export const dynamic = "force-dynamic"; + +export async function POST(request: NextRequest) { + const rawBase = process.env.ERROR_REPORTING_ADMIN_API_BASE?.trim(); + if (!rawBase) { + return NextResponse.json( + { + success: false, + message: "ERROR_REPORTING_ADMIN_API_BASE is not configured.", + }, + { status: 503 }, + ); + } + const base = rawBase.replace(/\/$/, ""); + const target = `${base}/api/error-monitoring/resolve-fixed-patterns`; + const body = await request.text(); + + const headers: Record = { + Accept: "application/json", + "Content-Type": request.headers.get("Content-Type") ?? "application/json", + }; + const cookie = request.headers.get("cookie"); + if (cookie) { + headers.Cookie = cookie; + } + const resolveHdr = request.headers.get("x-error-resolve-key"); + if (resolveHdr) { + headers["X-Error-Resolve-Key"] = resolveHdr; + } + + const upstream = await fetch(target, { + method: "POST", + headers, + body: body || undefined, + cache: "no-store", + }); + + const text = await upstream.text(); + const ct = upstream.headers.get("Content-Type") ?? "application/json; charset=utf-8"; + return new NextResponse(text, { + status: upstream.status, + headers: { "Content-Type": ct }, + }); +} diff --git a/api/src/routes/public/recentErrors.ts b/api/src/routes/public/recentErrors.ts index dea01f7..bf6b332 100644 --- a/api/src/routes/public/recentErrors.ts +++ b/api/src/routes/public/recentErrors.ts @@ -109,6 +109,29 @@ function parseStatusList(raw: string | undefined): string[] | null { return parts.length > 0 ? parts : ['open', 'investigating']; } + +function slimContext(ctx: Record | null): Record | null { + if (!ctx) return null; + const out: Record = {}; + for (const key of Object.keys(ctx).slice(0, 40)) out[key] = slimContextValue(ctx[key], 0); + return out; +} + +function slimContextValue(value: unknown, depth: number): unknown { + if (depth > 3) return '[nested]'; + if (typeof value === 'string') return value.length > 1500 ? `${value.slice(0, 1500)}…` : value; + if (value == null || typeof value === 'number' || typeof value === 'boolean') return value; + if (Array.isArray(value)) return value.slice(0, 20).map((item) => slimContextValue(item, depth + 1)); + if (typeof value === 'object') { + const nested: Record = {}; + for (const [key, item] of Object.entries(value as Record).slice(0, 30)) { + nested[key] = slimContextValue(item, depth + 1); + } + return nested; + } + return String(value).slice(0, 500); +} + async function handleRecentErrors(request: FastifyRequest, reply: FastifyReply): Promise { const db = request.server.db; @@ -321,6 +344,8 @@ async function handleRecentErrors(request: FastifyRequest, reply: FastifyReply): if (paperclip_project_id !== '') { rowOut.paperclip_project_id = paperclip_project_id; } + const contextData = slimContext(ctx); + if (contextData) rowOut.context_data = contextData; return rowOut; }); diff --git a/deploy/lxc/webhook-deploy.sh b/deploy/lxc/webhook-deploy.sh index e50f667..1e3937b 100755 --- a/deploy/lxc/webhook-deploy.sh +++ b/deploy/lxc/webhook-deploy.sh @@ -27,10 +27,10 @@ git checkout "${_DEPLOY_BRANCH}" git merge --ff-only "origin/${_DEPLOY_BRANCH}" echo "webhook-deploy: npm ci + build (ingest-api, admin-ui, collector-worker, api)" -(cd "${_ROOT}/ingest-api" && npm ci && npm run build) -(cd "${_ROOT}/admin-ui" && npm ci && npm run build) -(cd "${_ROOT}/collector-worker" && npm ci && npm run build) -(cd "${_ROOT}/api" && npm ci && npm run build) +(cd "${_ROOT}/ingest-api" && npm ci --include=dev && npm run build) +(cd "${_ROOT}/admin-ui" && npm ci --include=dev && npm run build) +(cd "${_ROOT}/collector-worker" && npm ci --include=dev && npm run build) +(cd "${_ROOT}/api" && npm ci --include=dev && npm run build) if getent passwd error-reporting >/dev/null 2>&1; then chown -R error-reporting:error-reporting "${_ROOT}"