Skip to content

feat(preprod): Add size_analysis webhook resource and broadcasting#110196

Open
cameroncooke wants to merge 4 commits intomasterfrom
cam/preprod-size-analysis-webhooks-backend
Open

feat(preprod): Add size_analysis webhook resource and broadcasting#110196
cameroncooke wants to merge 4 commits intomasterfrom
cam/preprod-size-analysis-webhooks-backend

Conversation

@cameroncooke
Copy link

Summary

Adds webhook support for the size analysis product within Sentry's pre-production platform. When size analysis reaches a terminal state (success or error), subscribed Sentry Apps receive a size_analysis.completed webhook with a lean payload containing build ID, status, sizes, comparison data, git context, and app metadata. Consumers use the buildId to fetch full details via the public API.

Follows patterns established by the Seer webhook implementation (PR #96222) and reuses the existing broadcast_webhooks_for_organization infrastructure — no new webhook plumbing needed.

Changes

  • Registration: SizeAnalysisActionType(COMPLETED), SIZE_ANALYSIS resource type, event expansion, SIZE_ANALYSIS_COMPLETED metrics enum, size_analysis → project:read permission
  • Feature flag: organizations:preprod-size-analysis-webhooks (FLAGPOLE, not api_exposed)
  • Payload builder: New src/sentry/preprod/size_analysis/webhooks.py with build_webhook_payload() and send_size_analysis_webhook()
  • Broadcast calls at 4 terminal points:
    1. Standalone builds (no commit_comparison) — success with comparison: null
    2. After PR comparisons complete — success or error with comparison data
    3. Build config mismatch early return — success with comparison: null
    4. Analysis processing failure — error with errorCode/errorMessage
  • Tests: 20 tests covering all payload scenarios, feature flag gating, exception handling

Design doc

See src/sentry/preprod/size_analysis/WEBHOOK_DESIGN.md for full payload specification, examples, and rationale.

Known limitation

When a PR build (head) is uploaded before its base branch build exists, the webhook fires with comparison: null. If the base build arrives later and a comparison is created retroactively, the head artifact does not receive an updated webhook. This is acceptable for v1 because:

  • Most CI workflows upload the base (main branch) build before the PR build
  • Fixing requires either dual webhooks per build or deferred emission, adding complexity
  • Consumers can poll the API with the buildId if needed

Companion PRs

  • Frontend: Will follow in a separate PR (Sentry enforces non-atomic deploys for static/ and src/)
  • Docs: Will follow in sentry-docs repo

Test plan

  • All 20 new webhook tests pass (tests/sentry/preprod/size_analysis/test_webhooks.py)
  • Existing size analysis task tests still pass
  • Existing sentry_apps webhook tests still pass
  • Pre-commit hooks pass on all modified files
  • CI passes

Add webhook infrastructure for size analysis notifications:
- SizeAnalysisActionType with COMPLETED action
- SIZE_ANALYSIS resource type and event expansion
- SIZE_ANALYSIS_COMPLETED event type in metrics enum
- size_analysis -> project:read in required permissions
- organizations:preprod-size-analysis-webhooks feature flag
…t calls

- New webhooks.py module with payload builder and send_size_analysis_webhook helper
- Webhook fires at terminal states: standalone success, PR comparison
  success/failure, build config mismatch, and analysis failure
- Feature-flag gated behind organizations:preprod-size-analysis-webhooks
- Payload includes buildId, status, sizes, comparison data, git context, and app metadata
Tests cover:
- Payload construction for all scenarios: standalone success, PR comparison
  success/failure, analysis failure, error codes, NOT_RAN/PENDING/PROCESSING
- Feature flag gating
- Broadcast exception handling
- Platform/artifact type mapping
- App metadata and git context population
…ok payload

Order comparison records by date_added descending when building the
webhook payload, ensuring the most recent comparison is used when
multiple exist for the same head metric.
@cameroncooke cameroncooke requested review from a team as code owners March 9, 2026 11:51
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 9, 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.

send_size_analysis_webhook(artifact=artifact, organization_id=self.organization.id)

mock_broadcast.delay.assert_called_once()
call_kwargs = mock_broadcast.delay.call_kwargs
Copy link
Contributor

Choose a reason for hiding this comment

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

Dead store from accidentally committed debugging code in test

Low Severity

Line 357 assigns call_kwargs = mock_broadcast.delay.call_kwargs, which accesses a non-existent .call_kwargs attribute on a Mock (Mock silently returns a new Mock for any attribute). This value is immediately overwritten on line 359 with the correct .call_args. The comment on line 358 ("Use call_args since .delay is a mock") confirms this was a debugging artifact that wasn't cleaned up.

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