Skip to content

feat(code_review): Improve debuggability#106880

Merged
armenzg merged 9 commits intomasterfrom
11_21_debuggability
Jan 27, 2026
Merged

feat(code_review): Improve debuggability#106880
armenzg merged 9 commits intomasterfrom
11_21_debuggability

Conversation

@armenzg
Copy link
Member

@armenzg armenzg commented Jan 23, 2026

This is a follow-up to #106567 and fixes the issue we found when it was deployed (SENTRY-5H53). For this line: extra = extract_github_info(event, github_event=github_event.value) we had an AttributeError: 'str' object has no attribute 'value'.

Description

This PR adds the extract_github_info() function to extract GitHub metadata from webhook events for improved debugging and logging.

In the future, we should also add this ability to Seer's code review code path.

Changes

New Function: extract_github_info()

  • Extracts GitHub metadata from webhook event payloads
  • Returns a dictionary with:
    • github_owner: Repository owner/organization name
    • github_repo_name: Repository name
    • github_repo_full_name: Full repository name (owner/repo)
    • github_event_url: URL to the specific event (check_run, pull_request, or comment)

Integration

  • Updated handle_webhook_event() in handlers.py to use extract_github_info()
  • Extracted metadata is passed as extra parameter to event handlers
  • Updated check_run.py, issue_comment.py, and pull_request.py to accept extra parameter

Testing

  • Added comprehensive unit test suite with 14 test cases
  • Tests cover all event types (pull_request, check_run, issue_comment)
  • Tests verify URL precedence logic (comment > check_run > pull_request)
  • Tests use real GitHub webhook fixtures for better accuracy
  • Edge cases tested (missing data, empty events, etc.)

Fixtures

  • Updated GitHub fixtures to include complete repository metadata
  • Added missing repository.name and repository.owner.login fields

Fixes CW-299

@armenzg armenzg self-assigned this Jan 23, 2026
@linear
Copy link

linear bot commented Jan 23, 2026

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 23, 2026
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're adding some extra metadata which already exists in GitHub events but were never added to the fixtures.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The big improvement on this PR versus the previous one is that we add this module to the stronger typing list, thus, issues like SENTRY-5H53 should not happen.

**kwargs: Additional keyword arguments
"""
# The extracted important key values are used for debugging with logs
extra = extract_github_info(event, github_event=github_event.value)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We extract the key values as early as possible in the entry point handler and pass the values to all downstream logging.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey I'm pretty sure this is going to error again unless we move this down to line 56 after the GITHUB_ENTERPRISE check.

This is the same thing I encountered here with the sentry issue here.

The problem is that the type of github_event is wrong and is str in the case of the github enterprise class not enum. Maybe it's better if we fix the type in the github enterprise check here . Yeah either that or move these lines extracting extra to under the ghe check

repo=repo,
integration=integration,
org_code_review_settings=preflight.settings,
extra=extra,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing it to the downstream handlers.

*,
enqueued_at_str: str,
github_event: GithubWebhookType,
github_event: str,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the task gets scheduled, Celery JSON serializes the data and we lose the Enum type.

I'm investigating if there's any tool we could add to prevent issues like this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good to know, I can definitely see myself falling into that trap again

@armenzg
Copy link
Member Author

armenzg commented Jan 26, 2026

@sentry review

@armenzg armenzg marked this pull request as ready for review January 26, 2026 20:37
@armenzg armenzg requested review from a team as code owners January 26, 2026 20:37
organization_id=organization.id,
repo=repo,
pr_number=str(pr_number) if pr_number else None,
comment_id=str(comment_id),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be ideal if we could pass extra in here and also the callsite in pull_request.py and log a warning every time we do record_webhook_handler_error. Happy to address this in a followup PR after this gets merged 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @srest2021 I will let you handle since I'm unsure what you have in mind.

Copy link
Contributor

@suejung-sentry suejung-sentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes sense but just a warning to address this or I'm pretty sure it's gonna error again

*,
enqueued_at_str: str,
github_event: GithubWebhookType,
github_event: str,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good to know, I can definitely see myself falling into that trap again

**kwargs: Additional keyword arguments
"""
# The extracted important key values are used for debugging with logs
extra = extract_github_info(event, github_event=github_event.value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey I'm pretty sure this is going to error again unless we move this down to line 56 after the GITHUB_ENTERPRISE check.

This is the same thing I encountered here with the sentry issue here.

The problem is that the type of github_event is wrong and is str in the case of the github enterprise class not enum. Maybe it's better if we fix the type in the github enterprise check here . Yeah either that or move these lines extracting extra to under the ghe check

Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

return

# The extracted important key values are used for debugging with logs
extra = extract_github_info(event, github_event=github_event.value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling .value on string fails for GitHub Enterprise

High Severity

The call to github_event.value at this line assumes github_event is always a GithubWebhookType enum, but GitHub Enterprise webhook handlers pass github_event as a raw string (from request.headers.get("x-github-event")). While there's a GitHub Enterprise check at lines 51-52 that should return early, a reviewer explicitly raised concerns that this will still error. The original bug this PR fixes was exactly AttributeError: 'str' object has no attribute 'value' on this line.

Fix in Cursor Fix in Web

@armenzg armenzg merged commit db4d290 into master Jan 27, 2026
68 checks passed
@armenzg armenzg deleted the 11_21_debuggability branch January 27, 2026 14:12
priscilawebdev pushed a commit that referenced this pull request Feb 2, 2026
This is a follow-up to #106567 and fixes the issue we found when it was
deployed ([SENTRY-5H53](https://sentry.sentry.io/issues/7210274284/)).
For this line: `extra = extract_github_info(event,
github_event=github_event.value)` we had an `AttributeError: 'str'
object has no attribute 'value'`.

## Description

This PR adds the `extract_github_info()` function to extract GitHub
metadata from webhook events for improved debugging and logging.

In the future, we should also add this ability to Seer's code review
code path.

## Changes

### New Function: `extract_github_info()`
- Extracts GitHub metadata from webhook event payloads
- Returns a dictionary with:
  - `github_owner`: Repository owner/organization name
  - `github_repo_name`: Repository name
  - `github_repo_full_name`: Full repository name (owner/repo)
- `github_event_url`: URL to the specific event (check_run,
pull_request, or comment)

### Integration
- Updated `handle_webhook_event()` in `handlers.py` to use
`extract_github_info()`
- Extracted metadata is passed as `extra` parameter to event handlers
- Updated `check_run.py`, `issue_comment.py`, and `pull_request.py` to
accept `extra` parameter

### Testing
- Added comprehensive unit test suite with 14 test cases
- Tests cover all event types (pull_request, check_run, issue_comment)
- Tests verify URL precedence logic (comment > check_run > pull_request)
- Tests use real GitHub webhook fixtures for better accuracy
- Edge cases tested (missing data, empty events, etc.)

### Fixtures
- Updated GitHub fixtures to include complete repository metadata
- Added missing `repository.name` and `repository.owner.login` fields

Fixes [CW-299](https://linear.app/getsentry/issue/CW-299)
@github-actions github-actions bot locked and limited conversation to collaborators Feb 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants