Skip to content

chore: manual exception capture calls #31135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 14, 2025

Conversation

daibhin
Copy link
Contributor

@daibhin daibhin commented Apr 11, 2025

More generic exception capture

@daibhin daibhin requested review from zlwaterfield, a team, hpouillot and oliverb123 April 11, 2025 16:34
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.

PR Summary

This PR centralizes exception handling by replacing direct Sentry SDK calls with PostHog's own exception capture implementation.

  • Modified posthog/exceptions_capture.py to remove Sentry integration, focusing solely on PostHog's analytics exception capture with a new properties parameter
  • Changed import sources across multiple files from sentry_sdk.capture_exception to a custom implementation in posthog.exceptions
  • Renamed parameter extras to properties in all capture_exception calls in RBAC migration files
  • Potential issue with import path in rbac_feature_flag_migration.py which may need to be a relative import from a PostHog module
  • Standardized exception capturing approach across the codebase while maintaining the same error handling functionality

6 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile

posthog/email.py Outdated
@@ -11,7 +11,7 @@
from django.template.loader import get_template
from django.utils import timezone
from django.utils.module_loading import import_string
from sentry_sdk import capture_exception
from exceptions import capture_exception
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The import path from exceptions import capture_exception appears incorrect. Based on the context, this should likely be from posthog.exceptions_capture import capture_exception since 'exceptions' is not a standard Python module and the custom implementation is likely in the posthog package.

@@ -33,7 +33,7 @@
from rest_framework.decorators import action
from posthog.rbac.migrations.rbac_team_migration import rbac_team_access_control_migration
from posthog.rbac.migrations.rbac_feature_flag_migration import rbac_feature_flag_role_access_migration
from sentry_sdk import capture_exception
from exceptions import capture_exception
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The import should be from posthog.exceptions_capture import capture_exception based on the file structure shown in the context. The current import path may cause import errors.

@@ -5,7 +5,7 @@
from ee.models.rbac.role import Role
from django.db import transaction
import structlog
from sentry_sdk import capture_exception
from exceptions import capture_exception
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The import path 'exceptions' appears incorrect. Based on other files in the codebase, this should likely be 'posthog.exceptions_capture' or similar. An incorrect import path will cause the migration to fail when executed.

@@ -3,7 +3,7 @@
from ee.models.explicit_team_membership import ExplicitTeamMembership
import structlog
from posthog.models.organization import Organization, OrganizationMembership
from sentry_sdk import capture_exception
from exceptions import capture_exception
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Import should be from posthog.exceptions_capture instead of just exceptions. This will likely cause an ImportError since there's no top-level exceptions module.

Suggested change
from exceptions import capture_exception
from posthog.exceptions import capture_exception

Copy link
Contributor

@zlwaterfield zlwaterfield left a comment

Choose a reason for hiding this comment

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

big moves

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

Copy link
Contributor

github-actions bot commented Apr 11, 2025

Size Change: -203 kB (-1.51%)

Total Size: 13.2 MB

Filename Size Change
frontend/dist/toolbar.js 13.2 MB -203 kB (-1.51%)

compressed-size-action

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

from posthoganalytics import api_key, capture_exception as posthog_capture_exception
import structlog

logger = structlog.get_logger(__name__)

sentry_capture_exception(error, scope=sentry_scope, **sentry_scope_kwargs)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dmarticus I dug a little further and it looks like removing this line is what is causing the number of query assertions to fail under the hood. Don't exactly know why but it feels like a pretty safe change to make. Going to update the test and merge this

Copy link
Contributor

@hpouillot hpouillot left a comment

Choose a reason for hiding this comment

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

Should we replace frontend/src/layout/ErrorBoundary/ErrorBoundary.tsx and get rid of unused deps as well ?

@@ -120,9 +120,9 @@ export const Settings = ({
}

return (
<ErrorBoundary>
<PostHogErrorBoundary>
Copy link
Contributor

Choose a reason for hiding this comment

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

👌

@daibhin daibhin enabled auto-merge (squash) April 14, 2025 08:11
@daibhin daibhin merged commit b8b58d9 into master Apr 14, 2025
109 of 110 checks passed
@daibhin daibhin deleted the dn-chore/update-manual-exception-capture-calls branch April 14, 2025 08:38
lricoy pushed a commit that referenced this pull request Apr 14, 2025
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