From 82902360570336b5d5b7e8a4fc8964ddf1604dee Mon Sep 17 00:00:00 2001 From: Thibault Le Ouay Date: Thu, 23 Oct 2025 14:06:05 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=B5=20more=20logs=20(#1474)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * more logs * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- apps/workflows/src/checker/alerting.ts | 13 ++++++++----- apps/workflows/src/cron/checker.ts | 14 +++++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/apps/workflows/src/checker/alerting.ts b/apps/workflows/src/checker/alerting.ts index 68eb07f7..8dd42235 100644 --- a/apps/workflows/src/checker/alerting.ts +++ b/apps/workflows/src/checker/alerting.ts @@ -6,10 +6,13 @@ import { selectWorkspaceSchema, } from "@openstatus/db/src/schema"; +import { getLogger } from "@logtape/logtape"; import type { Region } from "@openstatus/db/src/schema/constants"; import { checkerAudit } from "../utils/audit-log"; import { providerToFunction } from "./utils"; +const logger = getLogger("api-server"); + export const triggerNotifications = async ({ monitorId, statusCode, @@ -90,13 +93,13 @@ export const triggerNotifications = async ({ .all(); if ((smsSent[0]?.count ?? 0) > data.limits["sms-limit"]) { - console.log( + logger.warn( `SMS quota exceeded for workspace ${notif.notification.workspaceId}`, ); continue; } } - console.log( + logger.info( `💌 sending notification for ${monitorId} and chanel ${notif.notification.provider} for ${notifType}`, ); const monitor = selectMonitorSchema.parse(notif.monitor); @@ -107,7 +110,7 @@ export const triggerNotifications = async ({ cronTimestamp: cronTimestamp, }); } catch (_e) { - console.log("notification trigger already exists dont send again"); + logger.error("notification trigger already exists dont send again"); continue; } switch (notifType) { @@ -202,6 +205,6 @@ export const upsertMonitorStatus = async ({ set: { status, updatedAt: new Date() }, }) .returning(); - console.log(`📈 upsertMonitorStatus for ${monitorId} in region ${region}`); - console.log(`🤔 upsert monitor ${JSON.stringify(newData)}`); + logger.info(`📈 upsertMonitorStatus for ${monitorId} in region ${region}`); + logger.info("🤔 upsert monitor {*}", { ...newData }); }; diff --git a/apps/workflows/src/cron/checker.ts b/apps/workflows/src/cron/checker.ts index a8292c67..06d855e5 100644 --- a/apps/workflows/src/cron/checker.ts +++ b/apps/workflows/src/cron/checker.ts @@ -17,6 +17,7 @@ import { regionDict } from "@openstatus/regions"; import { db } from "../lib/db"; import { getSentry } from "@hono/sentry"; +import { getLogger } from "@logtape/logtape"; import type { monitorPeriodicitySchema } from "@openstatus/db/src/schema/constants"; import { type httpPayloadSchema, @@ -30,6 +31,8 @@ export const isAuthorizedDomain = (url: string) => { return url.includes(env().SITE_URL); }; +const logger = getLogger("api-server"); + const channelOptions = { // Conservative 5-minute keepalive (gRPC best practice) "grpc.keepalive_time_ms": 300000, @@ -89,12 +92,12 @@ export async function sendCheckerTasks( ) .all(); - console.log(`Start cron for ${periodicity}`); + logger.info(`Start cron for ${periodicity}`); const monitors = z.array(selectMonitorSchema).safeParse(result); const allResult = []; if (!monitors.success) { - console.error(`Error while fetching the monitors ${monitors.error.errors}`); + logger.error(`Error while fetching the monitors ${monitors.error.errors}`); throw new Error("Error while fetching the monitors"); } @@ -121,13 +124,13 @@ export async function sendCheckerTasks( const r = regionDict[region as keyof typeof regionDict]; if (!r) { - console.error(`Invalid region ${region}`); + logger.error(`Invalid region ${region}`); continue; } if (r.deprecated) { // Let's uncomment this when we are ready to remove deprecated regions // We should not use deprecated regions anymore - console.error(`Deprecated region ${region}`); + logger.error(`Deprecated region ${region}`); continue; } const response = createCronTask({ @@ -160,10 +163,11 @@ export async function sendCheckerTasks( const success = allRequests.filter((r) => r.status === "fulfilled").length; const failed = allRequests.filter((r) => r.status === "rejected").length; - console.log( + logger.info( `End cron for ${periodicity} with ${allResult.length} jobs with ${success} success and ${failed} failed`, ); if (failed > 0) { + logger.error("error with cron jobs"); getSentry(c).captureMessage( `sendCheckerTasks for ${periodicity} ended with ${failed} failed tasks`, "error", -- 2.51.2