Skip to content

Commit 0916bf8

Browse files
chore(jira): Add more logs/expose them better (#92359)
1 parent b9a0786 commit 0916bf8

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

src/sentry/integrations/jira/integration.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from sentry import features
1717
from sentry.eventstore.models import GroupEvent
18+
from sentry.exceptions import InvalidConfiguration
1819
from sentry.integrations.base import (
1920
FeatureDescription,
2021
IntegrationData,
@@ -1006,24 +1007,35 @@ def sync_assignee_outbound(
10061007
extra={
10071008
"integration_id": external_issue.integration_id,
10081009
"user_id": user.id,
1010+
"user_emails": user.emails,
10091011
"issue_key": external_issue.key,
1012+
"organization_id": external_issue.organization_id,
10101013
},
10111014
)
1012-
return
1015+
if not user.emails:
1016+
raise InvalidConfiguration(
1017+
{
1018+
"email": "User must have a verified email on Sentry to sync assignee in Jira",
1019+
"help": "https://sentry.io/settings/account/emails",
1020+
}
1021+
)
1022+
raise InvalidConfiguration({"email": "Unable to find the requested user"})
10131023
try:
10141024
id_field = client.user_id_field()
10151025
client.assign_issue(external_issue.key, jira_user and jira_user.get(id_field))
1016-
except (ApiUnauthorized, ApiError):
1026+
except ApiError as e:
10171027
# TODO(jess): do we want to email people about these types of failures?
10181028
logger.info(
10191029
"jira.failed-to-assign",
1030+
exc_info=e,
10201031
extra={
10211032
"organization_id": external_issue.organization_id,
10221033
"integration_id": external_issue.integration_id,
10231034
"user_id": user.id if user else None,
10241035
"issue_key": external_issue.key,
10251036
},
10261037
)
1038+
raise
10271039

10281040
def sync_status_outbound(
10291041
self, external_issue: ExternalIssue, is_resolved: bool, project_id: int

src/sentry/integrations/tasks/sync_assignee_outbound.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from sentry import analytics, features
44
from sentry.constants import ObjectStatus
5+
from sentry.exceptions import InvalidConfiguration
56
from sentry.integrations.errors import OrganizationIntegrationNotFound
67
from sentry.integrations.models.external_issue import ExternalIssue
78
from sentry.integrations.models.integration import Integration
@@ -12,7 +13,7 @@
1213
from sentry.integrations.services.assignment_source import AssignmentSource
1314
from sentry.integrations.services.integration import integration_service
1415
from sentry.models.organization import Organization
15-
from sentry.shared_integrations.exceptions import IntegrationError
16+
from sentry.shared_integrations.exceptions import ApiUnauthorized, IntegrationError
1617
from sentry.silo.base import SiloMode
1718
from sentry.tasks.base import instrumented_task, retry
1819
from sentry.taskworker.config import TaskworkerConfig
@@ -96,5 +97,5 @@ def sync_assignee_outbound(
9697
id=integration.id,
9798
organization_id=external_issue.organization_id,
9899
)
99-
except OrganizationIntegrationNotFound:
100-
lifecycle.record_halt("organization_integration_not_found")
100+
except (OrganizationIntegrationNotFound, ApiUnauthorized, InvalidConfiguration) as e:
101+
lifecycle.record_halt(halt_reason=e)

tests/sentry/integrations/jira/test_integration.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from fixtures.integrations.jira.stub_client import StubJiraApiClient
1111
from fixtures.integrations.stub_service import StubService
12+
from sentry.exceptions import InvalidConfiguration
1213
from sentry.integrations.jira.integration import JiraIntegrationProvider
1314
from sentry.integrations.jira.views import SALT
1415
from sentry.integrations.models.external_issue import ExternalIssue
@@ -824,7 +825,8 @@ def test_sync_assignee_outbound_no_email(self):
824825
"https://example.atlassian.net/rest/api/2/user/assignable/search",
825826
json=[{"accountId": "deadbeef123", "displayName": "Dead Beef"}],
826827
)
827-
installation.sync_assignee_outbound(external_issue, user)
828+
with pytest.raises(InvalidConfiguration):
829+
installation.sync_assignee_outbound(external_issue, user)
828830

829831
# No sync made as jira users don't have email addresses
830832
assert len(responses.calls) == 1

tests/sentry/integrations/tasks/test_sync_assignee_outbound.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
import pytest
44

5+
from sentry.integrations.errors import OrganizationIntegrationNotFound
56
from sentry.integrations.example import ExampleIntegration
67
from sentry.integrations.models import ExternalIssue, Integration
78
from sentry.integrations.models.organization_integration import OrganizationIntegration
89
from sentry.integrations.tasks import sync_assignee_outbound
910
from sentry.integrations.types import EventLifecycleOutcome
10-
from sentry.testutils.asserts import assert_success_metric
11+
from sentry.testutils.asserts import assert_halt_metric, assert_success_metric
1112
from sentry.testutils.cases import TestCase
1213
from sentry.testutils.silo import assume_test_silo_mode_of
1314
from sentry.users.services.user import RpcUser
@@ -151,4 +152,6 @@ def test_missing_organization_integration(self, mock_sync_assignee, mock_record_
151152
mock_sync_assignee.assert_not_called()
152153

153154
assert mock_record_event.call_count == 2
154-
assert_success_metric(mock_record_event)
155+
assert_halt_metric(
156+
mock_record_event, OrganizationIntegrationNotFound("missing org_integration")
157+
)

0 commit comments

Comments
 (0)