From 5f7875ff185df00cd66ed219c05fb6d33bcab31c Mon Sep 17 00:00:00 2001 From: simoleo89 Date: Mon, 31 Aug 2026 21:26:29 +0200 Subject: [PATCH] chore: log server rendering failures --- src/instrumentation.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/instrumentation.ts diff --git a/src/instrumentation.ts b/src/instrumentation.ts new file mode 100644 index 00000000..2e2c44c7 --- /dev/null +++ b/src/instrumentation.ts @@ -0,0 +1,22 @@ +import type { Instrumentation } from "next"; + +export const onRequestError: Instrumentation.onRequestError = async ( + error, + request, + context, +) => { + if (process.env.NEXT_RUNTIME !== "nodejs") return; + + const { logServerError } = await import("@/lib/server-log"); + logServerError("next.request_failed", error, { + path: request.path.split("?", 1)[0] ?? request.path, + method: request.method, + routePath: context.routePath, + routeType: context.routeType, + renderSource: context.renderSource, + digest: + typeof error === "object" && error !== null && "digest" in error + ? String(error.digest) + : null, + }); +};