Skip to content

Commit 8dd1ef6

Browse files
chore(prevent): Add temp logs for overwatch webhook forwarder (#102994)
Temporary logging to debug why webhooks are not getting forwarded to overwatch as expected
1 parent 1a34aff commit 8dd1ef6

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

src/sentry/middleware/integrations/parsers/github.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ def get_response(self) -> HttpResponseBase:
100100
if codecov_regions:
101101
self.try_forward_to_codecov(event=event)
102102

103+
logger.info(
104+
"overwatch.debug.forward_if_applicable.begin",
105+
extra={
106+
"headers_keys": list(self.request.headers.keys()),
107+
"integration_id": integration.id,
108+
},
109+
)
103110
# The overwatch forwarder implements its own region-based checks
104111
OverwatchGithubWebhookForwarder(integration=integration).forward_if_applicable(
105112
event=event, headers=self.request.headers

src/sentry/overwatch_webhooks/webhook_forwarder.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,23 @@ def _get_org_summaries_by_region_for_integration(
5353
org_integrations = OrganizationIntegration.objects.filter(
5454
integration=integration, status=ObjectStatus.ACTIVE
5555
)
56+
logger.info(
57+
"overwatch.debug.org_integrations.fetched",
58+
extra={
59+
"integration_id": integration.id,
60+
"org_integration_ids": [oi.organization_id for oi in org_integrations],
61+
"count": len(org_integrations),
62+
},
63+
)
5664
organization_ids = [org_integration.organization_id for org_integration in org_integrations]
5765
org_mappings = OrganizationMapping.objects.filter(organization_id__in=organization_ids)
66+
logger.info(
67+
"overwatch.debug.org_mappings.fetched",
68+
extra={
69+
"org_mapping_ids": [om.organization_id for om in org_mappings],
70+
"count": len(org_mappings),
71+
},
72+
)
5873
org_mappings_by_id = {
5974
org_mapping.organization_id: org_mapping for org_mapping in org_mappings
6075
}
@@ -71,37 +86,87 @@ def _get_org_summaries_by_region_for_integration(
7186
organization_mapping=org_mapping,
7287
)
7388
)
89+
logger.info(
90+
"overwatch.debug.organizations.grouped_by_region",
91+
extra={
92+
"region_name": region_name,
93+
"org_id": org_integration.organization_id,
94+
},
95+
)
96+
97+
logger.info(
98+
"overwatch.debug.org_contexts_by_region.final",
99+
extra={
100+
"regions": list(org_contexts_by_region.keys()),
101+
"counts_per_region": {k: len(v) for k, v in org_contexts_by_region.items()},
102+
},
103+
)
74104

75105
return org_contexts_by_region
76106

77107
def forward_if_applicable(self, event: Mapping[str, Any], headers: Mapping[str, str]):
108+
region_name = None
78109
try:
79110
enabled_regions = options.get("overwatch.enabled-regions")
111+
logger.info(
112+
"overwatch.debug.enabled_regions", extra={"enabled_regions": enabled_regions}
113+
)
80114
if not enabled_regions:
81115
# feature isn't enabled, no work to do
116+
logger.info("overwatch.debug.excluded.feature_not_enabled", extra={})
82117
return
83118

84119
orgs_by_region = self._get_org_summaries_by_region_for_integration(
85120
integration=self.integration
86121
)
122+
logger.info(
123+
"overwatch.debug.orgs_by_region",
124+
extra={
125+
"regions": list(orgs_by_region.keys()),
126+
"counts_per_region": {k: len(v) for k, v in orgs_by_region.items()},
127+
},
128+
)
87129

88130
if not orgs_by_region or not self.should_forward_to_overwatch(headers):
131+
logger.info(
132+
"overwatch.debug.skipped_forwarding",
133+
extra={
134+
"orgs_by_region_empty": not orgs_by_region,
135+
"event_in_forward_list": self.should_forward_to_overwatch(headers),
136+
},
137+
)
89138
return
90139

91140
# We can conditionally opt into forwarding on a per-region basis,
92141
# similar to codecov's current implementation.
93142
for region_name, org_summaries in orgs_by_region.items():
143+
logger.info(
144+
"overwatch.debug.check_region",
145+
extra={
146+
"region_name": region_name,
147+
"enabled": region_name in enabled_regions,
148+
"org_summaries_count": len(org_summaries),
149+
},
150+
)
94151
if region_name not in enabled_regions:
95152
continue
96153

97154
raw_app_id = headers.get(
98155
GITHUB_INSTALLATION_TARGET_ID_HEADER,
99156
) or headers.get(DJANGO_HTTP_GITHUB_INSTALLATION_TARGET_ID_HEADER)
157+
logger.info(
158+
"overwatch.debug.raw_app_id",
159+
extra={"region_name": region_name, "raw_app_id": raw_app_id},
160+
)
100161
app_id: int | None = None
101162
if raw_app_id is not None:
102163
try:
103164
app_id = int(raw_app_id)
104165
except (TypeError, ValueError):
166+
logger.info(
167+
"overwatch.debug.app_id_parse_error",
168+
extra={"region_name": region_name, "raw_app_id": raw_app_id},
169+
)
105170
app_id = None
106171

107172
webhook_detail = WebhookDetails(
@@ -112,17 +177,25 @@ def forward_if_applicable(self, event: Mapping[str, Any], headers: Mapping[str,
112177
region=region_name,
113178
app_id=app_id,
114179
)
180+
logger.info(
181+
"overwatch.debug.webhook_detail.created",
182+
extra={"region_name": region_name, "app_id": app_id},
183+
)
115184

116185
publisher = OverwatchWebhookPublisher(
117186
integration_provider=self.integration.provider,
118187
region=get_region_by_name(region_name),
119188
)
189+
logger.info("overwatch.debug.enqueue_webhook", extra={"region_name": region_name})
120190
publisher.enqueue_webhook(webhook_detail)
121191
metrics.incr(
122192
"overwatch.forward-webhooks.success",
123193
sample_rate=1.0,
124194
tags={"forward_region": region_name},
125195
)
196+
logger.info(
197+
"overwatch.debug.metrics_incr.success", extra={"region_name": region_name}
198+
)
126199
except Exception:
127200
metrics.incr(
128201
"overwatch.forward-webhooks.forward-error",

0 commit comments

Comments
 (0)