Repository navigation
[CI] (0e81558) fastapi/fastapi3-ai-saas - #4239
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 a dedicated PostHog client module, ASGI middleware for per-request context/identity binding, event captures across auth, generation, API key, and settings routes, exception tracking via
Confidence score: 4/5 👍
File changes
App sanity check
|
| Criteria | Result | Description |
|---|---|---|
| App builds and runs | Yes | All imports resolve, syntax is valid, dependencies declared |
| Preserves existing env vars & configs | Yes | Existing settings and configs untouched |
| No syntax or type errors | Yes | All code is syntactically valid Python |
| Correct imports/exports | Yes | All imports reference correct packages and modules |
| Minimal, focused changes | No | The OTel log pipeline (posthog_logs.py + 3 OTel deps) is scope creep beyond PostHog integration |
| Pre-existing issues | None | No pre-existing issues observed |
Issues
- OTel log pipeline is unnecessary scope creep: The
posthog_logs.pymodule and its 3 OTel dependencies add significant complexity for a single log statement. A plainposthog.capture()call would achieve the same result with zero extra dependencies. [MEDIUM]
Other completed criteria
- Environment variables documented in
.env.example - Build configuration valid with pinned PostHog SDK version
- Pydantic Settings used for configuration with env file support
PostHog implementation ⚠️
| Criteria | Result | Description |
|---|---|---|
| PostHog SDKs installed | Yes | posthog==7.60.1 in requirements.txt |
| PostHog client initialized | Yes | Posthog() constructor with project_api_key, host, and enable_exception_autocapture=True in posthog.py; atexit.register(posthog_client.shutdown) for cleanup |
| API key from env | Yes | Loaded via Pydantic Settings from POSTHOG_PROJECT_TOKEN env var |
| Host configured | Yes | Loaded via Pydantic Settings from POSTHOG_HOST env var |
| capture() | Yes | Multiple meaningful capture calls across routes |
| identify() | N/A | Server-only app |
| Error tracking | Yes | enable_exception_autocapture=True in constructor; manual capture_exception() in 500 handler |
| Reverse proxy | N/A | Server-only app |
Issues
- 500 handler
capture_exceptionlacks PostHog context: The exception handler inmain.pycallsposthog_client.capture_exception(exc)but runs outside the middleware'snew_context()block, so the exception won't be attributed to the user who triggered it. The exception is still captured (autocapture also covers this), but the manual call adds no user context. [MEDIUM]
Other completed criteria
atexit.register(posthog_client.shutdown)ensures events are flushed on exit- Lifespan shutdown calls
flush()thenshutdown()for belt-and-suspenders cleanup - Middleware correctly wraps requests in
new_context()and callsidentify_context()for authenticated users identify_authenticated_user()in auth routes callsidentify_context()after login/signup so the request's captures are attributed correctly- Person properties set via
posthog_client.set()(the correct SDK method for Python)
PostHog insights and events ✅
| Filename | PostHog events | Description |
|---|---|---|
app/routers/auth.py |
user_logged_in, user_signed_up, user_logged_out |
Core auth funnel events with person properties set on login/signup |
app/routers/generate.py |
generation_completed |
AI generation event with type, credits, and prompt length properties |
app/routers/api_keys.py |
api_key_created, api_key_revoked |
API key lifecycle events; created includes active key count |
app/routers/settings.py |
email_updated, password_changed |
Account settings change events; email update also sets person property |
app/main.py |
capturedException |
500 handler captures server exceptions |
app/posthog_logs.py |
application_started, content_generation_completed (via OTel logs) |
Application lifecycle and generation logs via OTel pipeline |
Issues
- No critical issues with event quality.
Other completed criteria
- Events represent real user actions mapping to product flows (auth funnel, content generation, API key management)
- Events enable product insights: signup → generation → API key creation funnel is trackable
- Events include relevant contextual properties (credits_used, generation_type, prompt_length, active_key_count)
- No PII in capture() event properties — email is only in
set()person properties - Event naming is descriptive and uses 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:
0e81558App:
fastapi/fastapi3-ai-saasApp directory:
apps/fastapi/fastapi3-ai-saasWorkbench branch:
wizard-ci-0e81558-fastapi-fastapi3-ai-saasWizard branch:
release-please--branches--main--components--wizardContext Mill branch:
mainPostHog (MCP) branch:
masterTimestamp: 2026-09-29T08:20:59.852Z
Duration: 444.1s
YARA Scanner