Skip to content

Open source alternative to Semrush and Ahrefs

Stop each deploy from opening new PostHog error issues (#1078)

Ben Senescu869b502c4a1b
diff --git a/.agents/skills/observability-triage/SKILL.md b/.agents/skills/observability-triage/SKILL.md
index e59ca6bc..8311179b 100644
--- a/.agents/skills/observability-triage/SKILL.md
+++ b/.agents/skills/observability-triage/SKILL.md
@@ -78,7 +78,7 @@ Cloudflare captures an on-demand CPU or allocation profile from a live productio
- Read it without Go: `node .agents/skills/observability-triage/scripts/pprof-top.mjs open-seo-cpu.pprof` prints the hottest self and inclusive frames. Google's `pprof` opens the file too.
- **It only samples an isolate that is already serving traffic**; nothing is started for you. The app worker always qualifies. The audit worker returns 0 samples unless an audit is running, so start one first. Idle preview and self-host workers fail with "The Worker has no loaded isolate in its recent execution locations" or "No recent executions were found".
- One capture is one isolate in one colo, chosen among the ones that ran recently, so repeat a capture before trusting a small frame. A 10 s CPU capture under normal load yields ~2,000 samples at 1 ms intervals.
-- Function names are readable without source maps (the Vite build keeps them); file names are chunk hashes like `index-OuwxKDQa.js`. The deploy uploads no source maps (the build only emits them with `POSTHOG_SOURCEMAPS=true`), so chunk names stay hashes until that changes.
+- Function names are readable without source maps (the Vite build keeps them); file names are chunk hashes like `index-OuwxKDQa.js`. The production deploy uploads its source maps to PostHog error tracking and deletes them before deploying, so Cloudflare never has them and chunk names here stay hashes.
- A heap profile shows allocations made during the window (one stack per ~512 kB allocated), not retained memory: it finds churn, not leaks.
- Pair it with invocation data to see which route pays for the frames: group `cf-worker-event` by `$metadata.trigger` with `sum`, `median`, and `p90` of `$workers.cpuTimeMs`. A 10 s capture of one isolate weights whatever that isolate happened to serve, so convert a hot frame's share into milliseconds against the route's mean before acting on it: a frame at a third of a profile dominated by 2 ms auth failures is worth well under 1 ms per request.
diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml
index 670c4469..faa8d118 100644
--- a/.github/workflows/deploy-production.yml
+++ b/.github/workflows/deploy-production.yml
@@ -124,6 +124,26 @@ jobs:
- name: Build
run: pnpm build
+ env:
+ POSTHOG_SOURCEMAPS: "true"
+ NODE_OPTIONS: --max-old-space-size=8192
+
+ # Error tracking groups exceptions by their original source location,
+ # which it can only resolve for chunks tagged here, in the build that
+ # ships. A PostHog outage must not block a deploy.
+ - name: Upload sourcemaps to PostHog
+ continue-on-error: true
+ run: |
+ pnpm dlx @posthog/[email protected] sourcemap inject --directory ./dist
+ pnpm dlx @posthog/[email protected] sourcemap upload --directory ./dist --delete-after
+ env:
+ POSTHOG_CLI_HOST: ${{ vars.POSTHOG_CLI_HOST }}
+ POSTHOG_CLI_ENV_ID: ${{ vars.POSTHOG_CLI_ENV_ID }}
+ POSTHOG_CLI_TOKEN: ${{ secrets.POSTHOG_CLI_TOKEN }}
+
+ # --delete-after already removed them unless the upload failed.
+ - name: Keep sourcemaps out of the deploy
+ run: find dist -name '*.map' -delete
- name: Migrate production Postgres
run: pnpm db:migrate:pg
diff --git a/.github/workflows/sourcemaps.yml b/.github/workflows/sourcemaps.yml
deleted file mode 100644
index b79dd578..00000000
--- a/.github/workflows/sourcemaps.yml
+++ /dev/null
@@ -1,31 +0,0 @@
-name: Upload sourcemaps
-on:
- push:
- branches:
- - main
-concurrency:
- group: sourcemaps-${{ github.ref }}
- cancel-in-progress: true
-jobs:
- upload:
- if: github.repository != 'every-app/open-seo'
- runs-on: ubuntu-latest
- env:
- POSTHOG_SOURCEMAPS: "true"
- POSTHOG_CLI_HOST: ${{ vars.POSTHOG_CLI_HOST }}
- POSTHOG_CLI_ENV_ID: ${{ vars.POSTHOG_CLI_ENV_ID }}
- POSTHOG_CLI_TOKEN: ${{ secrets.POSTHOG_CLI_TOKEN }}
- steps:
- - name: Checkout
- uses: actions/checkout@v4
- - name: Setup pnpm
- uses: pnpm/action-setup@v4
- - name: Setup Node.js
- uses: actions/setup-node@v4
- with:
- node-version: 22
- cache: pnpm
- - name: Install dependencies
- run: pnpm install --frozen-lockfile
- - name: Build and upload sourcemaps
- run: pnpm run sourcemaps:upload
diff --git a/.gitignore b/.gitignore
index b2633720..0aa15504 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,7 +4,6 @@ package-lock.json
yarn.lock
.dev.vars
dist/
-dist-sourcemaps/
.wrangler
/tmp
diff --git a/deploy/docker/docker-entrypoint.sh b/deploy/docker/docker-entrypoint.sh
index be205492..28fa65d6 100644
--- a/deploy/docker/docker-entrypoint.sh
+++ b/deploy/docker/docker-entrypoint.sh
@@ -15,10 +15,7 @@ pnpm exec tsx scripts/selfhost-preflight.ts
pnpm run db:migrate:local
-# POSTHOG_SOURCEMAPS (CI sourcemap uploads) moves vite's outDir; keep the
-# fingerprint marker beside the output it describes.
-if [ "${POSTHOG_SOURCEMAPS:-}" = "true" ]; then OUT_DIR=dist-sourcemaps; else OUT_DIR=dist; fi
-FP_FILE="$OUT_DIR/.openseo-build-env"
+FP_FILE="dist/.openseo-build-env"
# Everything that changes build output: the envPrefix prefixes from
# vite.config.ts (keep in sync) plus POSTHOG_SOURCEMAPS.
diff --git a/package.json b/package.json
index 857b5f03..01e9d8d2 100644
--- a/package.json
+++ b/package.json
@@ -25,7 +25,6 @@
"preview:access": "pnpm alchemy deploy deploy/alchemy/alchemy.preview-access.run.ts --env-file .env.preview --stage preview-access --adopt",
"alchemy": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-strip-types\" alchemy",
"destroy:preview": "pnpm alchemy destroy deploy/alchemy/alchemy.run.ts --env-file .env.preview",
- "sourcemaps:upload": "POSTHOG_SOURCEMAPS=true NODE_OPTIONS=--max-old-space-size=8192 npm run build && pnpm dlx @posthog/cli sourcemap inject --directory ./dist-sourcemaps && pnpm dlx @posthog/cli sourcemap upload --directory ./dist-sourcemaps",
"cf-typegen": "wrangler types src/worker-configuration.d.ts --config wrangler.jsonc --config wrangler.audit.jsonc",
"types:check": "tsc --noEmit",
"format:check": "prettier --check .",
diff --git a/vite.config.ts b/vite.config.ts
index 9f64de64..076d26ae 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -59,6 +59,8 @@ export default defineConfig(({ mode, command }) => {
env.ALLOWED_HOST,
env.BETTER_AUTH_URL ? new URL(env.BETTER_AUTH_URL).hostname : undefined,
].filter((host): host is string => Boolean(host));
+ // The production deploy sets this, tags the chunks it is about to ship, and
+ // uploads the maps to PostHog error tracking (see deploy-production.yml).
const emitSourcemaps = env.POSTHOG_SOURCEMAPS === "true";
// `vite build --mode standalone` produces the Docker edition: one server
// module for celld (see deploy/standalone/) instead of the Workers pair.
@@ -92,7 +94,6 @@ export default defineConfig(({ mode, command }) => {
},
build: {
sourcemap: emitSourcemaps,
- outDir: emitSourcemaps ? "dist-sourcemaps" : "dist",
rolldownOptions: {
output: {
// Emit every chunk as pure ASCII: Rolldown rewrites each non-ASCII