Repository navigation
[CI] (3f39e0e) fastapi/fastapi3-ai-saas - #4155
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 into a FastAPI AI SaaS application by adding the Python SDK with instance-based initialization in the lifespan handler, a custom ASGI middleware for user identity context, event captures across auth/generation/settings/API-key routes, error tracking via exception handler and autocapture, and an OpenTelemetry log exporter for structured logging to PostHog.
Confidence score: 5/5 🧙
File changes
App sanity check
|
| Criteria | Result | Description |
|---|---|---|
| App builds and runs | Yes | All imports resolve, dependencies added, no syntax errors |
| Preserves existing env vars & configs | Yes | Existing env vars and configs unchanged; PostHog additions are additive |
| No syntax or type errors | Yes | Code is syntactically valid Python |
| Correct imports/exports | Yes | All imports are correct — posthog.Posthog, OTel packages, internal modules |
| Minimal, focused changes | Yes | All changes relate to PostHog integration |
| Pre-existing issues | None |
Issues
- Synchronous DB in async middleware:
_get_authenticated_user()callsSessionLocal()andUser.get_by_id()synchronously, blocking the asyncio event loop on every HTTP request. Should userun_in_executoror an async session. [MEDIUM] - RuntimeError on missing config in debug mode: Raising
RuntimeErrorin the lifespan when PostHog env vars are missing crashes the entire app in debug mode. A warning log would be safer. [MEDIUM]
Other completed criteria
- Environment variables properly documented in
.env.example - Build configuration valid with pinned dependency versions
- All changes are relevant to PostHog integration
- Code follows existing codebase patterns (guard patterns, router structure)
PostHog implementation ⚠️
| Criteria | Result | Description |
|---|---|---|
| PostHog SDKs installed | Yes | posthog==7.60.0 added to requirements.txt |
| PostHog client initialized | Yes | Instance-based Posthog() constructor in lifespan with enable_exception_autocapture=True |
| capture() | Yes | Multiple meaningful capture calls across auth, generation, settings, and API key routes |
| identify() | N/A | Server-only app |
| Error tracking | Yes | enable_exception_autocapture=True plus manual capture_exception() in 500 handler |
| Reverse proxy | N/A | Server-only app |
Issues
- No
flush()beforeshutdown()needed — but atexit + lifespan double-shutdown: The client is shut down both viaatexit.register(posthog_client.shutdown)and in the lifespan teardown. The secondshutdown()call on an already-shut-down client may log warnings or behave unexpectedly. Theatexitregistration is a good safety net, but callingshutdown()twice is not ideal. [LOW]
Other completed criteria
- API key loaded from environment variable via Pydantic Settings (
posthog_project_token) - Host correctly configured from environment variable (
posthog_host) - Screen views: N/A (server-only)
- All targets initialized: N/A (single-target)
- User identification done correctly via
identify_context()in middleware withstr(user.id)as distinct_id - Person properties set via
posthog_client.set()with email inidentify_authenticated_userand settings update
PostHog insights and events ✅
| Filename | PostHog events | Description |
|---|---|---|
app/routers/auth.py |
user_logged_in, user_signed_up, user_logged_out |
Core auth funnel with login method and signup method properties |
app/routers/generate.py |
content_generated |
Core product action with generation_type, credits_used, prompt_length |
app/routers/api_keys.py |
api_key_created, api_key_revoked |
API key lifecycle with active_key_count |
app/routers/settings.py |
email_updated, password_changed |
Account settings changes |
app/main.py |
capturedException |
500 error handler captures exceptions with user context |
Issues
No issues.
Other completed criteria
- Events represent real user actions mapping to actual product flows
- Events enable product insights — signup→login→generate funnel is clearly buildable
- Events include relevant contextual properties (generation_type, credits_used, login_method, etc.)
- No PII in event properties — email is set via
posthog_client.set()as person property, not in capture properties - Event names are descriptive, consistent snake_case convention
Reviewed by wizard workbench PR evaluator
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:
3f39e0eApp:
fastapi/fastapi3-ai-saasApp directory:
apps/fastapi/fastapi3-ai-saasWorkbench branch:
wizard-ci-3f39e0e-fastapi-fastapi3-ai-saasWizard branch:
release-please--branches--main--components--wizardContext Mill branch:
mainPostHog (MCP) branch:
masterTimestamp: 2026-09-23T21:57:26.646Z
Duration: 572.9s
YARA Scanner