Skip to content

Observability PII session context#231

Open
iamEvanYT wants to merge 6 commits intomainfrom
cursor/observability-pii-session-context-6cec
Open

Observability PII session context#231
iamEvanYT wants to merge 6 commits intomainfrom
cursor/observability-pii-session-context-6cec

Conversation

@iamEvanYT
Copy link
Member

Improve PostHog observability by adding PII sanitization, session context, comprehensive lifecycle and performance events, and crash reporting, with telemetry disabled in development.


Open in Web Open in Cursor 

cursoragent and others added 2 commits March 6, 2026 16:40
- Add sanitize-pii.ts: scrubs URLs (keeps origin, redacts path/query/fragment),
  email addresses, IPv4 addresses, and known sensitive keys (url, title, cookie,
  authorization, token, etc.) from all PostHog event and exception properties.
  Handles nested objects, arrays, exception lists, and stack frame context lines.

- Add session.ts: generates a per-app-launch session UUID so all events and
  exceptions from a single run can be correlated via $session_id.

- Update PosthogController: captureEvent and captureException now pipe all
  properties through sanitizeProperties and inject $session_id.

- Update ErrorTracking SDK: autocaptured exceptions now include $session_id
  and have their properties sanitized before being sent to PostHog.

Co-authored-by: Evan <iamEvanYT@users.noreply.github.com>
…e PostHog in dev

PostHog disabled in development:
- PostHog client is only created when app.isPackaged is true.
  All captureEvent/captureException calls are no-ops in dev mode.
- ErrorTracking autocapture and crash reporter are also skipped.

Lifecycle & user action events (via observability.ts):
- Tab: tab-created, tab-closed, tab-switched (throttled 500ms)
- Window: window-created, window-closed (with windowType)
- Space: space-created, space-deleted
- Profile: profile-created, profile-deleted
- Settings: setting-changed
- Onboarding: onboarding-completed
- Extensions: extension-installed, extension-uninstalled
- Updates: update-available, update-downloaded (deduplicated per version)

Performance metrics:
- app-ready: includes startupMs (time from module load to app.whenReady)
- tab-load-finished: includes loadDurationMs (did-start-loading to did-finish-load)
- tab-load-failed: includes errorCode (for main frame failures)

Crash reporter:
- Electron crashReporter started with sessionId in extras
- child-process-gone and render-process-gone events sent to PostHog
  with process type, reason, and exit code

Co-authored-by: Evan <iamEvanYT@users.noreply.github.com>
@cursor
Copy link

cursor bot commented Mar 6, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

Build artifacts for all platforms are ready! 🚀

Download the artifacts for:

One-line installer (Unstable):
bunx flow-debug-build --open 22825931528

(execution 22825931528 / attempt 1)

@greptile-apps
Copy link

greptile-apps bot commented Mar 6, 2026

Greptile Summary

This PR significantly improves the PostHog observability infrastructure by adding PII sanitization via a before_send hook, per-launch session IDs, comprehensive lifecycle/performance event tracking, crash reporting, and gating all telemetry behind app.isPackaged (disabled in dev).

Key changes:

  • PII sanitization (sanitize-pii.ts): Redacts URLs, emails, and IPs from all outgoing events via before_send; sensitive keys (e.g. url, token, cookie) are fully redacted; a SAFE_STRING_KEYS allowlist ("version") preserves useful version strings.
  • Session context (session.ts): A per-launch crypto.randomUUID() session ID is injected into every event via withContext.
  • Observability events (observability.ts): Tab load timing, window/space/profile lifecycle events, update status tracking, and app-ready startup timing. Uses appStartTimestamp = performance.timeOrigin to measure real process-start-to-ready latency.
  • Exception autocapture (exception-autocapture.ts): Replaces the custom SDK fork with @posthog/core utilities; adds rate limiting and duplicate-capture prevention.
  • Crash reporting: crashReporter.start() annotated with the session ID; child-process and renderer crash events forwarded to PostHog.
  • Dev mode gating: The entire PostHog client is skipped when !app.isPackaged, so no events are sent during development.

Issues found:

  • In exception-autocapture.ts, the onFatalFn passed to makeUncaughtExceptionHandler is async but called without await, so if client.shutdown() rejects, process.exit(1) is never invoked and the process continues in a post-crash zombie state.

Confidence Score: 2/5

  • NOT safe to merge — critical async/await correctness bug in fatal error handler could cause process hang if shutdown fails.
  • The PR implements solid observability infrastructure with good PII sanitization and session context. However, exception-autocapture.ts has a critical correctness issue where the async onFatalFn is called without awaiting its Promise, so if client.shutdown() rejects, process.exit(1) is never invoked and the process hangs in a corrupted post-crash state. This is a blocking issue that must be fixed before merge.
  • src/main/controllers/posthog-controller/exception-autocapture.ts requires attention for the async/await mismatch in the fatal error handler.

Last reviewed commit: 6d2ea49

@iamEvanYT
Copy link
Member Author

@greptile review

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