Skip to content

Conversation

@daibhin
Copy link
Contributor

@daibhin daibhin commented Jul 16, 2025

Originally reported by @jamesbrewerdev in #286

Django has its own exception handler for views and middleware that catches and processes exceptions. We need to hook into that and capture the exception manually. There might be some followup work needed here to process stack traces correctly but given this is pretty critical I'll follow up with that if necessary

Verified by manually editing the package (hence the old version number) that the view exception is correctly captured (including the context tags for URL etc)
Screenshot 2025-07-16 at 20 46 40

@daibhin daibhin requested review from a team, hpouillot, oliverb123 and pauldambra July 16, 2025 19:48
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Summary

This PR fixes a critical issue where Django's exception handling middleware wasn't properly capturing exceptions from views and middleware. The core issue was that Django converts exceptions into responses rather than propagating them through the middleware stack, which meant PostHog's exception capture wasn't seeing these exceptions.

The fix adds a process_exception method to the PosthogContextMiddleware class that properly integrates with Django's exception handling flow. This ensures that exceptions are captured even when Django processes them into responses, maintaining all important context like URLs and user data.

Specific changes:

  • Added process_exception method to Django middleware
  • Version bump from 6.1.0 to 6.1.1
  • Updated CHANGELOG.md to document the fix

Confidence score: 4/5

  1. This PR makes a targeted fix for a specific, well-understood issue
  2. The implementation follows Django's standard middleware patterns and has been manually verified
  3. Files that need attention: The process_exception method in django.py should be reviewed to ensure it properly handles all edge cases

3 files reviewed, 2 comments
Edit PR Review Bot Settings | Greptile

@daibhin daibhin enabled auto-merge (squash) July 16, 2025 19:53
@daibhin daibhin merged commit da09639 into master Jul 16, 2025
14 checks passed
@daibhin daibhin deleted the dn-chore/capture-processed-exceptions branch July 16, 2025 19:54
@jamesbrewerdev
Copy link

I really appreciate the incredibly fast turnaround on this 😲 ❤️

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants