🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
chore: add logging for failing health checks (#2611)
Max Deichmann4c6817731fc6
diff --git a/web/src/pages/api/public/health.ts b/web/src/pages/api/public/health.tsindex df1c463e1d..433a5c8b04 100644--- a/web/src/pages/api/public/health.ts+++ b/web/src/pages/api/public/health.ts@@ -8,53 +8,62 @@ export default async function handler(req: NextApiRequest,res: NextApiResponse,) {- await runMiddleware(req, res, cors);- await telemetry();- const failIfNoRecentEvents = req.query.failIfNoRecentEvents === "true";-try {- await prisma.$queryRaw`SELECT 1;`;+ await runMiddleware(req, res, cors);+ await telemetry();+ const failIfNoRecentEvents = req.query.failIfNoRecentEvents === "true";++ try {+ await prisma.$queryRaw`SELECT 1;`;- if (failIfNoRecentEvents) {- const now = Date.now();- const trace = await prisma.trace.findFirst({- where: {- timestamp: {- gte: new Date(now - 180000), // 3 minutes ago- lte: new Date(now),+ if (failIfNoRecentEvents) {+ const now = Date.now();+ const trace = await prisma.trace.findFirst({+ where: {+ timestamp: {+ gte: new Date(now - 180000), // 3 minutes ago+ lte: new Date(now),+ },},- },- select: {- id: true,- },- });- const observation = await prisma.observation.findFirst({- where: {- startTime: {- gte: new Date(now - 180000), // 3 minutes ago- lte: new Date(now),+ select: {+ id: true,},- },- select: {- id: true,- },- });- if (!!!trace || !!!observation) {- return res.status(503).json({- status: `No ${- !!!trace- ? "traces"- : !!!observation- ? "observations"- : "<should not happen>"- } within the last 3 minutes`,- version: VERSION.replace("v", ""),});+ const observation = await prisma.observation.findFirst({+ where: {+ startTime: {+ gte: new Date(now - 180000), // 3 minutes ago+ lte: new Date(now),+ },+ },+ select: {+ id: true,+ },+ });+ if (!!!trace || !!!observation) {+ return res.status(503).json({+ status: `No ${+ !!!trace+ ? "traces"+ : !!!observation+ ? "observations"+ : "<should not happen>"+ } within the last 3 minutes`,+ version: VERSION.replace("v", ""),+ });+ }}+ } catch (e) {+ console.log("Health check failed: db not available", e);+ return res.status(503).json({+ status: "Database not available",+ version: VERSION.replace("v", ""),+ });}} catch (e) {+ console.log("Health check failed: ", e);return res.status(503).json({- status: "Database not available",+ status: "Health check failed",version: VERSION.replace("v", ""),});}