Skip to content

feat(code_review): Set context as tags#107714

Draft
armenzg wants to merge 1 commit intomasterfrom
seer/code-review-sentry-tags
Draft

feat(code_review): Set context as tags#107714
armenzg wants to merge 1 commit intomasterfrom
seer/code-review-sentry-tags

Conversation

@armenzg
Copy link
Member

@armenzg armenzg commented Feb 5, 2026

Summary

Applies the same context extraction and Sentry SDK tagging pattern used in the seer repository to Sentry's code_review webhook handlers.

Changes

  • utils.py: Added extract_webhook_context() to combine GitHub event info with Sentry-specific context (org, repo, integration, provider). Returns a dict suitable for sentry_sdk.set_tags().
  • handlers.py: Call extract_webhook_context() and sentry_sdk.set_tags(context) at webhook entry so all downstream logs, errors, and spans get the context automatically.
  • task.py: Extract context from the transformed payload and sentry_sdk.set_tags(context_tags) at the start of process_github_webhook_event() so the async task execution scope also has tags.

Pattern (from seer)

In seer's CodegenStep._invoke():

context = extract_context(self.context.request)
sentry_sdk.set_tags(context)

We now do the equivalent in both the webhook handler path and the Celery task path.

Benefits

  • Automatic tag propagation to Sentry errors, transactions, and spans
  • Better error grouping and debugging in Sentry UI
  • Consistent pattern between seer and Sentry code_review

Made with Cursor

- Add extract_webhook_context() in utils.py to combine GitHub event info
  with Sentry-specific context (org, repo, integration, provider)
- In handlers.py: call extract_webhook_context() and set tags via
  sentry_sdk.set_tags() so all downstream logs/errors/spans get context
- In task.py: extract context from transformed payload and set
  sentry_sdk.set_tags() at task start for async execution scope

Follows the same pattern used in seer's CodegenStep._invoke() for
automatic tag propagation to Sentry errors and traces.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 5, 2026
@armenzg armenzg changed the title Apply seer extract_context + set_tags pattern to code_review webhooks feat(code_review): Set context as tags Feb 5, 2026
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.

integration=integration,
github_event=github_event.value,
)
sentry_sdk.set_tags(context)
Copy link
Contributor

Choose a reason for hiding this comment

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

None values not filtered before setting Sentry tags

Low Severity

The context dict from extract_webhook_context() is passed directly to sentry_sdk.set_tags() without filtering None values. The extract_github_info() function returns a dict where most fields default to None, and extract_webhook_context() also sets sentry_integration_id to None when no integration is provided. In task.py, None values are explicitly filtered out with a comment stating "Filter out None values to avoid cluttering Sentry tags" - but this filtering is missing in handlers.py, causing inconsistent behavior.

Additional Locations (1)

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant