Conversation
- Added PostHog configuration options to .env.example files for both Docker and Surfsense backend. - Introduced PostHog dependency in pyproject.toml. - Implemented analytics middleware to capture various events across the application, including user authentication, automation runs, and API requests. - Enhanced existing routes and services to emit analytics events, providing insights into user interactions and system performance. - Ensured graceful shutdown of analytics clients in worker processes and application lifecycles.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Description
Motivation and Context
FIX #
Screenshots
API Changes
Change Type
Testing Performed
Checklist
High-level PR Summary
This PR integrates PostHog analytics into the backend to provide server-side event tracking for enhanced observability. It introduces a new analytics module that captures authoritative product events (authentication, chat turns, document processing, connector operations, automations, billing, and API usage) that the frontend cannot reliably observe—especially traffic from MCP clients, PAT scripts, OAuth callbacks, and Celery background jobs. The implementation is fully opt-in (no-op when
POSTHOG_API_KEYis unset), includes privacy-preserving defaults for LLM content, and is designed to be fork-safe for Celery workers. The frontend analytics were simultaneously cleaned up to remove redundant optimistic event captures, ensuring server-side events serve as the single source of truth for outcome metrics while client-side tracking focuses on user intent and UX interactions.⏱️ Estimated Review Time: 30-90 minutes
💡 Review Order Suggestion
surfsense_backend/pyproject.tomlsurfsense_backend/uv.lockdocker/.env.examplesurfsense_backend/.env.examplesurfsense_backend/app/config/__init__.pysurfsense_backend/app/observability/__init__.pysurfsense_backend/app/observability/analytics.pysurfsense_backend/tests/unit/observability/test_analytics.pysurfsense_backend/app/celery_app.pysurfsense_backend/app/app.pysurfsense_backend/app/users.pysurfsense_backend/app/routes/anonymous_chat_routes.pysurfsense_backend/app/tasks/chat/streaming/flows/shared/analytics.pysurfsense_backend/app/tasks/chat/streaming/flows/new_chat/orchestrator.pysurfsense_backend/app/tasks/chat/streaming/flows/resume_chat/orchestrator.pysurfsense_backend/app/routes/new_chat_routes.pysurfsense_backend/app/routes/public_chat_routes.pysurfsense_backend/app/capabilities/core/access/rest.pysurfsense_backend/app/tasks/celery_tasks/connector_tasks.pysurfsense_backend/app/routes/search_source_connectors_routes.pysurfsense_backend/app/tasks/celery_tasks/document_tasks.pysurfsense_backend/app/automations/services/automation.pysurfsense_backend/app/automations/services/trigger.pysurfsense_backend/app/automations/runtime/executor.pysurfsense_backend/app/routes/image_generation_routes.pysurfsense_backend/app/podcasts/tasks/render.pysurfsense_backend/app/tasks/celery_tasks/video_presentation_tasks.pysurfsense_backend/app/routes/rbac_routes.pysurfsense_backend/app/routes/incentive_tasks_routes.pysurfsense_backend/app/routes/stripe_routes.pysurfsense_backend/app/routes/workspaces_routes.pysurfsense_backend/app/routes/personal_access_tokens_routes.pysurfsense_mcp/mcp_server/core/client.pysurfsense_web/lib/posthog/events.tssurfsense_web/app/(home)/login/LocalLoginForm.tsxsurfsense_web/app/(home)/register/page.tsxsurfsense_web/components/layout/ui/dialogs/CreateWorkspaceDialog.tsxsurfsense_web/app/dashboard/[workspace_id]/team/team-content.tsxsurfsense_web/app/invite/[invite_code]/page.tsxsurfsense_web/atoms/automations/automations-mutation.atoms.tssurfsense_web/components/assistant-ui/connector-popup/hooks/use-connector-dialog.tssurfsense_web/components/sources/DocumentUploadTab.tsxsurfsense_web/lib/chat/stream-engine/engine.tssurfsense_web/hooks/use-run-stream.tssurfsense_web/components/settings/earn-credits-content.tsxsurfsense_web/lib/apis/base-api.service.tssurfsense_web/content/docs/observability.mdx