Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions infra/ENV.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
8 changes: 6 additions & 2 deletions kf.project.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 3 additions & 1 deletion pubstash/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions server/envSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions utils/__tests__/sentryDsn.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
19 changes: 19 additions & 0 deletions utils/sentryDsn.ts
Original file line number Diff line number Diff line change
@@ -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://<instance>:<key>@<host>/`), 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;
}
}
3 changes: 2 additions & 1 deletion workers/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
Loading