Skip to content

Commit 5432f9e

Browse files
iamrajjoshishashjar
authored andcommitted
🔧 chore: add more logs to github sync assignee inbound (#102675)
1 parent 2af1ea8 commit 5432f9e

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/sentry/integrations/utils/sync.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,36 @@ def _handle_assign(
9292
users_by_id = {user.id: user for user in users}
9393
projects_by_user = Project.objects.get_by_users(users)
9494

95+
logger = logging.getLogger(f"sentry.integrations.{integration.provider}")
96+
9597
for group in affected_groups:
9698
if not should_sync_assignee_inbound(group.organization, integration.provider):
9799
continue
98100

99101
user_id = _get_user_id(projects_by_user, group)
100102
user = users_by_id.get(user_id) if user_id is not None else None
101103
if user:
104+
logger.info(
105+
"sync_group_assignee_inbound._handle_assign.assigning.group",
106+
extra={
107+
"group_id": group.id,
108+
"user_id": user.id,
109+
},
110+
)
102111
GroupAssignee.objects.assign(
103112
group,
104113
user,
105114
assignment_source=AssignmentSource.from_integration(integration),
106115
)
107116
groups_assigned.append(group)
117+
else:
118+
logger.info(
119+
"sync_group_assignee_inbound._handle_assign.user_not_found",
120+
extra={
121+
"group_id": group.id,
122+
"user_id": user_id,
123+
},
124+
)
108125

109126
return groups_assigned
110127

@@ -128,6 +145,7 @@ def sync_group_assignee_inbound_by_external_actor(
128145
"external_user_name": external_user_name,
129146
"issue_key": external_issue_key,
130147
"method": AssigneeInboundSyncMethod.EXTERNAL_ACTOR.value,
148+
"assign": assign,
131149
}
132150

133151
if not affected_groups:
@@ -147,11 +165,16 @@ def sync_group_assignee_inbound_by_external_actor(
147165
user_ids = [
148166
external_actor for external_actor in external_actors if external_actor is not None
149167
]
168+
log_context["user_ids"] = user_ids
169+
logger.info("sync_group_assignee_inbound_by_external_actor.user_ids", extra=log_context)
170+
150171
users = user_service.get_many_by_id(ids=user_ids)
151172

152173
groups_assigned = _handle_assign(affected_groups, integration, users)
153174

154175
if len(groups_assigned) != len(affected_groups):
176+
log_context["groups_assigned_count"] = len(groups_assigned)
177+
log_context["affected_groups_count"] = len(affected_groups)
155178
lifecycle.record_halt(
156179
ProjectManagementHaltReason.SYNC_INBOUND_ASSIGNEE_NOT_FOUND, extra=log_context
157180
)
@@ -183,6 +206,7 @@ def sync_group_assignee_inbound(
183206
"email": email,
184207
"issue_key": external_issue_key,
185208
"method": AssigneeInboundSyncMethod.EMAIL.value,
209+
"assign": assign,
186210
}
187211
if not affected_groups:
188212
logger.info("no-affected-groups", extra=log_context)

tests/sentry/integrations/utils/test_sync.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def test_assign_with_no_user_found(self, mock_record_halt: mock.MagicMock) -> No
183183
"email": "oopsnotfound@example.com",
184184
"issue_key": external_issue.key,
185185
"method": AssigneeInboundSyncMethod.EMAIL.value,
186+
"assign": True,
186187
},
187188
)
188189

@@ -469,6 +470,10 @@ def test_assign_with_no_external_actor_found(self, mock_record_halt: mock.MagicM
469470
"external_user_name": "unknownuser",
470471
"issue_key": external_issue.key,
471472
"method": AssigneeInboundSyncMethod.EXTERNAL_ACTOR.value,
473+
"assign": True,
474+
"user_ids": [],
475+
"groups_assigned_count": 0,
476+
"affected_groups_count": 1,
472477
},
473478
)
474479

@@ -510,6 +515,10 @@ def test_assign_with_user_not_in_project(self, mock_record_halt: mock.MagicMock)
510515
"external_user_name": "outsider",
511516
"issue_key": external_issue.key,
512517
"method": AssigneeInboundSyncMethod.EXTERNAL_ACTOR.value,
518+
"assign": True,
519+
"user_ids": [other_user.id],
520+
"groups_assigned_count": 0,
521+
"affected_groups_count": 1,
513522
},
514523
)
515524

0 commit comments

Comments
 (0)