Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
4.4 kB ยท 149 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150import { FetchError } from "@openstatus/status-fetcher";import * as Sentry from "@sentry/deno";import type { SeverityLevel } from "@sentry/deno";
import { env } from "../env";
Sentry.init({ dsn: env().SENTRY_DSN, environment: env().NODE_ENV, tracesSampleRate: 0,});
export function runSentryCron(monitorSlug: string): { cronCompleted: () => Promise<void>; cronFailed: () => Promise<void>;} { const checkInId = Sentry.captureCheckIn({ monitorSlug, status: "in_progress", }); return { cronCompleted: async () => { Sentry.captureCheckIn({ checkInId, monitorSlug, status: "ok" }); await Sentry.flush(); }, cronFailed: async () => { Sentry.captureCheckIn({ checkInId, monitorSlug, status: "error" }); await Sentry.flush(); }, };}
export async function reportBackgroundError(message: string): Promise<void> { Sentry.captureMessage(message, "error"); await Sentry.flush();}
export type DetectionOutcome = | { kind: "applied"; provider: string } | { kind: "config-cleared" } | { kind: "suggest"; suggestion: string } | { kind: "schema-mismatch" } | { kind: "none" };
// One event tells the whole story of a probed tick: the fetch failure plus// what detection concluded. Fingerprinted per (slug, outcome) so repeats// collapse into a single issue; a schema mismatch is our bug, so it groups// per provider instead.export function reportDetectionStory(args: { slug: string; currentProvider: string; fetchError?: FetchError; outcome: DetectionOutcome; evidence: string[];}): void { const { slug, currentProvider, fetchError, outcome, evidence } = args; const story = (() => { switch (outcome.kind) { case "applied": return { fingerprint: [ "external-status-detect", slug, `applied:${outcome.provider}`, ], level: "info" as const, message: `provider auto-updated ${currentProvider} โ ${outcome.provider}`, }; case "config-cleared": return { fingerprint: ["external-status-detect", slug, "config-cleared"], level: "info" as const, message: `stale api_config cleared (provider ${currentProvider})`, }; case "suggest": return { fingerprint: ["external-status-detect", slug, outcome.suggestion], level: "warning" as const, message: `provider suggestion: ${outcome.suggestion} (currently ${currentProvider})`, }; case "schema-mismatch": return { fingerprint: ["external-status-detect", "schema", currentProvider], level: "error" as const, message: `JSON did not match the ${currentProvider} schema`, }; case "none": return { fingerprint: ["external-status-detect", slug, "none"], level: "warning" as const, message: `failing, no provider detected (currently ${currentProvider})`, }; } })(); Sentry.captureMessage(`external-status: ${slug} ${story.message}`, { level: story.level, fingerprint: story.fingerprint, tags: { cron: "external-status", phase: "detect", slug, current_provider: currentProvider, outcome: outcome.kind, }, extra: { evidence, fetchError: fetchError?.message, url: fetchError?.url, }, });}
export function reportDetectionWriteFailure(args: { slug: string; error: Error;}): void { Sentry.captureException(args.error, { tags: { cron: "external-status", phase: "detect", slug: args.slug }, });}
// Fires inside the per-service fetch loop, so no flush here โ the tick's// cronCompleted/cronFailed path flushes once the tick settles.export function reportFetchFailure(args: { phase: "status" | "incidents" | "components"; slug: string; error: FetchError; level?: SeverityLevel;}): void { const { phase, slug, error, level } = args; Sentry.captureException(error, { level, fingerprint: [ "external-status-fetch", slug, phase, error.kind ?? "unknown", String(error.httpStatus ?? ""), ], tags: { cron: "external-status", phase, slug, fetcher: error.fetcherName ?? "unknown", http_status: error.httpStatus, }, extra: { url: error.url }, });}