Skip to content

: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.

fix(vercel): report failed resource imports to error tracking (#106043)

Matt Brookerb8bab2acdbe9
diff --git a/ee/api/vercel/test/test_vercel_connect.py b/ee/api/vercel/test/test_vercel_connect.py
index 12dc5c6add29..330289fb1bb0 100644
--- a/ee/api/vercel/test/test_vercel_connect.py
+++ b/ee/api/vercel/test/test_vercel_connect.py
@@ -19,6 +19,7 @@ from ee.api.vercel.crypto import encrypt_payload
from ee.api.vercel.vercel_connect import (
CONNECT_NONCE_COOKIE_PREFIX,
CONNECT_SALT,
+ VercelImportError,
_browser_nonce_cookie_name,
_delete_orphaned_integration,
_load_connect_session,
@@ -752,11 +753,18 @@ class TestVercelConnectComplete(VercelConnectTestBase):
("without_status", OperationResult(success=False, error="Network error"), "Network error"),
]
)
+ @patch("ee.api.vercel.vercel_connect.capture_exception")
@patch("ee.vercel.integration.VercelIntegration")
@patch("ee.api.vercel.vercel_connect.VercelAPIClient")
def test_failed_import_rolls_back_and_returns_400(
- self, _name, import_result, expected_detail, mock_client_class, mock_vercel_integration
- ):
+ self,
+ _name: str,
+ import_result: OperationResult,
+ expected_detail: str,
+ mock_client_class: MagicMock,
+ mock_vercel_integration: MagicMock,
+ mock_capture: MagicMock,
+ ) -> None:
mock_client = MagicMock()
mock_client_class.return_value = mock_client
mock_client.import_resource.return_value = import_result
@@ -783,6 +791,12 @@ class TestVercelConnectComplete(VercelConnectTestBase):
kind=Integration.IntegrationKind.VERCEL,
).exists()
mock_vercel_integration.bulk_sync_feature_flags_to_vercel.assert_not_called()
+ mock_capture.assert_called_once()
+ exception, properties = mock_capture.call_args[0]
+ assert isinstance(exception, VercelImportError)
+ assert properties["status_code"] == import_result.status_code
+ assert properties["installation_id"] == CACHED_SESSION_DATA["installation_id"]
+ assert properties["resource_id"] == mock_client.import_resource.call_args.kwargs["resource_id"]
@override_settings(VERCEL_CLIENT_INTEGRATION_ID="client_id", VERCEL_CLIENT_INTEGRATION_SECRET="secret")
diff --git a/ee/api/vercel/vercel_connect.py b/ee/api/vercel/vercel_connect.py
index b85d69525b0a..1aebfdbdd838 100644
--- a/ee/api/vercel/vercel_connect.py
+++ b/ee/api/vercel/vercel_connect.py
@@ -28,6 +28,11 @@ from ee.vercel.client import APIError, VercelAPIClient
logger = structlog.get_logger(__name__)
+
+class VercelImportError(Exception):
+ pass
+
+
ALLOWED_REDIRECT_DOMAINS = {
"vercel.com",
"www.vercel.com",
@@ -398,19 +403,31 @@ class VercelConnectLinkViewSet(viewsets.GenericViewSet):
secrets=env_secrets,
)
if not import_result.success:
+ resource_id = str(production_resource.pk)
logger.error(
"Failed to import resource to Vercel",
error=import_result.error,
status_code=import_result.status_code,
error_detail=import_result.error_detail,
installation_id=installation_id,
- resource_id=str(production_resource.pk),
+ resource_id=resource_id,
integration="vercel",
)
with transaction.atomic():
org_integration.delete()
for resource in resources.values():
resource.delete()
+ capture_exception(
+ VercelImportError("Vercel did not accept the resource import"),
+ {
+ "status_code": import_result.status_code,
+ "error": import_result.error,
+ "error_detail": import_result.error_detail,
+ "installation_id": installation_id,
+ "resource_id": resource_id,
+ "organization_id": str(organization.id),
+ },
+ )
if import_result.status_code is not None:
raise exceptions.ValidationError(
f"Vercel rejected the link (HTTP {import_result.status_code}). Start the link again from Vercel."
diff --git a/ee/vercel/client.py b/ee/vercel/client.py
index f1a5680adda9..1a2d6f61d28c 100644
--- a/ee/vercel/client.py
+++ b/ee/vercel/client.py
@@ -122,7 +122,7 @@ class VercelAPIClient:
raise APIError("Request timed out", detail=str(e))
except HTTPError as e:
status_code = e.response.status_code if e.response is not None else None
- detail = e.response.text if e.response is not None else str(e)
+ detail = e.response.text[:500] if e.response is not None else str(e)
logger.exception("HTTP error", method=method, url=url, status_code=status_code, integration="vercel")
raise APIError("HTTP error", status_code=status_code, detail=detail)
except RequestException as e:
diff --git a/ee/vercel/test/test_vercel_client.py b/ee/vercel/test/test_vercel_client.py
index 7cc1c14c8a98..8b5243aef181 100644
--- a/ee/vercel/test/test_vercel_client.py
+++ b/ee/vercel/test/test_vercel_client.py
@@ -158,9 +158,24 @@ class TestVercelAPIClient:
assert result.error == "HTTP error"
assert result.status_code == 400
+ @pytest.mark.parametrize(
+ "body,expected_detail",
+ [
+ ("Forbidden", "Forbidden"),
+ ("a" * 500 + "b" * 100, "a" * 500),
+ ],
+ ids=["short_body", "long_body"],
+ )
@patch("ee.vercel.client.requests.Session.request")
- def test_http_error_status_code_survives_falsy_response(self, mock_request, client, test_ids):
- mock_request.return_value = self.real_response(403, "Forbidden")
+ def test_http_error_keeps_status_code_and_first_500_chars_of_body(
+ self,
+ mock_request: MagicMock,
+ client: VercelAPIClient,
+ test_ids: dict[str, str],
+ body: str,
+ expected_detail: str,
+ ) -> None:
+ mock_request.return_value = self.real_response(403, body)
result = client.update_resource_secrets(
test_ids["integration_config_id"], test_ids["resource_id"], [{"name": "A", "value": "b"}]
@@ -168,7 +183,7 @@ class TestVercelAPIClient:
assert not result.success
assert result.status_code == 403
- assert result.error_detail == "Forbidden"
+ assert result.error_detail == expected_detail
@patch("ee.vercel.client.requests.Session.request")
def test_check_installation_active_false_on_real_404(self, mock_request, client):