Skip to content

[CI] (edaca63) fastapi/fastapi3-ai-saas - #2876

Closed
wizard-ci-bot[bot] wants to merge 1 commit into
mainfrom
wizard-ci-edaca63-fastapi-fastapi3-ai-saas
Closed

wizard-ci-bot[bot] wants to merge 1 commit into
mainfrom
wizard-ci-edaca63-fastapi-fastapi3-ai-saas

Conversation

@wizard-ci-bot

@wizard-ci-bot wizard-ci-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

Automated wizard CI run

Source: wizard-pr
Trigger ID: edaca63
App: fastapi/fastapi3-ai-saas
App directory: apps/fastapi/fastapi3-ai-saas
Workbench branch: wizard-ci-edaca63-fastapi-fastapi3-ai-saas
Wizard branch: release-please--branches--main--components--wizard
Context Mill branch: main
PostHog (MCP) branch: master
Timestamp: 2026-07-16T16:57:00.689Z
Duration: 195.1s

YARA Scanner

✓ 89 tool calls scanned, 0 violations detected

No violations: ✓ 89 clean scans

@wizard-ci-bot

wizard-ci-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown
Author

PR Evaluation Report

Summary

This PR adds server-side PostHog analytics to a FastAPI AI SaaS application. It creates a shared PostHog client with exception autocapture, adds capture calls across auth, content generation, API key, and settings routes, and documents environment variables. The implementation is clean and well-structured but uses flush() instead of shutdown() in the lifespan handler.

Files changed Lines added Lines removed
10 +119 -0

Confidence score: 5/5 🧙

  • flush() used instead of shutdown() in lifespan: The FastAPI docs recommend calling posthog.flush() in the lifespan shutdown, but the framework rules say to call shutdown() to ensure all events are sent. Since atexit.register(posthog_client.shutdown) is also present, events should still be flushed, but shutdown() in the lifespan would be more correct and atexit may not fire reliably in all ASGI deployments. [MEDIUM]
  • No context API usage: The PR uses the direct distinct_id parameter pattern on every capture() call rather than the recommended context-based approach (new_context() + identify_context()). While functional, this misses the benefit of automatic context propagation and the exception autocapture context association. [MEDIUM]
  • .env.example uses comments instead of placeholder values: The env vars are listed as comments (# POSTHOG_PROJECT_TOKEN) rather than as POSTHOG_PROJECT_TOKEN= with empty or placeholder values. Since the Pydantic Settings model marks them as required str fields with no defaults, the app will fail to start without them set. [LOW]

File changes

Filename Score Description
app/posthog_client.py 4/5 New file creating shared PostHog client with Pydantic settings, exception autocapture, and atexit shutdown
app/config.py 5/5 Adds posthog_project_token and posthog_host to Pydantic Settings
app/main.py 4/5 Imports client and adds flush() in lifespan shutdown (should be shutdown())
app/routers/auth.py 4/5 Captures signup, login, logout events with person property setting via set()
app/routers/generate.py 5/5 Captures content generation and blocked generation events with rich properties
app/routers/api_keys.py 5/5 Captures API key creation and revocation with active key count
app/routers/settings.py 5/5 Captures email update and password change events
.env.example 3/5 Documents PostHog env vars but as comments rather than assignable placeholders
requirements.txt 5/5 Adds posthog>=6.0.0 dependency
posthog-setup-report.md 5/5 Comprehensive setup report documenting all events and next steps

App sanity check ⚠️

Criteria Result Description
App builds and runs Yes All imports valid, dependencies added, no syntax errors
Preserves existing env vars & configs Yes All existing config preserved, PostHog settings appended
No syntax or type errors Yes Clean Python syntax throughout
Correct imports/exports Yes from posthog import Posthog and all internal imports are correct
Minimal, focused changes Yes Only PostHog-related additions, no unrelated modifications
Pre-existing issues None No pre-existing issues observed

Issues

  • .env.example format: PostHog env vars are listed as comments (# POSTHOG_PROJECT_TOKEN) instead of POSTHOG_PROJECT_TOKEN=<your-token>. Since the Pydantic Settings class requires these fields (no default), the app will crash on startup if they are not set. Developers copying .env.example to .env won't get the variable names automatically. [LOW]

Other completed criteria

  • All changes relate to PostHog integration
  • Correct files modified for FastAPI framework
  • Code follows existing codebase patterns (Pydantic Settings, router structure)
  • Build configuration valid with posthog>=6.0.0 in requirements.txt

PostHog implementation ⚠️

Criteria Result Description
PostHog SDKs installed Yes posthog>=6.0.0 added to requirements.txt
PostHog client initialized Yes Posthog() constructor used with settings-based config, enable_exception_autocapture=True, and atexit shutdown
capture() Yes 9 meaningful capture calls across auth, generation, API key, and settings routes
identify() N/A Server-only app
Error tracking Yes enable_exception_autocapture=True in client constructor
Reverse proxy N/A Server-only app

Issues

  • flush() instead of shutdown() in lifespan: The lifespan shutdown calls posthog_client.flush() but should call posthog_client.shutdown() to ensure all events are fully sent and background threads are cleaned up. While atexit.register(posthog_client.shutdown) provides a safety net, atexit handlers may not fire reliably in all ASGI server shutdown scenarios (e.g., containerized environments with SIGKILL). [MEDIUM]
  • No context API usage: All capture calls pass distinct_id directly rather than using the recommended new_context() + identify_context() pattern. This means exception autocapture won't automatically associate exceptions with the correct user, losing a key benefit of enabling it. The FastAPI docs show using contexts at the top of each route. [MEDIUM]

Other completed criteria

  • API key loaded from environment variable via Pydantic Settings
  • Host correctly configured from environment variable
  • Person properties set via posthog_client.set() (correct Python SDK method) rather than identify()
  • atexit.register(posthog_client.shutdown) ensures flush on process exit

PostHog insights and events ✅

Filename PostHog events Description
app/routers/auth.py user_signed_up, user_logged_in, user_logged_out Auth lifecycle events with login/signup method properties; person properties set via set()
app/routers/generate.py content_generated, generation_blocked Core product events tracking AI generation with type, credits used/remaining
app/routers/api_keys.py api_key_created, api_key_revoked API key lifecycle with active key count metric
app/routers/settings.py email_updated, password_changed Account management events
app/posthog_client.py capturedException (autocapture) Automatic exception tracking via enable_exception_autocapture=True

Issues

No issues — events are well-designed with meaningful names, enriched properties, and no PII leakage.

Other completed criteria

  • Events represent real user actions (signup, login, content generation, key management)
  • Events enable product insights (signup→generation funnel, credit usage trends, key management patterns)
  • Events include relevant properties (generation type, credits, key counts)
  • No PII in event properties — email set only via set() on person profile
  • Consistent snake_case naming convention following [noun]_[verb] pattern

Reviewed by wizard workbench PR evaluator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants