Skip to content

Commit f7e4cf5

Browse files
authored
GitHub App: track debug logs as info (#12352)
We are experiencing some delays sometimes, this should be useful to pinpoint the problem.
1 parent 37687dd commit f7e4cf5

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

readthedocs/oauth/tasks.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def handle(self):
281281
log.debug("Unsupported event")
282282
raise ValueError(f"Unsupported event: {self.event}")
283283

284-
log.debug("Handling event")
284+
log.info("Handling event")
285285
self.event_handlers[self.event]()
286286

287287
def _handle_installation_event(self):
@@ -743,12 +743,17 @@ def _get_or_create_installation(self, sync_repositories_on_create: bool = True):
743743

744744

745745
@app.task(queue="web")
746-
def handle_github_app_webhook(data: dict, event: str):
746+
def handle_github_app_webhook(data: dict, event: str, event_id: str = "unknown"):
747747
"""
748748
Handle GitHub App webhooks asynchronously.
749749
750750
:param data: The webhook payload data.
751751
:param event: The event type of the webhook.
752752
"""
753+
structlog.contextvars.bind_contextvars(
754+
event=event,
755+
event_id=event_id,
756+
)
757+
log.info("Handling GitHub App webhook")
753758
handler = GitHubAppWebhookHandler(data, event)
754759
handler.handle()

readthedocs/oauth/views.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,24 @@ def post(self, request):
3636
installation_id = request.data.get("installation", {}).get("id", "unknown")
3737
action = request.data.get("action", "unknown")
3838
event = self.request.headers.get(GITHUB_EVENT_HEADER)
39+
# Unique identifiers for the event, useful to keep track of the event for debugging.
40+
# https://docs.github.com/en/webhooks/webhook-events-and-payloads#delivery-headers.
41+
event_id = self.request.headers.get("X-GitHub-Delivery", "unknown")
3942
structlog.contextvars.bind_contextvars(
4043
installation_id=installation_id,
4144
action=action,
4245
event=event,
46+
event_id=event_id,
4347
)
4448
if event not in GitHubAppWebhookHandler(request.data, event).event_handlers:
45-
log.debug("Unsupported event")
49+
log.info("Unsupported event")
4650
raise ValidationError(f"Unsupported event: {event}")
4751

48-
log.debug("Handling event")
52+
log.info("Handling event")
4953
handle_github_app_webhook.delay(
5054
data=request.data,
5155
event=event,
56+
event_id=event_id,
5257
)
5358
return Response(status=200)
5459

0 commit comments

Comments
 (0)