Repository navigation
[CI] (9f92c68) fastapi/fastapi3-ai-saas - #2513
wizard-ci-bot[bot] wants to merge 1 commit into
Conversation
|
Now I have all the context I need. The PR Evaluation ReportSummaryThis PR integrates PostHog analytics into a FastAPI AI SaaS application. It adds PostHog initialization in the lifespan manager, creates a custom ASGI middleware for request-scoped contexts, and instruments 9 events across auth, content generation, API key management, and settings routes. The integration has two significant issues: it calls a non-existent
Confidence score: 4/5 👍
File changes
App sanity check
|
| Criteria | Result | Description |
|---|---|---|
| App builds and runs | Yes | Python won't fail at import time; the posthog.identify() error only triggers at runtime on login/signup |
| Preserves existing env vars & configs | Yes | All existing code preserved; new settings added additively |
| No syntax or type errors | No | posthog.identify() does not exist in the Python SDK — this is a runtime AttributeError |
| Correct imports/exports | Yes | All imports resolve to valid posthog module-level functions |
| Minimal, focused changes | Yes | All changes are PostHog-related |
| Pre-existing issues | None | Base app is clean |
Issues
posthog.identify()does not exist: The Python SDK has noidentify()method. The two calls inauth.pywill raiseAttributeErrorat runtime during login and signup flows. Replace withposthog.set(distinct_id=str(user.id), properties={"is_active": user.is_active}). [CRITICAL].env.examplenot updated: New PostHog environment variables (POSTHOG_PROJECT_TOKEN,POSTHOG_HOST,POSTHOG_DISABLED) are not documented in.env.example. [MEDIUM]
Other completed criteria
- App starts and initializes PostHog correctly in the lifespan context manager
- Existing routers, models, and database initialization are fully preserved
- PostHog middleware is registered cleanly via
app.add_middleware() posthog.flush()called on shutdown to ensure events are sent
PostHog implementation ⚠️
| Criteria | Result | Description |
|---|---|---|
| PostHog SDKs installed | Yes | posthog>=3.0.0 added to requirements.txt |
| PostHog client initialized | Yes | Module-level posthog.api_key and posthog.host set in lifespan context manager, matching FastAPI pattern |
| capture() | Yes | 9 capture calls across auth, generate, api_keys, and settings routers |
| identify() | N/A | Server-only app |
| Error tracking | Yes | Middleware wraps all requests in new_context() which auto-captures exceptions by default |
| Reverse proxy | N/A | Server-only app |
Issues
- Non-existent
posthog.identify()called:auth.pycallsposthog.identify(user.email, {"is_active": user.is_active})twice. The Python SDK does not have anidentify()method — useposthog.set(distinct_id=str(user.id), properties={"is_active": user.is_active})to set person properties. [CRITICAL] - Email as distinct_id: Both the middleware (
identify_context(user.email)) and auth routes useuser.emailas the distinct_id. The User model has an integeridprimary key which is a stable, non-PII identifier — usestr(user.id)instead. [CRITICAL]
Other completed criteria
- API key loaded from environment via Pydantic Settings (
posthog_project_tokenmaps toPOSTHOG_PROJECT_TOKENenv var) - Host correctly configured to
https://us.i.posthog.com - PostHog disabled flag allows disabling in tests/dev
- Middleware correctly uses
new_context()withidentify_context()andtag()pattern
PostHog insights and events ⚠️
| Filename | PostHog events | Description |
|---|---|---|
app/routers/auth.py |
user_signed_up, user_logged_in, user_logged_out |
Auth lifecycle events; signup/login include method properties |
app/routers/generate.py |
content_generated, insufficient_credits |
Content generation with type, credits_used, credits_remaining; insufficient credits with credits_needed/available |
app/routers/api_keys.py |
api_key_created, api_key_revoked |
API key lifecycle events (no enriching properties) |
app/routers/settings.py |
settings_updated, password_changed |
Account settings changes; settings_updated includes fields_changed |
Issues
- Email used as distinct_id is PII: Raw email addresses are used as distinct IDs via
identify_context(user.email)throughout. This embeds PII into every event's distinct_id field. Use the user's integer primary key instead. [CRITICAL] - API key events lack properties:
api_key_createdandapi_key_revokedhave no properties — adding the key name or key ID would improve debuggability. [LOW]
Other completed criteria
- Events represent real user actions mapped to actual product flows (signup → login → generate → manage keys)
- Events enable product insights — can build signup-to-generation funnel, track credit depletion, monitor API key activity
- Content generation events include rich properties (generation_type, credits_used, credits_remaining)
- Event names follow consistent snake_case convention with descriptive verb-based naming
Reviewed by wizard workbench PR evaluator
Automated wizard CI run
Source: wizard-pr
Trigger ID:
9f92c68App:
fastapi/fastapi3-ai-saasApp directory:
apps/fastapi/fastapi3-ai-saasWorkbench branch:
wizard-ci-9f92c68-fastapi-fastapi3-ai-saasWizard branch:
release-please--branches--main--components--wizardContext Mill branch:
mainPostHog (MCP) branch:
masterTimestamp: 2026-07-08T16:48:35.818Z
Duration: 451.9s
YARA Scanner