Skip to content

fix(python): use the framework integrations for exception capture - #437

Merged
ablaszkiewicz merged 2 commits into
mainfrom
fix/python-framework-integrations
Oct 22, 2026
Merged

ablaszkiewicz merged 2 commits into
mainfrom
fix/python-framework-integrations

Conversation

@ablaszkiewicz

@ablaszkiewicz ablaszkiewicz commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Changes

The Python framework rules in commandments.yaml and the posthog-best-practices skill point agents at the posthog-python framework integrations and leave the setup details to the docs:

  • Django: pass the Posthog() client to PosthogContextMiddleware with POSTHOG_MW_CLIENT, as the Django docs show. Settings are not assigned at runtime.
  • Flask: register PosthogFlaskIntegration with one Posthog() client, as the Flask docs show. No @app.errorhandler(Exception) is added for capture.
  • FastAPI: add PosthogASGIMiddleware, as the Python docs show, with the client created where the app is built, not in the lifespan. No capture_exception() in an Exception catch-all handler.
  • Python: the Flask, ASGI, and DRF integrations require posthog>=7.69.0.

The stale rules that told agents to capture exceptions by hand, configure the global posthog.api_key, and that "no middleware ships" for Flask or FastAPI are removed.

Depends on the docs in PostHog/posthog#121769 and PostHog/posthog.com#21477.

Verification

Ran the wizard's error-tracking flow on the workbench fixtures with this branch on a local context-mill, serving the content of both docs PRs, then ran each instrumented app, raised an exception in a route, and checked the event in PostHog:

Fixture Wizard wiring Event in PostHog
no-posthog-django POSTHOG_MW_CLIENT = Posthog(...) in settings.py $exception_source = django.middleware, /boom
python-flask PosthogFlaskIntegration(app, client=posthog_client) in create_app(), posthog>=7.69.0 $exception_source = flask.got_request_exception, /boom
no-posthog-fastapi-uv app.add_middleware(PosthogASGIMiddleware, client=posthog_client) beside the existing Exception handler $exception_source = asgi.middleware, /reports/supplier-sync

Each route exception arrived once. Without the version rule, all three runs required only posthog>=7.59.0, the release-linking minimum. pnpm test passes.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci ai-observability
  • /wizard-ci basic-integration
  • /wizard-ci feature-flags
  • /wizard-ci mcp-analytics
  • /wizard-ci replay-vision
  • /wizard-ci revenue
  • /wizard-ci self-driving
  • /wizard-ci warehouse
  • /wizard-ci warehouse-seeded

Test an individual app:

  • /wizard-ci ai-observability/anthropic
  • /wizard-ci ai-observability/google-adk
  • /wizard-ci ai-observability/groq
Show more apps
  • /wizard-ci ai-observability/manual-capture
  • /wizard-ci ai-observability/openai
  • /wizard-ci ai-observability/openai-agents
  • /wizard-ci ai-observability/opentelemetry
  • /wizard-ci ai-observability/vercel-ai
  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/flutter
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci feature-flags/django
  • /wizard-ci feature-flags/next-js
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci replay-vision/javascript-node
  • /wizard-ci replay-vision/next-js
  • /wizard-ci replay-vision/react-vite
  • /wizard-ci revenue/stripe
  • /wizard-ci self-driving/astro
  • /wizard-ci self-driving/fastapi
  • /wizard-ci self-driving/nuxt
  • /wizard-ci self-driving/react-router
  • /wizard-ci self-driving/sveltekit
  • /wizard-ci warehouse/monorepo-env
  • /wizard-ci warehouse/multi-source-next
  • /wizard-ci warehouse/stripe-node
  • /wizard-ci warehouse/zero-source
  • /wizard-ci warehouse-seeded/next-stripe
  • /wizard-ci warehouse-seeded/next-stripe-declined

Test against a wizard branch:

  • /wizard-ci all wizard:my-branch

Add wizard:<branch> to any command above to pin the wizard branch. It defaults to main.

Results will be posted here when complete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ablaszkiewicz
ablaszkiewicz marked this pull request as ready for review October 22, 2026 11:36
@ablaszkiewicz
ablaszkiewicz requested a review from a team as a code owner October 22, 2026 11:36
@ablaszkiewicz
ablaszkiewicz merged commit e141fc6 into main Oct 22, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants