Open source alternative to Semrush and Ahrefs
TypeScript backlink-analysisgoogle-search-console-mcpkeyword-researchmcpseoseo-agentseo-auditseo-automationseo-skillsseo-toolssite-audit
Exclude health probes from self-host telemetry (#635)
Ben Senescu3b9cbeaf5b73
diff --git a/docs/SELF_HOSTING_CLOUDFLARE_OPERATIONS.md b/docs/SELF_HOSTING_CLOUDFLARE_OPERATIONS.mdindex 8510b689..c7c0b89d 100644--- a/docs/SELF_HOSTING_CLOUDFLARE_OPERATIONS.md+++ b/docs/SELF_HOSTING_CLOUDFLARE_OPERATIONS.md@@ -30,4 +30,6 @@ https://YOUR_WORKER_HOSTNAME/mcpOpenSEO collects anonymized telemetry for core usage events: heartbeats with aggregate counts (installs, users, projects, feature usage) tied to a random install ID, sent every 5 minutes during the first two hours after install, then at most once daily. No URLs, keywords, prompts, emails, or IP-derived location are collected, and idle installs send nothing.+Heartbeats are triggered by requests to the app or MCP server. Requests to `/api/health` do not trigger telemetry, matching Docker's behavior.+To disable it, set `OPENSEO_TELEMETRY_DISABLED=1` in `.env.selfhost` and redeploy. Docker and [legacy deployments](./SELF_HOSTING_CLOUDFLARE_LEGACY.md): set it (or `DO_NOT_TRACK=1`) as an environment variable / Worker variable instead.diff --git a/docs/SELF_HOSTING_DOCKER.md b/docs/SELF_HOSTING_DOCKER.mdindex bcea3d5c..8d138dc2 100644--- a/docs/SELF_HOSTING_DOCKER.md+++ b/docs/SELF_HOSTING_DOCKER.md@@ -47,6 +47,8 @@ You can also persist it in `.env`.OpenSEO collects anonymized telemetry for core usage events: heartbeats with aggregate counts (installs, users, projects, feature usage) tied to a random install ID, sent every 5 minutes during the first two hours after install, then at most once daily. Telemetry also includes failed setup check names and statuses, never values or error messages. No URLs, keywords, prompts, emails, or IP-derived location are collected, and idle installs send nothing.+Heartbeats are triggered by requests to the app or MCP server. Requests to `/api/health`, including Docker's automatic health checks, do not trigger telemetry.+To disable it, set `OPENSEO_TELEMETRY_DISABLED=1` (or `DO_NOT_TRACK=1`) in `.env`, then run `docker compose up -d --force-recreate open-seo`.## Pin to a specific image tagdiff --git a/src/server.ts b/src/server.tsindex 68c93bf1..737e442e 100644--- a/src/server.ts+++ b/src/server.ts@@ -140,11 +140,10 @@ function handleFetch(env: Env,ctx: ExecutionContext,): Response | Promise<Response> {- ctx.waitUntil(maybeSendSelfHostHeartbeat());-const authMode = getAuthMode(env.AUTH_MODE);const publicRequest = requestWithPublicOrigin(request);const pathname = new URL(publicRequest.url).pathname;+ ctx.waitUntil(maybeSendSelfHostHeartbeat(pathname));if (pathname === GDPR_STORAGE_ERASURE_PATH) {return handleGdprStorageErasure(publicRequest, env);diff --git a/src/server/lib/self-host-telemetry.test.ts b/src/server/lib/self-host-telemetry.test.tsindex bedef238..54e27f2f 100644--- a/src/server/lib/self-host-telemetry.test.ts+++ b/src/server/lib/self-host-telemetry.test.ts@@ -1,12 +1,21 @@-import { beforeEach, describe, expect, it, vi } from "vitest";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import type { SelfHostTelemetryDependencies } from "./self-host-telemetry";import {getCheckIntervalMs,getHeartbeatIntervalMs,+ incrementSelfHostMcpToolCallCount,} from "./self-host-telemetry";+const dbMocks = vi.hoisted(() => {+ const onConflictDoUpdate = vi.fn().mockResolvedValue(undefined);+ const insert = vi.fn(() => ({+ values: vi.fn(() => ({ onConflictDoUpdate })),+ }));+ return { insert, onConflictDoUpdate };+});+vi.mock("cloudflare:workers", () => ({ env: {} }));-vi.mock("@/db", () => ({ db: {} }));+vi.mock("@/db", () => ({ db: { insert: dbMocks.insert } }));type StoredState = {installId: string;@@ -78,9 +87,12 @@ function createHarness(};}-async function runHeartbeat(harness: ReturnType<typeof createHarness>) {+async function runHeartbeat(+ harness: ReturnType<typeof createHarness>,+ pathname = "/",+) {const { maybeSendSelfHostHeartbeat } = await import("./self-host-telemetry");- await maybeSendSelfHostHeartbeat({+ await maybeSendSelfHostHeartbeat(pathname, {dependencies: harness.dependencies,skipMemoryThrottle: true,});@@ -127,6 +139,56 @@ describe("maybeSendSelfHostHeartbeat", () => {vi.stubEnv("DO_NOT_TRACK", "");});+ afterEach(() => {+ vi.unstubAllEnvs();+ });++ it.each(["local_noauth", "cloudflare_access"])(+ "ignores health probes without consuming the heartbeat in %s mode",+ async (authMode) => {+ vi.stubEnv("AUTH_MODE", authMode);+ const harness = createHarness();++ await runHeartbeat(harness, "/api/health");+ await runHeartbeat(harness, "/api/health/");++ expect(harness.claimHeartbeat).not.toHaveBeenCalled();+ expect(harness.sendHeartbeat).not.toHaveBeenCalled();++ await runHeartbeat(harness, "/mcp");++ expect(harness.sendHeartbeat).toHaveBeenCalledTimes(1);+ expect(harness.sendHeartbeat.mock.calls[0]?.[1]).toMatchObject({+ deployTarget: authMode === "local_noauth" ? "docker" : "cloudflare",+ });+ },+ );++ it.each([+ { mode: "production", prod: true, sends: true },+ { mode: "selfhost", prod: true, sends: true },+ { mode: "preview", prod: true, sends: false },+ { mode: "development", prod: false, sends: false },+ { mode: "test", prod: false, sends: false },+ { mode: "selfhost", prod: false, sends: false },+ { mode: "production", prod: false, sends: false },+ ])(+ "gates heartbeats and MCP counters for mode=$mode, PROD=$prod",+ async ({ mode, prod, sends }) => {+ vi.stubEnv("MODE", mode);+ vi.stubEnv("PROD", prod);+ const harness = createHarness();+ delete harness.dependencies.isNonProductionBuild;++ await runHeartbeat(harness);+ await incrementSelfHostMcpToolCallCount();++ expect(harness.claimHeartbeat).toHaveBeenCalledTimes(sends ? 1 : 0);+ expect(harness.sendHeartbeat).toHaveBeenCalledTimes(sends ? 1 : 0);+ expect(dbMocks.onConflictDoUpdate).toHaveBeenCalledTimes(sends ? 1 : 0);+ },+ );+it("does not send in hosted mode", async () => {vi.stubEnv("AUTH_MODE", "hosted");const harness = createHarness();diff --git a/src/server/lib/self-host-telemetry.ts b/src/server/lib/self-host-telemetry.tsindex 95f02bdc..e01a4b2e 100644--- a/src/server/lib/self-host-telemetry.ts+++ b/src/server/lib/self-host-telemetry.ts@@ -112,11 +112,15 @@ let lastCheckedAt: number | null = null;// check interval without a DB read. Epoch 0 marks "old install, age unknown".let cachedInstalledAt: Date | null = null;-// Only production builds report: this excludes `vite dev`, vitest, and-// preview deployments (`vite build --mode preview`), whose per-PR databases-// would otherwise each register as a fresh self-host install.+// Docker uses the default production mode; deploy:selfhost builds with the+// selfhost mode to load .env.selfhost. Both report, but dev/test and preview+// deployments must not register as installs.function isNonProductionBuild() {- return import.meta.env.MODE !== "production";+ return (+ !import.meta.env.PROD ||+ (import.meta.env.MODE !== "production" &&+ import.meta.env.MODE !== "selfhost")+ );}async function telemetryIsDisabled() {@@ -276,8 +280,13 @@ const productionDependencies: SelfHostTelemetryDependencies = {};export async function maybeSendSelfHostHeartbeat(+ pathname: string,options: SelfHostTelemetryOptions = {},) {+ // Docker probes this endpoint every 30 seconds. Probes must not create an+ // install, consume its heartbeat interval, or keep an idle install active.+ if (pathname === "/api/health" || pathname === "/api/health/") return;+try {if (await telemetryIsDisabled()) return;diff --git a/web/content/docs/self-hosting/docker.md b/web/content/docs/self-hosting/docker.mdindex 052b0bb2..1796c8c7 100644--- a/web/content/docs/self-hosting/docker.md+++ b/web/content/docs/self-hosting/docker.md@@ -53,6 +53,8 @@ You can also persist it in `.env`.OpenSEO collects anonymized telemetry for core usage events: heartbeats with aggregate counts (installs, users, projects, feature usage) tied to a random install ID, sent every 5 minutes during the first two hours after install, then at most once daily. Telemetry also includes failed setup check names and statuses, never values or error messages. No URLs, keywords, prompts, emails, or IP-derived location are collected, and idle installs send nothing.+Heartbeats are triggered by requests to the app or MCP server. Requests to `/api/health`, including Docker's automatic health checks, do not trigger telemetry.+To disable it, set `OPENSEO_TELEMETRY_DISABLED=1` (or `DO_NOT_TRACK=1`) in `.env`, then run `docker compose up -d --force-recreate open-seo`.## Pin to a specific image tag