Skip to content

feat(discovery-index): replace Sentry with PostHog for error tracking + sourcemap pipeline#8614

Merged
JSONbored merged 2 commits into
mainfrom
claude/posthog-discovery-index-error-tracking
Jul 25, 2026
Merged

feat(discovery-index): replace Sentry with PostHog for error tracking + sourcemap pipeline#8614
JSONbored merged 2 commits into
mainfrom
claude/posthog-discovery-index-error-tracking

Conversation

@JSONbored

@JSONbored JSONbored commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Summary

Per the epic's revised strategy (correction comment on #8286, 2026-07-25): PostHog replaces Sentry directly, not a parallel-run sink. This PR's history reflects that: the first commit added PostHog alongside the existing Sentry wiring; the second commit finishes the swap by removing Sentry entirely.

  • Deleted: src/sentry.ts, scripts/validate-sentry-release.mjs, @sentry/node, @sentry/cli, and the live metagraphed Sentry DSN that was baked into wrangler.jsonc's vars -- a genuine cross-project entanglement (discovery-index reporting into a different product's shared Sentry project), exactly the problem this migration set out to fix.
  • Added: src/posthog.ts (mirrors the deleted sentry.ts's shape 1:1) and scripts/validate-posthog-release.mjs (narrower than the deleted Sentry validator, since PostHog's release model has no commits/deploys/finalize lifecycle -- just symbol-set presence + no failure_reason via error_tracking/symbol_sets).
  • upload-sourcemaps.ts's PostHog inject/upload/validate flow is now the only path (no more Sentry-then-PostHog sequencing or exit-code combining).
  • @posthog/cli is pinned to an exact version (0.9.1, no caret) -- its postinstall script downloads a platform binary over HTTPS with no checksum verification.
  • Rebased onto current main to pick up fix(deps): resolve postcss + tar audit findings via overrides #8612's postcss/tar dependency-audit fix, which an earlier npm install --workspace in this branch had inadvertently regressed to pre-fix versions.

All PostHog config is wired end-to-end but not yet a real wrangler.jsonc var/secret -- #7875 (a real loopover-owned PostHog project) isn't finished, so every path stays a complete no-op until then.

Closes #8289

Test plan

  • npm run typecheck (repo root + discovery-index package + cf:typecheck) clean
  • npx vitest run test/unit/discovery-index/ -- 180/180 passing, 100% line/branch coverage on every touched file
  • npm run build --workspace @loopover/discovery-index and cf:typecheck clean
  • npm audit --audit-level=moderate -- only the pre-existing, already-tracked eslint/brace-expansion finding (Bump eslint to v10 to resolve brace-expansion/minimatch DoS chain (GHSA-mh99-v99m-4gvg) #8608-8610), nothing new

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 25, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
loopover-ui 2bfc6af Commit Preview URL

Branch Preview URL
Jul 25 2026, 08:45 AM

@superagent-security superagent-security Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superagent found 1 security concern(s).

Comment thread package-lock.json
@superagent-security superagent-security Bot added the pr:flagged PR flagged for review by security analysis. label Jul 25, 2026
@JSONbored JSONbored self-assigned this Jul 25, 2026
@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.57%. Comparing base (a972353) to head (6561117).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8614      +/-   ##
==========================================
+ Coverage   92.55%   92.57%   +0.01%     
==========================================
  Files         798      799       +1     
  Lines       79850    79976     +126     
  Branches    24120    24156      +36     
==========================================
+ Hits        73908    74034     +126     
  Misses       4803     4803              
  Partials     1139     1139              
Flag Coverage Δ
backend 93.75% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/discovery-index/src/app.ts 100.00% <100.00%> (ø)
packages/discovery-index/src/posthog.ts 100.00% <100.00%> (ø)
packages/discovery-index/src/upload-sourcemaps.ts 100.00% <100.00%> (ø)

@loopover-orb loopover-orb Bot added the gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. label Jul 25, 2026
@loopover-orb

loopover-orb Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-25 08:33:02 UTC

16 files · 1 AI reviewer · no blockers · readiness 100/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR adds a parallel PostHog error-tracking + sourcemap pipeline to discovery-index that mirrors the existing sentry.ts/upload-sourcemaps.ts shape closely, wiring in app.ts/server.ts/worker.ts/wrangler.jsonc/Dockerfile, with extensive matching test coverage. The implementation is internally consistent, correctly no-ops everywhere when config is unset (verified by tracing initDiscoveryIndexPostHog, runPostHogSourcemapUpload's missing-config check, and the captureScopedError active/client guards), and the PR body itself flags the pending #7875 dependency and gated #8298 decommission for the eventual Sentry removal. The description states linked issue #8289 with full coverage per the review brief. The Superagent Security Scan failure has no detail provided and this branch is 2 commits behind default, so per grounding rules I cannot attribute that failure to a specific defect in this diff.

Nits — 7 non-blocking
  • `packages/discovery-index/src/posthog.ts:27` and `scripts/validate-posthog-release.mjs:10` hardcode the PostHog US-cloud host as a literal rather than a shared constant, though this matches the existing sentry.ts pattern in this repo so it's consistent, not a regression.
  • `packages/discovery-index/src/upload-sourcemaps.ts:244-278` repeats several magic numbers (5, 20, 30_000, 500ms slicing) already present in the Sentry leg's `runReleaseValidation`/`numericEnv` — copied duplication rather than a shared helper, per the file's own stated 'literal copy, no compile-time dependency' design choice.
  • `@​posthog/cli@​0.9.1` runs a postinstall script — worth a quick manual check of what it does before merging, since install-time scripts are a supply-chain vector even for a well-known vendor CLI.
  • The flagged 'potential leaked secrets' at `posthog.test.ts:254` and `upload-sourcemaps.test.ts:83` are test fixture placeholder strings (`phc_test`, `phx_test_personal_key`), not real credentials — safe, but worth a quick confirm they're not accidentally real.
  • Consider factoring the retry-loop constants (max attempts 20, default delay 30_000ms) shared between Sentry's and PostHog's `numericEnv`/validation-retry logic into one small shared helper module now that there are two near-identical implementations, to avoid a third copy showing up in a future sink.
  • PR author also opened the linked issue — Link an issue that was opened by a different contributor, or provide a rationale for why this self-authored issue represents genuine discovery work.
  • Possible secret-shaped assignment in the diff (generic_secret_assignment) — Verify the value is not a real credential.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #8289
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 13 registered-repo PR(s), 13 merged, 250 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 13 PR(s), 250 issue(s).
Improvement ✅ Minor risk: clean · value: minor
Linked issue satisfaction

Addressed
The PR adds src/posthog.ts mirroring sentry.ts's redaction/fingerprint/tag-allowlist shape, wires it in parallel at all three capture sites, replaces the sourcemap pipeline with a posthog-cli leg plus a new validate-posthog-release.mjs validator, wires the loopover project key vars (pending #7875 provisioning, tracked transparently), keeps the Sentry path fully intact, and adds a substantial parit

Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, TypeScript, Ruby, Go, MDX, Shell, Solidity, JavaScript
  • Official Gittensor activity: 13 PR(s), 250 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Treat this as maintainer-lane context rather than normal contributor-lane activity.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot added the manual-review Gittensor contributor context label Jul 25, 2026
@superagent-security superagent-security Bot removed the pr:flagged PR flagged for review by security analysis. label Jul 25, 2026
…e as a parallel Sentry sink

Adds src/posthog.ts, mirroring src/sentry.ts's shape exactly (same
redaction rules, tag allowlist, capture entry points) using PostHog's
documented captureException(error, distinctId, properties) API, wired
into app.ts's onError handler, server.ts's unhandled-rejection/
uncaught-exception hooks and shutdown path, and worker.ts's Container
env forwarding.

Extends upload-sourcemaps.ts with a second, fully independent leg:
posthog-cli sourcemap inject/upload with an explicit --release-version
(the Docker build never copies .git, so the CLI's own git-metadata
auto-detection has nothing to inspect), running after the existing,
unmodified Sentry leg so an unverified interaction between the two
CLIs' inject steps can't put the proven flow at risk. Adds
scripts/validate-posthog-release.mjs, a narrower release-verification
counterpart to validate-sentry-release.mjs -- PostHog's release model
has no commits/deploys/finalize lifecycle to check, only symbol-set
presence via the error_tracking/symbol_sets API.

All PostHog config (POSTHOG_API_KEY/HOST/ENVIRONMENT/RELEASE for
capture, POSTHOG_CLI_API_KEY/PROJECT_ID/HOST for sourcemap upload) is
wired end-to-end but not yet a real wrangler.jsonc var/secret -- #7875
(a real loopover-owned PostHog project) isn't provisioned yet, so every
path stays a complete no-op until then, same as an unset SENTRY_DSN.

Runs fully parallel with the existing Sentry sink per the epic's gated
decommission plan (#8298); nothing about the Sentry leg changes here.

Closes #8289
…racking sink

Per the epic's revised strategy (#8286 correction, 2026-07-25): PostHog
replaces Sentry directly, not a parallel-run sink. This branch's earlier
commit added PostHog alongside the existing Sentry wiring; this commit
finishes the swap by removing Sentry entirely.

Deletes src/sentry.ts, scripts/validate-sentry-release.mjs, the
@sentry/node/@sentry/cli dependencies, and the live metagraphed Sentry
DSN previously baked into wrangler.jsonc's vars (a genuine cross-project
entanglement -- discovery-index reporting into a different product's
shared Sentry project, exactly the problem #8289 set out to fix).
Removes the corresponding SENTRY_* fields from env.d.ts/WorkerEnv/
Cloudflare.Env, regenerates worker-configuration.d.ts, and drops the
Sentry leg from upload-sourcemaps.ts (PostHog's inject/upload/validate
flow is now the only path, no more Math.max(sentryExitCode,
postHogExitCode) combining).

@posthog/cli is pinned to an exact version (0.9.1, no caret) rather
than a range -- its postinstall script downloads a platform binary over
HTTPS with no checksum verification.

Also rebases onto current main to pick up #8612's postcss/tar dependency
overrides, which an earlier `npm install --workspace` in this branch had
inadvertently regressed to their pre-fix versions.

Closes #8289
@JSONbored
JSONbored force-pushed the claude/posthog-discovery-index-error-tracking branch from 6561117 to 2bfc6af Compare July 25, 2026 08:43
@JSONbored JSONbored changed the title feat(discovery-index): add PostHog error tracking + sourcemap pipeline as a parallel Sentry sink feat(discovery-index): replace Sentry with PostHog for error tracking + sourcemap pipeline Jul 25, 2026
@superagent-security superagent-security Bot added the pr:flagged PR flagged for review by security analysis. label Jul 25, 2026
@JSONbored
JSONbored merged commit 2004a8f into main Jul 25, 2026
4 of 6 checks passed
@JSONbored
JSONbored deleted the claude/posthog-discovery-index-error-tracking branch July 25, 2026 08:50
@loopover-orb loopover-orb Bot added gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. and removed gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. labels Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. manual-review Gittensor contributor context pr:flagged PR flagged for review by security analysis.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostHog error tracking + release/sourcemap pipeline for discovery-index (off the shared metagraphed Sentry project)

1 participant