Skip to content

[CI] (0e81558) fastapi/fastapi3-ai-saas - #4239

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

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

Conversation

@wizard-ci-bot

@wizard-ci-bot wizard-ci-bot Bot commented Sep 29, 2026

Copy link
Copy Markdown

Automated wizard CI run

Source: wizard-pr
Trigger ID: 0e81558
App: fastapi/fastapi3-ai-saas
App directory: apps/fastapi/fastapi3-ai-saas
Workbench branch: wizard-ci-0e81558-fastapi-fastapi3-ai-saas
Wizard branch: release-please--branches--main--components--wizard
Context Mill branch: main
PostHog (MCP) branch: master
Timestamp: 2026-09-29T08:20:59.852Z
Duration: 444.1s

YARA Scanner

✓ 189 tool calls scanned, 0 violations detected

No violations: ✓ 189 clean scans

@wizard-ci-bot

wizard-ci-bot Bot commented Sep 29, 2026

Copy link
Copy Markdown
Author

PR Evaluation Report

Summary

This 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 capture_exception, and an OpenTelemetry-based log export pipeline to PostHog.

Files changed Lines added Lines removed
11 +267 -3

Confidence score: 4/5 👍

  • Email in posthog_client.set() properties dict: identify_authenticated_user() passes "email": user.email inside posthog_client.set(properties={...}). The set() method sets person properties (equivalent to ``), which is the correct place for PII like email — this is acceptable. However, credits and `is_active` are transient state, not stable person properties, which is a minor design concern. [LOW]
  • OpenTelemetry log pipeline adds significant scope creep: The posthog_logs.py module introduces three new OTel dependencies (opentelemetry-api, opentelemetry-sdk, opentelemetry-exporter-otlp) and a custom log export pipeline. This is well beyond a basic PostHog integration and adds substantial operational complexity for a single posthog_logger.info("content_generation_completed") call. A standard posthog.capture() call would have sufficed. [MEDIUM]
  • Missing distinct_id on several capture calls: Multiple capture() calls in api_keys.py, settings.py, and the 500 error handler lack an explicit distinct_id. They rely on the middleware's new_context() + identify_context(), which is correct for authenticated routes. However, the 500 handler in main.py calls capture_exception(exc) outside any PostHog context — it will be sent as an anonymous event with no user attribution. [MEDIUM]

File changes

Filename Score Description
app/posthog.py 4/5 New module: initializes Posthog client with enable_exception_autocapture=True, registers atexit shutdown. Clean and correct.
app/posthog_logs.py 2/5 New module: OTel log export to PostHog. Scope creep — adds 3 heavy dependencies for a single log line.
app/middleware.py 4/5 ASGI middleware that resolves authenticated user from session cookie and sets PostHog context. Synchronous DB call in async path is not ideal but functional.
app/main.py 3/5 Lifespan startup/shutdown, adds middleware, 500 handler captures exceptions. Exception handler has no context.
app/routers/auth.py 4/5 Captures user_logged_in, user_signed_up, user_logged_out; identifies user via identify_context + set().
app/routers/generate.py 4/5 Captures generation_completed with rich properties. Also uses posthog_logger.
app/routers/api_keys.py 4/5 Captures api_key_created and api_key_revoked.
app/routers/settings.py 4/5 Captures email_updated, password_changed; updates person properties on email change.
app/config.py 5/5 Adds posthog_project_token and posthog_host to Pydantic Settings.
.env.example 5/5 Documents new PostHog env vars.
requirements.txt 3/5 Adds posthog==7.60.1 plus 3 OTel packages — the OTel packages are unnecessary for basic integration.

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.py module and its 3 OTel dependencies add significant complexity for a single log statement. A plain posthog.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_exception lacks PostHog context: The exception handler in main.py calls posthog_client.capture_exception(exc) but runs outside the middleware's new_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() then shutdown() for belt-and-suspenders cleanup
  • Middleware correctly wraps requests in new_context() and calls identify_context() for authenticated users
  • identify_authenticated_user() in auth routes calls identify_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

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