Skip to content

[CI] (0e81558) django/django3-saas - #4238

Closed
wizard-ci-bot[bot] wants to merge 1 commit into
mainfrom
wizard-ci-0e81558-django-django3-saas
Closed

wizard-ci-bot[bot] wants to merge 1 commit into
mainfrom
wizard-ci-0e81558-django-django3-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: django/django3-saas
App directory: apps/django/django3-saas
Workbench branch: wizard-ci-0e81558-django-django3-saas
Wizard branch: release-please--branches--main--components--wizard
Context Mill branch: main
PostHog (MCP) branch: master
Timestamp: 2026-09-29T08:20:05.504Z
Duration: 387.9s

YARA Scanner

✓ 190 tool calls scanned, 0 violations detected

No violations: ✓ 190 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 Django 3 SaaS application by adding the Python SDK with instance-based initialization in AppConfig.ready(), the PosthogContextMiddleware, a user_logged_in signal handler for identification, and capture calls across accounts, billing, and dashboard views. It also adds an OpenTelemetry OTLP logging exporter alongside the PostHog integration.

Files changed Lines added Lines removed
7 +211 -0

Confidence score: 4/5 👍

  • Instance client / module-level client mismatch: The PR creates a Posthog() instance stored in a module global (posthog_client) but adds PosthogContextMiddleware which uses the module-level posthog client (via setup()). Since posthog.api_key is never set, the middleware likely operates with a disabled module-level client. This means the middleware's automatic exception capture, context enrichment (IP, user-agent, URL, session headers), and distinct-ID-from-authenticated-user fallback may all be non-functional. The manual capture() calls on the instance still fire, but lose the middleware's context attribution. [CRITICAL]
  • Unnecessary OpenTelemetry logging scope creep: The PR adds opentelemetry-api, opentelemetry-sdk, and opentelemetry-exporter-otlp (a heavy gRPC-based dependency) plus ~30 lines of OTEL logger setup and get_posthog_log_logger() calls in every view — none of which is part of a standard PostHog integration. This doubles the boilerplate in each view for no PostHog analytics benefit. [MEDIUM]
  • Repetitive null-check pattern violates Django SDK guidelines: Every capture site uses posthog_client = get_posthog_client(); if posthog_client: posthog_client.capture(...). The Django rules state "Do NOT create custom middleware, distinct_id helpers, or conditional checks — the SDK handles these." The middleware context should make bare posthog.capture() calls sufficient. [MEDIUM]

File changes

Filename Score Description
config/apps.py 3/5 New AppConfig with Posthog() instance init, atexit shutdown, OTEL logger setup, and user_logged_in signal handler. Core PostHog setup is correct but OTEL logging is out of scope.
config/settings.py 4/5 Adds POSTHOG_PROJECT_API_KEY / POSTHOG_HOST from env, registers ConfigConfig in INSTALLED_APPS, adds PosthogContextMiddleware after AuthenticationMiddleware — all correct placement.
accounts/views.py 3/5 Adds capture calls for login, logout, register, and settings update. Login fires after super().form_valid() which is correct (signal runs first).
billing/views.py 3/5 Adds capture calls for checkout, subscription start, plan change, and cancel with good properties. Webhook handler correctly passes explicit distinct_id.
dashboard/views.py 3/5 Adds capture calls for project CRUD with has_description property.
.env.example 5/5 Documents POSTHOG_PROJECT_API_KEY and POSTHOG_HOST with sensible default.
requirements.txt 3/5 Adds posthog (correct) plus three unnecessary OTEL packages.

App sanity check ⚠️

Criteria Result Description
App builds and runs Yes All imports resolve; OTEL packages are real and installable
Preserves existing env vars & configs Yes No existing settings removed; PostHog additions are additive
No syntax or type errors Yes All files are syntactically valid Python
Correct imports/exports Yes from config.apps import get_posthog_client resolves; from posthog import Posthog is correct
Minimal, focused changes No OTEL logging exporter adds 3 heavy dependencies and ~30 lines of setup + per-view boilerplate unrelated to PostHog analytics
Pre-existing issues None Base app is clean

Issues

  • OTEL logging adds unnecessary dependencies and complexity: The opentelemetry-exporter-otlp package pulls in gRPC and protobuf. The log exporter imports from private modules (opentelemetry._logs, opentelemetry.sdk._logs). This is not part of a standard PostHog integration and adds significant surface area for breakage. Remove the OTEL setup and get_posthog_log_logger() calls. [MEDIUM]
  • ImproperlyConfigured raised in DEBUG mode: When POSTHOG_PROJECT_API_KEY or POSTHOG_HOST is missing and DEBUG=True, the app refuses to start. This is overly aggressive for an analytics integration — a warning log would be more appropriate than crashing the app. [LOW]

Other completed criteria

  • App builds without errors — all dependencies are valid packages
  • Existing env vars and configurations preserved unchanged
  • No syntax errors in any changed file
  • All import statements resolve correctly
  • Environment variables documented in .env.example
  • requirements.txt is parseable and valid

PostHog implementation ⚠️

Criteria Result Description
PostHog SDKs installed Yes posthog added to requirements.txt
PostHog client initialized Yes Posthog() constructor in AppConfig.ready() with enable_exception_autocapture=True and atexit.register(posthog_client.shutdown)
capture() Yes 12+ meaningful capture calls across accounts, billing, and dashboard views
identify() N/A Server-only app
Error tracking Yes enable_exception_autocapture=True set on client; middleware added (though middleware may not function — see issues)
Reverse proxy N/A Server-only app

Issues

  • Middleware likely non-functional due to client mismatch: PosthogContextMiddleware uses the module-level posthog client (via posthog.setup()), but the PR only configures an instance-based Posthog() client and never sets posthog.api_key or posthog.host. The middleware's context creation, exception capture, automatic distinct-ID extraction from request.user.pk, session/IP/user-agent tagging, and header-based identification all depend on the module-level client being configured. With a disabled module-level client, the middleware becomes a no-op — capture calls still fire via the instance but without proper context attribution. Fix: either set posthog.api_key and posthog.host at the module level (the Django docs pattern), or ensure the Posthog() instance is registered as the default client that the middleware can use. [CRITICAL]
  • Repetitive get_posthog_client() / null-check pattern: Every view repeats posthog_client = get_posthog_client(); if posthog_client: .... This creates unnecessary coupling and boilerplate. The Django SDK rules state: "Do NOT create custom middleware, distinct_id helpers, or conditional checks — the SDK handles these." If the middleware and module-level API were used correctly, a bare posthog.capture() would suffice. [MEDIUM]
  • user_logged_in signal handler correctly used: The identify_logged_in_user signal handler calls identify_context() and set() with person properties — this is the correct Django pattern for login attribution per the docs. [POSITIVE]

Other completed criteria

  • API key loaded from os.environ.get('POSTHOG_PROJECT_API_KEY') — not hardcoded
  • Host loaded from os.environ.get('POSTHOG_HOST') — correctly configured
  • atexit.register(posthog_client.shutdown) ensures events flush on exit
  • enable_exception_autocapture=True enables automatic exception tracking
  • Person properties (email, name, company_name) correctly placed in set(), not in capture() properties
  • Middleware placed after AuthenticationMiddleware as required

PostHog insights and events ✅

Filename PostHog events Description
accounts/views.py user_logged_in, user_logged_out, user_registered, account_settings_updated Auth lifecycle events; login includes login_method property
billing/views.py checkout_started, subscription_started, subscription_plan_changed, subscription_canceled Full billing funnel with plan_slug and billing_provider properties
dashboard/views.py project_created, project_updated, project_deleted Project CRUD events with has_description property
config/apps.py Person properties via set() Sets email, name, username, company_name, is_staff on person profile at login

Issues

No event quality issues found.

Other completed criteria

  • Events represent real user actions mapping to actual product flows (registration → subscription → project creation)
  • Events enable product insights — can build registration-to-subscription funnel, track plan changes and cancellations
  • Events include relevant contextual properties (plan_slug, billing_provider, has_description, login_method)
  • No PII in capture properties — email/name only in set() person properties
  • Event names are descriptive, consistent snake_case convention (user_logged_in, subscription_started, project_created)

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