:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(error-tracking): always link the posthog issue in github and gitlab issue bodies (#127428)
posthog[bot]07507c09ac6a
diff --git a/products/error_tracking/backend/logic/external_references.py b/products/error_tracking/backend/logic/external_references.pyindex 9ea68172ccbf..d00b79fb6ca0 100644--- a/products/error_tracking/backend/logic/external_references.py+++ b/products/error_tracking/backend/logic/external_references.py@@ -223,6 +223,14 @@ def _get_issue_and_integration(return issue, _get_integration(team_id, integration_id)+def _with_issue_permalink(body: str, permalink: str) -> str:+ # The body is free text the user can clear, so the back-link is enforced here to keep every created issue traceable.+ if permalink in body:+ return body+ link = f"**PostHog issue:** {permalink}"+ return f"{body.rstrip()}\n\n{link}" if body.strip() else link++def create_external_reference(*,team_id: int,@@ -285,6 +293,10 @@ def create_external_reference(if assignee:provider_config["assignee"] = assignee+ if integration.kind in {IntegrationKind.GITHUB, IntegrationKind.GITLAB}:+ permalink = get_issue_permalink_by_fingerprint(team_id=team_id, issue_id=issue.id)+ provider_config["body"] = _with_issue_permalink(provider_config["body"], permalink)+if integration.kind == IntegrationKind.GITHUB:created_context = GitHubIntegration(integration, source="error_tracking", priority=Priority.CRITICALdiff --git a/products/error_tracking/backend/test/test_facade_api.py b/products/error_tracking/backend/test/test_facade_api.pyindex 757b9ae9a5ef..0db02eb0f41e 100644--- a/products/error_tracking/backend/test/test_facade_api.py+++ b/products/error_tracking/backend/test/test_facade_api.py@@ -446,6 +446,56 @@ class TestErrorTrackingFacadeAPI(BaseTest):mock_is_assignable.assert_called_once_with("posthog", login)assert mock_create_issue.called is creates_issue+ @parameterized.expand(+ [+ ("github_empty_body", "github", "", "{link}"),+ ("github_whitespace_body", "github", " \n ", "{link}"),+ ("github_user_text", "github", "Seen at checkout\n", "Seen at checkout\n\n{link}"),+ ("github_already_linked", "github", "Details: {url}", "Details: {url}"),+ ("gitlab_empty_body", "gitlab", "", "{link}"),+ ]+ )+ @override_settings(SITE_URL="https://app.example.com")+ @patch("products.error_tracking.backend.logic.external_references.GitLabIntegration.create_issue")+ @patch("products.error_tracking.backend.logic.external_references.GitHubIntegration.create_issue")+ def test_create_external_reference_always_links_back_to_posthog_issue(+ self, _name, kind, body, expected_body, mock_github_create_issue, mock_gitlab_create_issue+ ):+ mock_github_create_issue.return_value = {"number": 7, "repository": "posthog"}+ mock_gitlab_create_issue.return_value = {"issue_id": 7}+ issue = self._create_issue(team=self.team, name="Checkout TypeError")+ url = f"https://app.example.com/project/{self.team.id}/error-tracking/fingerprint/fp-{issue.id}"+ if kind == "github":+ integration = Integration.objects.create(+ team=self.team,+ kind=Integration.IntegrationKind.GITHUB.value,+ config={"account": {"name": "acme"}},+ sensitive_config={"access_token": "access-token"},+ )+ config = {"repository": "posthog", "title": "Checkout TypeError", "body": body.format(url=url)}+ mock_create_issue = mock_github_create_issue+ else:+ integration = Integration.objects.create(+ team=self.team,+ kind=Integration.IntegrationKind.GITLAB.value,+ config={"hostname": "https://gitlab.example.com", "project_id": 1},+ sensitive_config={"access_token": "access-token"},+ )+ config = {"title": "Checkout TypeError", "body": body.format(url=url)}+ mock_create_issue = mock_gitlab_create_issue++ api.create_external_reference(+ team_id=self.team.id,+ issue_id=issue.id,+ integration_id=integration.id,+ config=config,+ distinct_id=self.user.id,+ )++ assert mock_create_issue.call_args.args[0]["body"] == expected_body.format(+ url=url, link=f"**PostHog issue:** {url}"+ )+def test_search_external_issues_requires_repository_for_github(self):integration = Integration.objects.create(team=self.team,