Repository navigation
[CI] (4ac81e3) fastapi/fastapi3-ai-saas - #2453
Closed
wizard-ci-bot[bot] wants to merge 1 commit into
Closed
wizard-ci-bot[bot] wants to merge 1 commit into
wizard-ci-bot[bot] wants to merge 1 commit into
Conversation
Author
PR Evaluation ReportSummaryThis PR integrates PostHog analytics into a FastAPI AI SaaS application. It adds module-level PostHog initialization in the app lifespan, creates a custom ASGI middleware for per-request user context, and instruments 11 events across 6 router modules covering auth, content generation, API key management, settings, and usage tracking.
Confidence score: 5/5 🧙
File changes
App sanity check ✅
|
| Criteria | Result | Description |
|---|---|---|
| PostHog SDKs installed | Yes | posthog>=3.0.0 in requirements.txt |
| PostHog client initialized | Yes | Module-level posthog.api_key / posthog.host set in FastAPI lifespan context manager, following the FastAPI-specific pattern |
| capture() | Yes | 11 meaningful capture() calls across all router modules |
| identify() | N/A | Server-only app |
| Error tracking | No | No enable_exception_autocapture=True, no capture_exception() calls anywhere |
| Reverse proxy | N/A | Server-only app |
Issues
- No error tracking configured: The Python SDK rules require
enable_exception_autocapture=Trueto automatically track exceptions. Neither autocapture nor manualcapture_exception()calls are present. The middleware wraps requests innew_context()which would capture exceptions if autocapture were enabled, but it isn't. Addposthog.enable_exception_autocapture = Trueduring initialization or switch to the instance-basedPosthog()constructor withenable_exception_autocapture=True. [CRITICAL] - Email used as distinct_id:
identify_context(user.email)is used in the middleware and auth routes. TheUsermodel has a properidfield (used ascurrent_user.idthroughout the codebase). Using email as distinct_id causes data fragmentation if users change their email and won't link to frontend sessions. Change toidentify_context(str(user.id)). [CRITICAL] flush()instead ofshutdown(): The lifespan shutdown callsposthog.flush()but should callposthog.shutdown()to flush the queue and cleanly terminate background threads. [MEDIUM]
Other completed criteria
- API key loaded from environment variable via Pydantic Settings (
posthog_project_token) - Host correctly configured, defaulting to
https://us.i.posthog.com posthog_disabledflag allows disabling PostHog in test/dev environments- Middleware correctly wraps requests in
new_context()for context propagation posthog.set()correctly used for person properties (notidentify()which doesn't exist in the Python SDK)
PostHog insights and events ⚠️
| Filename | PostHog events | Description |
|---|---|---|
app/routers/auth.py |
user_signed_up, user_logged_in, user_logged_out |
Full auth lifecycle; signup includes initial_credits, login includes login_method |
app/routers/generate.py |
content_generated, generation_failed_insufficient_credits |
Core product action with success/failure paths; includes credits_used, generation_type, prompt_length |
app/routers/api_keys.py |
api_key_created, api_key_revoked |
API key lifecycle tracking; creation includes active_key_count |
app/routers/pages.py |
dashboard_viewed |
Page view with total_generations, credits_remaining, api_key_count |
app/routers/settings.py |
settings_updated, password_changed |
Account management events; settings_updated includes fields_changed |
app/routers/usage.py |
usage_stats_viewed |
Usage page tracking with days_range and total_generations |
Issues
api_key_revokedlacks properties: Theapi_key_revokedevent has no properties — it would benefit from at least the key name or remaining active key count for context. [LOW]
Other completed criteria
- Events represent real user actions mapping to actual product flows (signup → generate content → view usage)
- Events enable product insights — can build signup-to-generation funnel, track insufficient credits as churn signal, monitor API key usage
- Events include relevant enriched properties (credits_used, generation_type, prompt_length, etc.)
- No PII in event properties — emails are not passed in capture() properties; person properties set via
posthog.set()correctly - Event names are descriptive, consistent snake_case, and follow
[noun]_[verb]convention
Reviewed by wizard workbench PR evaluator
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Automated wizard CI run
Source: wizard-pr
Trigger ID:
4ac81e3App:
fastapi/fastapi3-ai-saasApp directory:
apps/fastapi/fastapi3-ai-saasWorkbench branch:
wizard-ci-4ac81e3-fastapi-fastapi3-ai-saasWizard branch:
fix/pi-harness-use-warlockContext Mill branch:
mainPostHog (MCP) branch:
masterTimestamp: 2026-07-07T18:55:27.194Z
Duration: 468.7s
YARA Scanner