Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
tb update (#2475)
Thibault Le Ouayb6c96d5108ec
diff --git a/.env.docker.example b/.env.docker.exampleindex bef5b3d51..c43abaafc 100644--- a/.env.docker.example+++ b/.env.docker.example@@ -44,6 +44,10 @@ TINYBIRD_TOKEN=# For local Tinybird container, set to: http://tinybird-local:7181TINYBIRD_URL=+# Set to "true" to resolve every Tinybird pipe and ingest to empty instead of+# calling the instance above (optional - defaults to off).+TINYBIRD_NOOP=+# ============================================================================# [REQUIRED] Resend API key for sending magic link emailsdiff --git a/apps/dashboard/src/scripts/export-blog-post-metrics.ts b/apps/dashboard/src/scripts/export-blog-post-metrics.tsindex 023bcff26..8eb63e249 100644--- a/apps/dashboard/src/scripts/export-blog-post-metrics.ts+++ b/apps/dashboard/src/scripts/export-blog-post-metrics.ts@@ -21,7 +21,11 @@ async function main() {throw new Error("TINY_BIRD_API_KEY environment variable is required");}- const tb = new OSTinybird(tinybirdApiKey);+ const tb = new OSTinybird({+ token: tinybirdApiKey,+ baseUrl: process.env.TINYBIRD_URL,+ noop: process.env.TINYBIRD_NOOP,+ });console.log(`Fetching data for monitor ID: ${MONITOR_ID}`);diff --git a/apps/server/.env.example b/apps/server/.env.exampleindex 4f4fafd3c..eacb114d2 100644--- a/apps/server/.env.example+++ b/apps/server/.env.example@@ -3,6 +3,12 @@ DATABASE_AUTH_TOKEN=NODE_ENV=productionUNKEY_TOKEN=TINY_BIRD_API_KEY=+# Tinybird instance for pipes and audit logs. Defaults to the cloud API;+# point at http://tinybird-local:7181 for the local container.+TINYBIRD_URL=+# Set to "true" to resolve every pipe and ingest to empty instead of calling+# Tinybird — keeps local runs off the configured instance.+TINYBIRD_NOOP=UPSTASH_REDIS_REST_URL=UPSTASH_REDIS_REST_TOKEN=RESEND_API_KEY=diff --git a/apps/server/src/env.ts b/apps/server/src/env.tsindex 12ee5b4d2..b0472b416 100644--- a/apps/server/src/env.ts+++ b/apps/server/src/env.ts@@ -8,6 +8,7 @@ export const env = createEnv({UNKEY_TOKEN: z.string().min(1),TINY_BIRD_API_KEY: z.string().min(1),TINYBIRD_URL: z.string().default("https://api.tinybird.co"),+ TINYBIRD_NOOP: z.stringbool().catch(false),UPSTASH_REDIS_REST_URL: z.string().min(1),UPSTASH_REDIS_REST_TOKEN: z.string().min(1),FLY_REGION: z.enum(monitorRegions),diff --git a/apps/server/src/libs/clients.ts b/apps/server/src/libs/clients.tsindex d777a8fb3..df937230c 100644--- a/apps/server/src/libs/clients.ts+++ b/apps/server/src/libs/clients.ts@@ -10,7 +10,11 @@ import { env } from "@/env";*/// Tinybird client singleton-export const tb = new OSTinybird(env.TINY_BIRD_API_KEY);+export const tb = new OSTinybird({+ token: env.TINY_BIRD_API_KEY,+ baseUrl: env.TINYBIRD_URL,+ noop: env.TINYBIRD_NOOP,+});// Redis client singletonexport const redis = Redis.fromEnv();diff --git a/apps/server/src/routes/mcp/adapter.ts b/apps/server/src/routes/mcp/adapter.tsindex 2f3d2a7d9..d4ff8d1fc 100644--- a/apps/server/src/routes/mcp/adapter.ts+++ b/apps/server/src/routes/mcp/adapter.ts@@ -4,6 +4,8 @@ import type { Scope, Workspace } from "@openstatus/db/src/schema";import { type ServiceContext, ServiceError } from "@openstatus/services";import { ZodError } from "zod";+import { tb } from "@/libs/clients";+/*** Build a `ServiceContext` for an MCP-originated request.*@@ -31,6 +33,7 @@ export function toServiceCtx(args: {scopes: args.apiKey.scopes,},requestId: args.requestId,+ tb,};}diff --git a/apps/server/src/routes/rpc/adapter.ts b/apps/server/src/routes/rpc/adapter.tsindex 7bf394f47..5ce3da0ed 100644--- a/apps/server/src/routes/rpc/adapter.ts+++ b/apps/server/src/routes/rpc/adapter.ts@@ -2,6 +2,8 @@ import { Code, ConnectError } from "@connectrpc/connect";import { type ServiceContext, ServiceError } from "@openstatus/services";import { ZodError } from "zod";+import { tb } from "@/libs/clients";+import type { RpcContext } from "./interceptors";/**@@ -19,6 +21,7 @@ export function toServiceCtx(rpcCtx: RpcContext): ServiceContext {scopes: rpcCtx.apiKey.scopes,},requestId: rpcCtx.requestId,+ tb,};}diff --git a/apps/server/src/routes/slack/agent.ts b/apps/server/src/routes/slack/agent.tsindex 739deb375..36771a745 100644--- a/apps/server/src/routes/slack/agent.ts+++ b/apps/server/src/routes/slack/agent.ts@@ -3,6 +3,8 @@ import type { ServiceContext } from "@openstatus/services";import { generateText, stepCountIs } from "ai";import type { ModelMessage } from "ai";+import { tb } from "@/libs/clients";+import { buildSlackTools } from "./registry-runner";import { buildSystemPrompt } from "./system-prompt";@@ -60,6 +62,7 @@ export async function runAgent(teamId: origin?.teamId ?? "",slackUserId: origin?.slackUserId ?? "",},+ tb,};const tools = buildSlackTools(ctx);let messages = convertThreadToMessages(thread, botUserId);diff --git a/apps/web/.env.example b/apps/web/.env.exampleindex 5e77a5dc7..39c4b5afc 100644--- a/apps/web/.env.example+++ b/apps/web/.env.example@@ -13,6 +13,10 @@ UPSTASH_REDIS_REST_TOKEN=test# TINY BIRD for time series data (trackers)TINY_BIRD_API_KEY=tiny-bird-api-key+# Optional — defaults to the cloud API+TINYBIRD_URL=+# Optional — "true" resolves every pipe and ingest to empty+TINYBIRD_NOOP=# TURSO SQLITEDATABASE_URL=http://127.0.0.1:8080diff --git a/apps/web/package.json b/apps/web/package.jsonindex ebf0045d2..da4aa3ead 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -9,7 +9,7 @@"build": "pnpm build:registry && next build","start": "next start","lint": "next lint",- "test": "deno test --parallel -A --no-check --sloppy-imports",+ "test": "NODE_ENV=test deno test --parallel -A --no-check --sloppy-imports","tsc": "tsc --noEmit"},"dependencies": {diff --git a/apps/web/src/app/api/og/monitor/route.tsx b/apps/web/src/app/api/og/monitor/route.tsxindex 788ab2008..8cc8f425a 100644--- a/apps/web/src/app/api/og/monitor/route.tsx+++ b/apps/web/src/app/api/og/monitor/route.tsx@@ -7,7 +7,11 @@ import { BasicLayout } from "../_components/basic-layout";import { Tracker } from "../_components/tracker";import { SIZE, calSemiBold, interLight, interRegular } from "../utils";-const tb = new OSTinybird(env.TINY_BIRD_API_KEY);+const tb = new OSTinybird({+ token: env.TINY_BIRD_API_KEY,+ baseUrl: env.TINYBIRD_URL,+ noop: env.TINYBIRD_NOOP,+});export const runtime = "edge";diff --git a/apps/web/src/content/status-markdown.ts b/apps/web/src/content/status-markdown.tsindex fa79587e3..ba4fc2b98 100644--- a/apps/web/src/content/status-markdown.ts+++ b/apps/web/src/content/status-markdown.ts@@ -8,13 +8,13 @@ import {getServiceReportDaily,getServiceReportWindows,} from "@openstatus/services/external-service-report";-import { OSTinybird, safePipeData } from "@openstatus/tinybird";+import { safePipeData } from "@openstatus/tinybird";-import { env } from "../env";import {cachedGetExternalServiceBySlug,cachedListExternalServices,} from "../lib/external-service-cache";+import { tb } from "../lib/tb";type LatestRow = {id: string;@@ -138,7 +138,6 @@ async function generateReportsMarkdown(args: {export async function generateStatusIndexMarkdown(): Promise<string> {const services = await cachedListExternalServices();- const tb = new OSTinybird(env.TINY_BIRD_API_KEY);const latestRes = await safePipeData(tb.externalStatusLatest({}),"externalStatusLatest (markdown index)",@@ -179,7 +178,6 @@ export async function generateStatusDetailMarkdown(const aliasSlugs = Array.isArray(service.aliases) ? service.aliases : [];const slugChain = [service.slug, ...aliasSlugs];- const tb = new OSTinybird(env.TINY_BIRD_API_KEY);const [latestRes, historyRes] = await Promise.all([safePipeData(tb.externalStatusLatest({ ids: slugChain }),diff --git a/apps/web/src/env.ts b/apps/web/src/env.tsindex 55569d22e..9d6c11fc2 100644--- a/apps/web/src/env.ts+++ b/apps/web/src/env.ts@@ -6,6 +6,8 @@ import "@openstatus/db/env.mjs";export const env = createEnv({server: {TINY_BIRD_API_KEY: z.string().min(1),+ TINYBIRD_URL: z.string().default("https://api.tinybird.co"),+ TINYBIRD_NOOP: z.stringbool().catch(false),RESEND_API_KEY: z.string().min(1),QSTASH_CURRENT_SIGNING_KEY: z.string().min(1),QSTASH_NEXT_SIGNING_KEY: z.string().min(1),@@ -34,6 +36,8 @@ export const env = createEnv({NEXT_PUBLIC_OPENPANEL_CLIENT_ID:process.env.NEXT_PUBLIC_OPENPANEL_CLIENT_ID,TINY_BIRD_API_KEY: process.env.TINY_BIRD_API_KEY,+ TINYBIRD_URL: process.env.TINYBIRD_URL,+ TINYBIRD_NOOP: process.env.TINYBIRD_NOOP,RESEND_API_KEY: process.env.RESEND_API_KEY,QSTASH_CURRENT_SIGNING_KEY: process.env.QSTASH_CURRENT_SIGNING_KEY,QSTASH_NEXT_SIGNING_KEY: process.env.QSTASH_NEXT_SIGNING_KEY,diff --git a/apps/web/src/lib/external-report-escalation.ts b/apps/web/src/lib/external-report-escalation.tsindex c91450026..9b632794c 100644--- a/apps/web/src/lib/external-report-escalation.ts+++ b/apps/web/src/lib/external-report-escalation.ts@@ -7,12 +7,10 @@ import {getComponentReportWindows,getServiceReportWindows,} from "@openstatus/services/external-service-report";-import { OSTinybird, safePipeData } from "@openstatus/tinybird";+import { safePipeData } from "@openstatus/tinybird";import { unstable_cache } from "next/cache";-import { env } from "../env";--const tb = new OSTinybird(env.TINY_BIRD_API_KEY);+import { tb } from "./tb";const REPORTS_REVALIDATE_SECONDS = 30;// Distinct from the "external-services" tag on service-lookup caches so thatdiff --git a/apps/web/src/lib/tb.ts b/apps/web/src/lib/tb.tsindex fc16ba37c..1634abf6c 100644--- a/apps/web/src/lib/tb.ts+++ b/apps/web/src/lib/tb.ts@@ -2,7 +2,11 @@ import { OSTinybird } from "@openstatus/tinybird";import { env } from "../env";-const tb = new OSTinybird(env.TINY_BIRD_API_KEY);+export const tb = new OSTinybird({+ token: env.TINY_BIRD_API_KEY,+ baseUrl: env.TINYBIRD_URL,+ noop: env.TINYBIRD_NOOP,+});// REMINDER: we could extend the limits (WorkspacePlan) by// knowing which plan the user is on and disable some periodsdiff --git a/apps/workflows/src/cron/external-status.ts b/apps/workflows/src/cron/external-status.tsindex ab0c64915..9ab070d71 100644--- a/apps/workflows/src/cron/external-status.ts+++ b/apps/workflows/src/cron/external-status.ts@@ -44,7 +44,11 @@ import {const logger = getLogger(["workflow", "external-status"]);-const tb = new OSTinybird(env().TINY_BIRD_API_KEY);+const tb = new OSTinybird({+ token: env().TINY_BIRD_API_KEY,+ baseUrl: env().TINYBIRD_URL,+ noop: env().TINYBIRD_NOOP,+});// 10 per phase × 3 phases = peak 30 concurrent HTTP requests upstream; keeps// Atlassian/Incident.io CDNs comfortable while still parallelising heavily.diff --git a/apps/workflows/src/cron/uptime-freeze.ts b/apps/workflows/src/cron/uptime-freeze.tsindex 2ee0e231b..7a93f8bde 100644--- a/apps/workflows/src/cron/uptime-freeze.ts+++ b/apps/workflows/src/cron/uptime-freeze.ts@@ -11,7 +11,11 @@ import { reportBackgroundError, runSentryCron } from "../lib/sentry";const logger = getLogger(["workflow", "uptime-freeze"]);-const tb = new OSTinybird(env().TINY_BIRD_API_KEY);+const tb = new OSTinybird({+ token: env().TINY_BIRD_API_KEY,+ baseUrl: env().TINYBIRD_URL,+ noop: env().TINYBIRD_NOOP,+});const pipes: UptimeFreezePipes = {http: tb.httpStatus45d,diff --git a/apps/workflows/src/env.ts b/apps/workflows/src/env.tsindex f95178e99..42e57785c 100644--- a/apps/workflows/src/env.ts+++ b/apps/workflows/src/env.ts@@ -16,6 +16,7 @@ export const env = () =>RESEND_API_KEY: z.string().prefault(""),TINY_BIRD_API_KEY: z.string().prefault(""),TINYBIRD_URL: z.string().prefault("https://api.tinybird.co"),+ TINYBIRD_NOOP: z.stringbool().catch(false),QSTASH_TOKEN: z.string().prefault(""),SCREENSHOT_SERVICE_URL: z.string().prefault(""),TWILLIO_AUTH_TOKEN: z.string().prefault(""),diff --git a/packages/api/src/env.ts b/packages/api/src/env.tsindex 77d6c73f4..66d923c58 100644--- a/packages/api/src/env.ts+++ b/packages/api/src/env.ts@@ -8,6 +8,8 @@ export const env = createEnv({TEAM_ID_VERCEL: z.string(),VERCEL_AUTH_BEARER_TOKEN: z.string(),TINY_BIRD_API_KEY: z.string(),+ TINYBIRD_URL: z.string().default("https://api.tinybird.co"),+ TINYBIRD_NOOP: z.stringbool().catch(false),RESEND_API_KEY: z.string(),CRON_SECRET: z.string(),UNKEY_TOKEN: z.string(),@@ -23,6 +25,8 @@ export const env = createEnv({TEAM_ID_VERCEL: process.env.TEAM_ID_VERCEL,VERCEL_AUTH_BEARER_TOKEN: process.env.VERCEL_AUTH_BEARER_TOKEN,TINY_BIRD_API_KEY: process.env.TINY_BIRD_API_KEY,+ TINYBIRD_URL: process.env.TINYBIRD_URL,+ TINYBIRD_NOOP: process.env.TINYBIRD_NOOP,RESEND_API_KEY: process.env.RESEND_API_KEY,CRON_SECRET: process.env.CRON_SECRET,UNKEY_TOKEN: process.env.UNKEY_TOKEN,diff --git a/packages/api/src/router/externalService.ts b/packages/api/src/router/externalService.tsindex 70c39e995..b4e102091 100644--- a/packages/api/src/router/externalService.ts+++ b/packages/api/src/router/externalService.ts@@ -19,13 +19,13 @@ import {getServiceReportWindows,recordExternalServiceReport,} from "@openstatus/services/external-service-report";-import { OSTinybird } from "@openstatus/tinybird";import { redis } from "@openstatus/upstash";import { TRPCError } from "@trpc/server";import { z } from "zod";import { env } from "../env";import { toTRPCError } from "../service-adapter";+import { tb } from "../tb";import { createTRPCRouter, publicProcedure } from "../trpc";import {REPORT_THRESHOLD,@@ -33,8 +33,6 @@ import {computeEffectiveStatus,} from "./effective-status";-const tb = new OSTinybird(env.TINY_BIRD_API_KEY);-const DEFAULT_HISTORY_DAYS = 45;const INCIDENTS_LIMIT = 5;const REPORT_COUNTRIES_LIMIT = 5;diff --git a/packages/api/src/router/tinybird/index.ts b/packages/api/src/router/tinybird/index.tsindex 8f5cba86b..39788c305 100644--- a/packages/api/src/router/tinybird/index.ts+++ b/packages/api/src/router/tinybird/index.ts@@ -1,16 +1,13 @@import { type SQL, and, db, eq, inArray } from "@openstatus/db";import { monitor } from "@openstatus/db/src/schema";import { monitorRegions } from "@openstatus/db/src/schema/constants";-import { OSTinybird } from "@openstatus/tinybird";import { TRPCError } from "@trpc/server";import { z } from "zod";-import { env } from "../../env";+import { tb } from "../../tb";import { createTRPCRouter, protectedProcedure } from "../../trpc";import { calculatePeriod } from "./utils";-const tb = new OSTinybird(env.TINY_BIRD_API_KEY);-const periods = ["1d", "7d", "14d", "30d", "90d"] as const;const types = ["http", "tcp", "dns"] as const;type Period = (typeof periods)[number];diff --git a/packages/api/src/service-adapter.ts b/packages/api/src/service-adapter.tsindex 8f1e21b12..c07bbf488 100644--- a/packages/api/src/service-adapter.ts+++ b/packages/api/src/service-adapter.ts@@ -2,6 +2,7 @@ import { type ServiceContext, ServiceError } from "@openstatus/services";import { TRPCError } from "@trpc/server";import { ZodError } from "zod";+import { tb } from "./tb";import type { Context } from "./trpc";type AuthedContext = Context & {@@ -19,6 +20,7 @@ export function toServiceCtx(ctx: AuthedContext): ServiceContext {workspace: ctx.workspace,actor: { type: "user", userId: ctx.user.id },requestId: ctx.req?.headers.get("x-request-id") ?? undefined,+ tb,};}diff --git a/packages/api/src/tb.ts b/packages/api/src/tb.tsnew file mode 100644index 000000000..1d638191d--- /dev/null+++ b/packages/api/src/tb.ts@@ -0,0 +1,9 @@+import { OSTinybird } from "@openstatus/tinybird";++import { env } from "./env";++export const tb = new OSTinybird({+ token: env.TINY_BIRD_API_KEY,+ baseUrl: env.TINYBIRD_URL,+ noop: env.TINYBIRD_NOOP,+});diff --git a/packages/services/src/context.ts b/packages/services/src/context.tsindex 51565e4c8..4ae3227e3 100644--- a/packages/services/src/context.ts+++ b/packages/services/src/context.ts@@ -30,7 +30,14 @@ export type ServiceContext = {tb?: OSTinybird;};-export const defaultTb = new OSTinybird(process.env.TINY_BIRD_API_KEY ?? "");+// Fallback for callers with no app env to read from (scripts, tests). Request+// paths must inject their app's configured client via `ctx.tb` — this one has+// no validated env behind it.+export const defaultTb = new OSTinybird({+ token: process.env.TINY_BIRD_API_KEY ?? "",+ baseUrl: process.env.TINYBIRD_URL,+ noop: process.env.TINYBIRD_NOOP,+});// drizzle's `is()` helper is identity-safe across module copies (uses a// symbol-based entityKind), which `instanceof` is not under pnpm when multiplediff --git a/packages/tinybird/package.json b/packages/tinybird/package.jsonindex 2084c0f54..d42bcd9f6 100644--- a/packages/tinybird/package.json+++ b/packages/tinybird/package.json@@ -5,7 +5,7 @@"main": "src/index.ts","scripts": {"check": "deno check --sloppy-imports .",- "test": "deno test --parallel -A --no-check --sloppy-imports"+ "test": "NODE_ENV=test deno test --parallel -A --no-check --sloppy-imports"},"dependencies": {"@chronark/zod-bird": "catalog:",diff --git a/packages/tinybird/src/client.test.ts b/packages/tinybird/src/client.test.tsnew file mode 100644index 000000000..26b4d2e7d--- /dev/null+++ b/packages/tinybird/src/client.test.ts@@ -0,0 +1,40 @@+import { expect } from "@std/expect";+import { describe, test } from "@std/testing/bdd";++import { noopFlagSchema, OSTinybird } from "./client";++describe("noopFlagSchema", () => {+ test("treats the string 'false' as disabled, not as a truthy string", () => {+ expect(noopFlagSchema.parse("false")).toBe(false);+ expect(noopFlagSchema.parse("0")).toBe(false);+ expect(noopFlagSchema.parse("")).toBe(false);+ });++ test("enables on the documented truthy spellings", () => {+ expect(noopFlagSchema.parse("true")).toBe(true);+ expect(noopFlagSchema.parse("1")).toBe(true);+ });++ test("passes booleans through for schemas that already coerced", () => {+ expect(noopFlagSchema.parse(true)).toBe(true);+ expect(noopFlagSchema.parse(false)).toBe(false);+ });++ test("defaults to disabled when unset or unrecognised", () => {+ expect(noopFlagSchema.parse(undefined)).toBe(false);+ expect(noopFlagSchema.parse("nope")).toBe(false);+ });+});++describe("OSTinybird", () => {+ test("no-ops under NODE_ENV=test even when the call site asks for a real client", async () => {+ const tb = new OSTinybird({+ token: "a-token",+ // Unroutable on purpose: a real client would reject instead of resolving.+ baseUrl: "http://127.0.0.1:1",+ noop: false,+ });++ expect(await tb.homeStats({})).toEqual({ meta: [], data: [] });+ });+});diff --git a/packages/tinybird/src/client.ts b/packages/tinybird/src/client.tsindex 595c236ab..fa5bc9966 100644--- a/packages/tinybird/src/client.ts+++ b/packages/tinybird/src/client.ts@@ -22,24 +22,45 @@ const externalStatusHistoryDailyShape = {snapshot_count: z.int(),};+export const TINYBIRD_DEFAULT_URL = "https://api.tinybird.co";++/**+ * A `TINYBIRD_NOOP` env value. Apps hand this over in two shapes: a real+ * boolean where the env schema validated it, a raw string where the schema ran+ * with `skipValidation` — and the string `"false"` is truthy, so it can never+ * be tested directly. Anything unset or unrecognised means disabled.+ */+export const noopFlagSchema = z.stringbool().or(z.boolean()).catch(false);++export type OSTinybirdConfig = {+ token: string;+ /** Instance to query. Callers pass their app's validated env value. */+ baseUrl?: string;+ /** Resolve every pipe and ingest to empty — tests and offline dev. */+ noop?: boolean | string;+};+export class OSTinybird {private readonly tb: Client;- constructor(token: string) {- const tinybirdUrl = process.env.TINYBIRD_URL;- // Empty token → noop unconditionally; pipes resolve empty rather than- // failing authn. Dev/test without a TINYBIRD_URL also gets a noop.- if (- !token ||- ((process.env.NODE_ENV === "development" ||- process.env.NODE_ENV === "test") &&- !tinybirdUrl)- ) {+ constructor(config: OSTinybirdConfig) {+ // Tests must never reach a real instance whatever token sits in the env —+ // checked here so no call site can forget it.+ const noop =+ process.env.NODE_ENV === "test" || noopFlagSchema.parse(config.noop);+ // An empty token cannot authenticate, so noop keeps pipes resolving empty+ // instead of throwing at every call site.+ if (noop || !config.token) {+ if (!noop) {+ console.warn(+ "[tinybird] no token configured — every pipe will return empty data",+ );+ }this.tb = new NoopTinybird();} else {this.tb = new Client({- token,- baseUrl: tinybirdUrl || "https://api.tinybird.co",+ token: config.token,+ baseUrl: config.baseUrl || TINYBIRD_DEFAULT_URL,});}}