Skip to content

Open-source status page, incident response and uptime monitoring

πŸͺ΅ more logs (#1474)

Thibault Le Ouay829023605703
diff --git a/apps/workflows/src/checker/alerting.ts b/apps/workflows/src/checker/alerting.ts
index 68eb07f7f..8dd422356 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 a8292c67c..06d855e53 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",