From 55ad15d9497a49a07ff5b32ad0327886d0fcfcca Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Wed, 2 Dec 2026 15:35:14 +0100 Subject: [PATCH 1/2] Rename the console project to pubpub --- kf.project.jsonc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kf.project.jsonc b/kf.project.jsonc index a37f5fb71..8573085f2 100644 --- a/kf.project.jsonc +++ b/kf.project.jsonc @@ -1,7 +1,7 @@ { "$schema": "https://console.knowledgefutures.org/schemas/kf.project.v2.json", "version": 2, - "slug": "kf-pubpub", + "slug": "pubpub", "name": "PubPub", "account": "kf", From 9da1c223c4cd4344530bb54970e1b99c7760ea3a Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Wed, 2 Dec 2026 15:37:11 +0100 Subject: [PATCH 2/2] Send server errors to Whistle --- infra/ENV.md | 1 + kf.project.jsonc | 8 ++++++-- pubstash/server.ts | 4 +++- server/envSchema.ts | 6 ++++++ server/server.ts | 4 +++- utils/__tests__/sentryDsn.test.ts | 16 ++++++++++++++++ utils/sentryDsn.ts | 19 +++++++++++++++++++ workers/queue.ts | 3 ++- 8 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 utils/__tests__/sentryDsn.test.ts create mode 100644 utils/sentryDsn.ts diff --git a/infra/ENV.md b/infra/ENV.md index 987492ed9..fc24ea64b 100644 --- a/infra/ENV.md +++ b/infra/ENV.md @@ -60,6 +60,7 @@ All environment variables used by PubPub, with types, defaults, and descriptions | `SLACK_WEBHOOK_URL` | string | No | — | Slack incoming webhook URL for notifications | | `SENTRY_AUTH_TOKEN` | string | No | — | Sentry auth token (build-time only) | | `SENTRY_ORG` | string | No | — | Sentry organization slug | +| `KF_WHISTLE_URL` | string | No | — | Whistle, from the KF console (kf/whistle@1): server errors go there instead of Sentry | | `BLOCKLIST_IP_ADDRESSES` | string | No | — | Comma-separated list of IP addresses to block | | `LARGE_COMMUNITY_SLUGS` | string | No | — | Comma-separated list of large community slugs for optimized queries | | `NEW_ACCOUNT_LINK_COMMENT_WINDOW_MINUTES` | number | No | — | Minutes after account creation during which link-comments are flagged | diff --git a/kf.project.jsonc b/kf.project.jsonc index 8573085f2..83d90df87 100644 --- a/kf.project.jsonc +++ b/kf.project.jsonc @@ -5,12 +5,16 @@ "name": "PubPub", "account": "kf", - // Deployed by .github/workflows/deploy.yml; secrets come from the console. + // Deployed by .github/workflows/deploy.yml; secrets come from the console, + // and with them KF_WHISTLE_URL, where server errors go (utils/sentryDsn.ts). + "defaults": { + "services": { "kf/whistle@1": {} } + }, "environments": { "production": { "ref": "tags/v*", "secrets": ["infra/.env.enc"], - "elsewhere": { "workflow": ".github/workflows/deploy.yml" } + "elsewhere": { "workflow": ".github/workflows/deploy.yml", "hosts": ["www.pubpub.org"] } }, // DuqDuq "dev": { diff --git a/pubstash/server.ts b/pubstash/server.ts index 843d4d771..735ae5199 100644 --- a/pubstash/server.ts +++ b/pubstash/server.ts @@ -2,6 +2,8 @@ import http from 'node:http'; import * as Sentry from '@sentry/node'; import { type Browser, chromium } from 'playwright-core'; +import { sentryDsn } from 'utils/sentryDsn'; + import { type OutlineNode, type PageBoxes, type PdfMeta, postProcessPdf } from './postprocess'; import { uploadPdfToS3 } from './s3'; @@ -10,7 +12,7 @@ import { uploadPdfToS3 } from './s3'; // --------------------------------------------------------------------------- if (process.env.NODE_ENV === 'production') { Sentry.init({ - dsn: 'https://abe1c84bbb3045bd982f9fea7407efaa@sentry.io/1505439', + dsn: sentryDsn(), environment: process.env.PUBPUB_PRODUCTION === 'true' ? 'prod' : 'dev', release: process.env.HEROKU_SLUG_COMMIT, tracesSampleRate: 0.1, diff --git a/server/envSchema.ts b/server/envSchema.ts index 73345f350..5efe10575 100644 --- a/server/envSchema.ts +++ b/server/envSchema.ts @@ -148,6 +148,12 @@ export const envSchema = z.object({ // ── Observability ─────────────────────────────────────────────────── SENTRY_AUTH_TOKEN: z.string().describe('Sentry auth token (build-time only)'), SENTRY_ORG: z.string().describe('Sentry organization slug'), + KF_WHISTLE_URL: z + .string() + .optional() + .describe( + 'Whistle, from the KF console (kf/whistle@1): server errors go there instead of Sentry', + ), // ── Analytics ─────────────────────────────────────────────────────── CLOUDFLARE_ANALYTICS_API_TOKEN: z diff --git a/server/server.ts b/server/server.ts index 3aca1d64c..114e55327 100755 --- a/server/server.ts +++ b/server/server.ts @@ -8,6 +8,8 @@ import noSlash from 'no-slash'; import passport from 'passport'; import path from 'path'; +import { sentryDsn } from 'utils/sentryDsn'; + import { env } from './env'; import { resolveAppCommit } from './utils/appCommit'; @@ -91,7 +93,7 @@ if (isProd() || isDuqDuq()) { if (env.NODE_ENV === 'production') { Sentry.init({ - dsn: 'https://abe1c84bbb3045bd982f9fea7407efaa@sentry.io/1505439', + dsn: sentryDsn(), environment: isProd() ? 'prod' : 'dev', release: getAppCommit(), tracesSampleRate: 0.05, diff --git a/utils/__tests__/sentryDsn.test.ts b/utils/__tests__/sentryDsn.test.ts new file mode 100644 index 000000000..adeb566a4 --- /dev/null +++ b/utils/__tests__/sentryDsn.test.ts @@ -0,0 +1,16 @@ +import { sentryDsn } from 'utils/sentryDsn'; + +describe('sentryDsn', () => { + it('sends to Whistle when the console gave this deploy KF_WHISTLE_URL', () => { + expect(sentryDsn('https://kf_abc:key_123@whistle.kfutures.org/')).toBe( + 'https://key_123@whistle.kfutures.org/1', + ); + }); + + it('stays on Sentry without one, or with one a DSN cannot carry', () => { + const sentry = 'https://abe1c84bbb3045bd982f9fea7407efaa@sentry.io/1505439'; + expect(sentryDsn('')).toBe(sentry); + expect(sentryDsn('not a url')).toBe(sentry); + expect(sentryDsn('https://kf_abc:a-b@whistle.kfutures.org/')).toBe(sentry); + }); +}); diff --git a/utils/sentryDsn.ts b/utils/sentryDsn.ts new file mode 100644 index 000000000..2405fa52c --- /dev/null +++ b/utils/sentryDsn.ts @@ -0,0 +1,19 @@ +/** Where server errors go before the console hands out KF_WHISTLE_URL. */ +const SENTRY_DSN = 'https://abe1c84bbb3045bd982f9fea7407efaa@sentry.io/1505439'; + +/** + * The DSN for Sentry.init: Whistle's Sentry intake when the console gave this + * deploy KF_WHISTLE_URL (`https://:@/`), else Sentry. + * Same as `sentryDsn` in @knowledgefutures/sdk/whistle. + */ +export function sentryDsn(whistleUrl = process.env.KF_WHISTLE_URL): string { + if (!whistleUrl) return SENTRY_DSN; + try { + const u = new URL(whistleUrl); + const key = decodeURIComponent(u.password); + if (!/^https?:$/.test(u.protocol) || !/^\w+$/.test(key)) return SENTRY_DSN; + return `${u.protocol}//${key}@${u.host}/1`; + } catch { + return SENTRY_DSN; + } +} diff --git a/workers/queue.ts b/workers/queue.ts index 1acc0ca85..3da5fdf55 100644 --- a/workers/queue.ts +++ b/workers/queue.ts @@ -11,6 +11,7 @@ import { failPushLogForWorkerTask } from 'server/underlayPushLog/queries'; import { expect } from 'utils/assert'; import { createCachePurgeDebouncer } from 'utils/caching/createCachePurgeDebouncer'; import { getAppCommit, isProd } from 'utils/environment'; +import { sentryDsn } from 'utils/sentryDsn'; import { TaskPriority, taskQueueName } from 'utils/workers'; const maxWorkerTimeSeconds = 120; @@ -27,7 +28,7 @@ const customTimeouts = { if (env.NODE_ENV === 'production') { Sentry.init({ - dsn: 'https://abe1c84bbb3045bd982f9fea7407efaa@sentry.io/1505439', + dsn: sentryDsn(), environment: isProd() ? 'prod' : 'dev', release: getAppCommit(), tracesSampleRate: 1,