Filter third-party exceptions from PostHog error tracking - #276
Filter third-party exceptions from PostHog error tracking#276posthog[bot] wants to merge 1 commit into
Conversation
Add a `before_send` hook to `posthog.init()` that drops `$exception` events with no first-party stack frames, plus a denylist for known injected globals (scanPdf, beTracker, runtime.sendMessage, zaraz). Browser extensions and third-party scripts throw inside our pages; without a filter PostHog ingested them as first-party issues, drowning genuine regressions in noise. No behavior change for users. Generated-By: PostHog Code Task-Id: 53904987-f9af-4349-88dd-148080ff915d
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ❌ Deployment failed View logs |
canadaspends | 5589240 | Aug 07 2026, 05:41 PM |
🚨 Preview Deployment Blocked - Security ProtectionYour pull request was blocked from triggering preview deployments Why was this blocked?
How to resolve this:Option 1: Get Collaborator Access (Recommended) Option 2: Request Permission Override For Repository Administrators:To disable this security check ( This security measure protects against malicious code execution in preview deployments. Only trusted collaborators should have the ability to trigger deployments. 🛡️ Learn more about this security featureThis protection prevents unauthorized users from:
Preview deployments are powerful but require trust. Only users with repository write access can trigger them. |
Problem
posthog.init()insrc/app/[lang]/providers.tsxhad nobefore_sendhook, so anything a browser extension or injected script throws inside our pages lands in our issue list.TypeError: window.scanPdf is not a functionon/en/first-nations/ISC_8/2022— a page that renders a government PDF in an iframe. The event has no stack frames, no source,handled: false: the classic shape of a PDF-scanning extension injecting awindow.scanPdfglobal.scanPdfappears nowhere in our bundle.beTracker, Cloudflare Zaraz fetch failures, andruntime.sendMessageextension errors dominate the backlog.Changes
before_sendhook that drops$exceptionevents with no first-party stack frames — i.e. no frame markedin_app. Exceptions with no frames at all (cross-originScript error.) can't be attributed to us and are treated as third-party.scanPdf,beTracker,runtime.sendMessage,zaraz.$exceptionevents pass through untouched. No user-facing behavior change.Risk
captureExceptionwithout a stacktrace) would be dropped. The codebase has no such manual captures today, and normal thrown errors carry in-app frames, so this is low-risk and matches the intent of trusting only attributable errors.Verification
tsc --noEmit,next lint --file, andprettier --checkall pass on the changed file (remaining repo-widetscerrors are pre-existing and unrelated — MDX component typing and missingvitesttypes in test files).Agent context
providers.tsxor exception filtering (PR Add Supabase Auth with OAuth and PostHog identification #269 mentions PostHog but only for auth/identification). No competing work in flight.buildcanada/atip(LICENSE-only); the fix belongs in this repo. Suppressing/resolving the existing noise issues in the PostHog error-tracking backlog still needs to be done in the PostHog UI once this ships.Created with PostHog Desktop from this inbox report.