Skip to content

fix(posthog): server flush, event data quality & dedup#2163

Open
sleyter93 wants to merge 3 commits into
v1.21.0from
fix/posthog-shutdown-and-event-quality
Open

fix(posthog): server flush, event data quality & dedup#2163
sleyter93 wants to merge 3 commits into
v1.21.0from
fix/posthog-shutdown-and-event-quality

Conversation

@sleyter93

Copy link
Copy Markdown
Collaborator

Review fixes on top of #2162 (PostHog). Targets v1.21.0.

Server-side flush (the important one)

  • login/route.ts: removed await posthog.shutdown() per request. The server client is a long-lived singleton (Node standalone) and flushAt: 1 already sends in the background. Per-request shutdown() tore down shared state (feature-flag poller, error tracking) and raced across concurrent logins (shared shutdownPromise).
  • instrumentation.ts: drain the queue once on SIGTERM/SIGINT instead — the correct place for shutdown().

Event data quality

  • Address casing: lowercase delegatee_address / previous_delegatee_address to match the wallet_address identity model (otherwise breakdowns split checksummed vs lowercase).
  • rewards_claim_failed: add tx_hash (backer + builder) for parity with the other tx-failure events; exposed hash from the claim hooks. (Present only when a tx was actually broadcast — undefined on wallet rejection / pre-broadcast failure, which is correct signal.)
  • Proposal submit: enriched the captureException with category + proposal_name (kept as an exception on purpose — it's a "submission broke" case, not a user-rejection metric; wallet is already attached via super property).
  • proposal_page_viewed: removed. Redundant with auto-captured $pageview (filter by $pathname/$current_url), and it didn't even fire on proposal detail pages.

Dedup / consistency

  • txFailureProps() helper in commonErrors.ts: unifies user_rejected vs tx_failed classification (works for both executeTxFlow's synthetic error and raw wagmi errors) and truncates error_message (full detail lives in Sentry). Replaces the duplicated 'Rejected TX' literal across 9 call sites.
  • useRewardsClaimFailedCapture(): backer/builder modals now share one capture effect so they can't drift.

Docs

  • docs/POSTHOG_ANALYTICS.md updated to match all of the above (including the corrected server-side flush guidance, which previously recommended shutdown()).

Verified with tsc --noEmit and eslint (0 errors). Pre-existing, unrelated test failures on the branch (vault/health/staking/fund-manager) are not touched by this change.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Comment thread src/app/api/auth/login/route.ts Outdated
},
})
await posthog.shutdown()
// flushAt: 1 sends in the background; do NOT shutdown()/flush() per request (singleton).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can delete this comment.

import { ConnectWorkflow } from '@/shared/walletConnection/connection/ConnectWorkflow'

export default function ProposalsPage() {
useEffect(() => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I disagree taking out this, because we can track with Posthog data how many people really goes from the proposals general page, to one specific proposal, so we should keep track of it.

shutdown:
- login route no longer calls posthog.shutdown() per request; the
  server client is a long-lived singleton and flushAt:1 already sends
  in the background. Per-request shutdown tore down shared state and
  raced across concurrent logins.
- drain the queue once on SIGTERM/SIGINT in instrumentation.ts instead.

events:
- lowercase delegatee_address / previous_delegatee_address to match the
  wallet_address identity model (no more split breakdowns).
- add tx_hash to rewards_claim_failed (backer + builder) for parity with
  the other tx failure events; expose hash from the claim hooks.
- enrich proposal-submit captureException with category + proposal_name.
- drop redundant proposal_page_viewed ($pageview already covers it).
- extract txFailureProps() helper: unifies user_rejected/tx_failed
  classification (works for executeTxFlow's synthetic error and raw
  wagmi errors) and truncates error_message (full detail lives in
  Sentry). Replaces the duplicated 'Rejected TX' literal across 9 sites.
- extract useRewardsClaimFailedCapture() so backer/builder modals share
  one capture and can't drift.
- docs/POSTHOG_ANALYTICS.md updated to match all of the above.
@sleyter93 sleyter93 force-pushed the fix/posthog-shutdown-and-event-quality branch from 91d4426 to d664fde Compare June 25, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants