Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore: add query parameter to healthcheck which enables failure on unavailable database (#4238)

Steffen Schmitza0c6acf4e4e2
diff --git a/web/src/pages/api/public/health.ts b/web/src/pages/api/public/health.ts
index 46db1d9878..d299390150 100644
--- a/web/src/pages/api/public/health.ts
+++ b/web/src/pages/api/public/health.ts
@@ -13,6 +13,21 @@ export default async function handler(
await runMiddleware(req, res, cors);
await telemetry();
const failIfNoRecentEvents = req.query.failIfNoRecentEvents === "true";
+ const failIfDatabaseUnavailable =
+ req.query.failIfDatabaseUnavailable === "true";
+
+ try {
+ if (failIfDatabaseUnavailable) {
+ await prisma.$queryRaw`SELECT 1;`;
+ }
+ } catch (e) {
+ logger.error("Couldn't connect to database", e);
+ traceException(e);
+ return res.status(503).json({
+ status: "Database not available",
+ version: VERSION.replace("v", ""),
+ });
+ }
try {
if (failIfNoRecentEvents) {
@@ -53,10 +68,10 @@ export default async function handler(
}
}
} catch (e) {
- logger.error("Couldn't fetch recent events: db not available", e);
+ logger.error("Couldn't fetch recent events", e);
traceException(e);
return res.status(503).json({
- status: "Database not available",
+ status: "Couldn't fetch recent events",
version: VERSION.replace("v", ""),
});
}