Show request duration warning after 240s for long requests

This commit is contained in:
Konstantin Wohlwend 2026-02-10 18:31:56 -08:00
parent 419a9c4367
commit 7bda141ca5

View File

@ -114,15 +114,13 @@ export function handleApiRequest(handler: (req: NextRequest, options: any, reque
"/api/latest/internal/external-db-sync/sequencer",
"/api/latest/internal/external-db-sync/sync-engine",
];
if (!allowedLongRequestPaths.includes(req.nextUrl.pathname)) {
const warnAfterSeconds = 12;
runAsynchronously(async () => {
await wait(warnAfterSeconds * 1000);
if (!hasRequestFinished) {
captureError("request-timeout-watcher", new Error(`Request with ID ${requestId} to ${req.method} ${req.nextUrl.pathname} has been running for ${warnAfterSeconds} seconds. Try to keep requests short. The request may be cancelled by the serverless provider if it takes too long.`));
}
});
}
const warnAfterSeconds = allowedLongRequestPaths.includes(req.nextUrl.pathname) ? 180 : 12;
runAsynchronously(async () => {
await wait(warnAfterSeconds * 1000);
if (!hasRequestFinished) {
captureError("request-timeout-watcher", new Error(`Request with ID ${requestId} to ${req.method} ${req.nextUrl.pathname} has been running for ${warnAfterSeconds} seconds. Try to keep requests short. The request may be cancelled by the serverless provider if it takes too long.`));
}
});
if (!disableExtendedLogging) console.log(`[API REQ] [${requestId}] ${req.method} ${censoredUrl}`);
const timeStart = performance.now();