🪢 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
feat(api): add `failIfNoEventsInLastMinute` flag to `/health` (#1642)
Marc Klingen3227cca75613
diff --git a/web/src/pages/api/public/health.ts b/web/src/pages/api/public/health.tsindex 44f549a850..cb9bf9cc59 100644--- a/web/src/pages/api/public/health.ts+++ b/web/src/pages/api/public/health.ts@@ -10,15 +10,57 @@ export default async function handler() {await runMiddleware(req, res, cors);await telemetry();+ const failIfNoEventsInLastMinute =+ req.query.failIfNoEventsInLastMinute === "true";+try {await prisma.$queryRaw`SELECT 1;`;++ if (failIfNoEventsInLastMinute) {+ const now = Date.now();+ const trace = await prisma.trace.findFirst({+ where: {+ timestamp: {+ gte: new Date(now - 60000),+ lte: new Date(now),+ },+ },+ select: {+ id: true,+ },+ });+ const observation = await prisma.observation.findFirst({+ where: {+ startTime: {+ gte: new Date(now - 60000),+ 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 minute`,+ version: VERSION.replace("v", ""),+ });+ }+ }} catch (e) {return res.status(503).json({status: "Database not available",version: VERSION.replace("v", ""),});}- return res- .status(200)- .json({ status: "OK", version: VERSION.replace("v", "") });+ return res.status(200).json({+ status: "OK",+ version: VERSION.replace("v", ""),+ });}