Skip to content

Commit

Permalink
Use Sentry DSN to obtain project ID (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
paolodamico authored Jan 5, 2022
1 parent a474fcf commit a97fe0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
16 changes: 11 additions & 5 deletions posthog/sentry/posthog_integration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from sentry_sdk._types import MYPY
from sentry_sdk.client import Client
from sentry_sdk.hub import Hub
from sentry_sdk.integrations import Integration
from sentry_sdk.scope import add_global_event_processor
from sentry_sdk.utils import Dsn

import posthog
from posthog.request import DEFAULT_HOST
Expand All @@ -17,7 +19,7 @@ class PostHogIntegration(Integration):
identifier = "posthog-python"
organization = None # The Sentry organization, used to send a direct link from PostHog to Sentry
project_id = None # The Sentry project id, used to send a direct link from PostHog to Sentry
prefix = "https://sentry.io/organizations/" # Url of a self-hosted sentry instance (default: https://sentry.io/organizations/)
prefix = "https://sentry.io/organizations/" # URL of a hosted sentry instance (default: https://sentry.io/organizations/)

@staticmethod
def setup_once():
Expand All @@ -37,10 +39,14 @@ def processor(event, hint):
"$sentry_exception": event["exception"],
}

if PostHogIntegration.organization and PostHogIntegration.project_id:
properties[
"$sentry_url"
] = f"{PostHogIntegration.prefix}{PostHogIntegration.organization}/issues/?project={PostHogIntegration.project_id}&query={event['event_id']}"
if PostHogIntegration.organization:
project_id = PostHogIntegration.project_id or (
not not Hub.current.client.dsn and Dsn(Hub.current.client.dsn).project_id
)
if project_id:
properties[
"$sentry_url"
] = f"{PostHogIntegration.prefix}{PostHogIntegration.organization}/issues/?project={project_id}&query={event['event_id']}"

posthog.capture(posthog_distinct_id, "$exception", properties)

Expand Down
1 change: 0 additions & 1 deletion sentry_django_example/sentry_django_example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
from posthog.sentry.posthog_integration import PostHogIntegration

PostHogIntegration.organization = "posthog" # TODO: your sentry organization
PostHogIntegration.project_id = "5624115" # TODO: your sentry projectID
# PostHogIntegration.prefix = # TODO: your self hosted Sentry url. (default: https://sentry.io/organizations/)

# Since Sentry doesn't allow Integrations configuration (see https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/__init__.py#L171-L183)
Expand Down

0 comments on commit a97fe0a

Please sign in to comment.