feat(backend): integrate PostHog analytics for enhanced observability

- 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.
This commit is contained in:
DESKTOP-RTLN3BA\$punk 2026-07-22 22:16:28 -07:00
parent ca4f231577
commit dbedf0cfa5
47 changed files with 1618 additions and 513 deletions

View file

@ -37,7 +37,11 @@ class SurfSenseClient:
self._fallback_api_key = fallback_api_key
self._http = httpx.AsyncClient(
base_url=api_base,
headers={"Accept": "application/json"},
# ``X-SurfSense-Client`` lets the backend distinguish PAT traffic
# originating from this MCP server vs. raw PAT scripts, so
# "documents added via MCP" / "searches via MCP" are queryable.
# Server-to-server, so no CORS implications.
headers={"Accept": "application/json", "X-SurfSense-Client": "mcp"},
timeout=timeout,
)