Skip to content

Open-source status page, incident response and uptime monitoring

🔥 Improve error handling workflows (#1466)

Thibault Le Ouay6fd6233c6f67
diff --git a/.github/workflows/workflow-preview.yml b/.github/workflows/workflow-preview.yml
new file mode 100644
index 000000000..a5d59ee49
--- /dev/null
+++ b/.github/workflows/workflow-preview.yml
@@ -0,0 +1,56 @@
+name: Fly Preview Workflows
+on:
+ pull_request:
+ types: [opened, reopened, synchronize, closed]
+ paths:
+ - "apps/workflows/**"
+ - "packages/db/**"
+ - "packages/emails/**"
+ - "packages/utils/**"
+ - "packages/tsconfig/**"
+env:
+ FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
+ # Set these to your Fly.io organization and preferred region.
+ FLY_REGION: ams
+ FLY_ORG: openstatus
+
+jobs:
+ review_app:
+ runs-on: ubuntu-latest
+ outputs:
+ url: ${{ steps.deploy.outputs.url }}
+ # Only run one deployment at a time per PR.
+ concurrency:
+ group: pr-${{ github.event.number }}
+
+ # Deploying apps with this "review" environment allows the URL for the app to be displayed in the PR UI.
+ # Feel free to change the name of this environment.
+ environment:
+ name: pr-${{ github.event.number }} # The script in the `deploy` sets the URL output for each review app.
+ url: ${{ steps.deploy.outputs.url }}
+ steps:
+ - name: Get code
+ uses: actions/checkout@v4
+
+ - name: Deploy PR app to Fly.io
+ id: deploy
+ uses: superfly/[email protected]
+ with:
+ config: apps/workflows/fly.toml
+ vmsize: shared-cpu-1x
+ name: openstatus-workflows-pr-${{ github.event.number }}
+ secrets: |
+ DATABASE_URL=${{ secrets.STAGING_DB_URL }}
+ DATABASE_AUTH_TOKEN=${{ env.STAGING_DB_AUTH_TOKEN }}
+ RESEND_API_KEY=${{ secrets.STAGING_RESEND_API_KEY }}
+ UPSTASH_REDIS_REST_URL=test
+ UPSTASH_REDIS_REST_TOKEN=test
+ GCP_PROJECT_ID=test
+
+ - name: Clean up GitHub environment
+ uses: strumwolf/delete-deployment-environment@v2
+ if: ${{ github.event.action == 'closed' }}
+ with:
+ # ⚠️ The provided token needs permission for admin write:org
+ token: ${{ secrets.GITHUB_TOKEN }}
+ environment: pr-${{ github.event.number }}
diff --git a/apps/workflows/docker-compose.yaml b/apps/workflows/docker-compose.yaml
index dfce75561..6eff45224 100644
--- a/apps/workflows/docker-compose.yaml
+++ b/apps/workflows/docker-compose.yaml
@@ -23,4 +23,4 @@ services:
source: ./data
target: /app/data
image: workflows-test
- command: .
+ # command: .
diff --git a/apps/workflows/src/cron/checker.ts b/apps/workflows/src/cron/checker.ts
index 8b4f2edaf..a8292c67c 100644
--- a/apps/workflows/src/cron/checker.ts
+++ b/apps/workflows/src/cron/checker.ts
@@ -16,12 +16,14 @@ import type { Region } from "@openstatus/db/src/schema/constants";
import { regionDict } from "@openstatus/regions";
import { db } from "../lib/db";
+import { getSentry } from "@hono/sentry";
import type { monitorPeriodicitySchema } from "@openstatus/db/src/schema/constants";
import {
type httpPayloadSchema,
type tpcPayloadSchema,
transformHeaders,
} from "@openstatus/utils";
+import type { Context } from "hono";
import { env } from "../env";
export const isAuthorizedDomain = (url: string) => {
@@ -39,6 +41,7 @@ const channelOptions = {
export async function sendCheckerTasks(
periodicity: z.infer<typeof monitorPeriodicitySchema>,
+ c: Context,
) {
const client = new CloudTasksClient({
fallback: "rest",
@@ -156,12 +159,16 @@ export async function sendCheckerTasks(
const success = allRequests.filter((r) => r.status === "fulfilled").length;
const failed = allRequests.filter((r) => r.status === "rejected").length;
- const failedRequest = allRequests.filter((r) => r.status === "rejected");
- console.log(failedRequest?.at(0));
console.log(
`End cron for ${periodicity} with ${allResult.length} jobs with ${success} success and ${failed} failed`,
);
+ if (failed > 0) {
+ getSentry(c).captureMessage(
+ `sendCheckerTasks for ${periodicity} ended with ${failed} failed tasks`,
+ "error",
+ );
+ }
}
// timestamp needs to be in ms
const createCronTask = async ({
diff --git a/apps/workflows/src/cron/index.ts b/apps/workflows/src/cron/index.ts
index d589d469b..c3c2071ef 100644
--- a/apps/workflows/src/cron/index.ts
+++ b/apps/workflows/src/cron/index.ts
@@ -1,3 +1,4 @@
+import { getSentry } from "@hono/sentry";
import { monitorPeriodicitySchema } from "@openstatus/db/src/schema/constants";
import { Hono } from "hono";
import { env } from "../env";
@@ -29,13 +30,27 @@ app.get("/checker/:period", async (c) => {
if (!schema.success) {
return c.json({ error: schema.error.issues?.[0].message }, 400);
}
-
+ const sentry = getSentry(c);
+ const checkInId = sentry.captureCheckIn({
+ monitorSlug: period,
+ status: "in_progress",
+ });
try {
- await sendCheckerTasks(schema.data);
-
+ await sendCheckerTasks(schema.data, c);
+ sentry.captureCheckIn({
+ checkInId,
+ monitorSlug: period,
+ status: "ok",
+ });
return c.json({ success: schema.data }, 200);
} catch (e) {
console.error(e);
+ sentry.captureMessage(`Error in /checker/${period} cron: ${e}`, "error");
+ sentry.captureCheckIn({
+ checkInId,
+ monitorSlug: period,
+ status: "error",
+ });
return c.text("Internal Server Error", 500);
}
});
@@ -66,9 +81,17 @@ app.get("/monitors/:step", async (c) => {
}
if (!userId) {
+ getSentry(c).captureMessage(
+ "userId is missing in /monitors/:step cron",
+ "error",
+ );
return c.json({ error: "userId is required" }, 400);
}
if (!initialRun) {
+ getSentry(c).captureMessage(
+ "initalRun is missing in /monitors/:step cron",
+ "error",
+ );
return c.json({ error: "initialRun is required" }, 400);
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 250ce73dc..f4740d1cc 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1144,7 +1144,7 @@ importers:
version: 2.6.2
drizzle-orm:
specifier: 0.44.4
hono:
specifier: 4.5.3
version: 4.5.3
@@ -1160,7 +1160,7 @@ importers:
version: link:../../packages/tsconfig
'@types/bun':
specifier: latest
- version: 1.2.22(@types/[email protected])
+ version: 1.3.0(@types/[email protected])
typescript:
specifier: 5.7.2
version: 5.7.2
@@ -1301,10 +1301,10 @@ importers:
drizzle-orm:
specifier: 0.44.4
drizzle-zod:
specifier: 0.5.1
zod:
specifier: 3.24.2
version: 3.24.2
@@ -6433,8 +6433,8 @@ packages:
resolution: {integrity: sha512-SQFof9H+LXeWNz8wDe7oN5zu7ket0qwMu5vZubW4GCJ8Kkeh6nBWUz87+KTz/G3Kqsrp0j/W253XJb3KMEeg3w==}
- '@types/[email protected]':
- resolution: {integrity: sha512-5A/KrKos2ZcN0c6ljRSOa1fYIyCKhZfIVYeuyb4snnvomnpFqC0tTsEkdqNxbAgExV384OETQ//WAjl3XbYqQA==}
+ '@types/[email protected]':
+ resolution: {integrity: sha512-+lAGCYjXjip2qY375xX/scJeVRmZ5cY0wyHYyCYxNcdEXrQ4AOe3gACgd4iQ8ksOslJtW4VNxBJ8llUwc3a6AA==}
resolution: {integrity: sha512-2in/lrHRNmDvHPgyormtEralhPcN3An1gLjJzj2Bw145VBxkQ75JEXW6CTdMAwShiHQcYsl2d10IjQSdJSJz4g==}
@@ -7096,8 +7096,8 @@ packages:
resolution: {integrity: sha512-2dNB+dBwAcFW7RSd4y5vKycRjouKVklSwPk4EjBKWvcMYUBOqZGGNzV7+b2tfKBG3BeRXnozbnegVKR1azuATg==}
- resolution: {integrity: sha512-hwaAu8tct/Zn6Zft4U9BsZcXkYomzpHJX28ofvx7k0Zz2HNz54n1n+tDgxoWFGB4PcFvJXJQloPhaV2eP3Q6EA==}
+ resolution: {integrity: sha512-u8X0thhx+yJ0KmkxuEo9HAtdfgCBaM/aI9K90VQcQioAmkVp3SG3FkwWGibUFz3WdXAdcsqOcbU40lK7tbHdkQ==}
peerDependencies:
'@types/react': ^19
@@ -17388,9 +17388,9 @@ snapshots:
'@types/[email protected]': {}
dependencies:
- bun-types: 1.2.22(@types/[email protected])
+ bun-types: 1.3.0(@types/[email protected])
transitivePeerDependencies:
- '@types/react'
@@ -18260,7 +18260,7 @@ snapshots:
dependencies:
'@types/node': 24.0.8
'@types/react': 19.2.2
@@ -18830,7 +18830,7 @@ snapshots:
transitivePeerDependencies:
- supports-color
optionalDependencies:
'@cloudflare/workers-types': 4.20250303.0
'@libsql/client': 0.15.15([email protected])([email protected])
@@ -18838,11 +18838,11 @@ snapshots:
'@opentelemetry/api': 1.9.0
'@types/pg': 8.11.10
better-sqlite3: 11.7.0
- bun-types: 1.2.22(@types/[email protected])
+ bun-types: 1.3.0(@types/[email protected])
dependencies:
zod: 3.24.2