Skip to content

feat(preprod): Add git metadata and artifact IDs as tags for size analysis issues#110854

Merged
mtopo27 merged 8 commits intomasterfrom
max/add-git-metadata-size-analysis-tags
Mar 17, 2026
Merged

feat(preprod): Add git metadata and artifact IDs as tags for size analysis issues#110854
mtopo27 merged 8 commits intomasterfrom
max/add-git-metadata-size-analysis-tags

Conversation

@mtopo27
Copy link
Contributor

@mtopo27 mtopo27 commented Mar 17, 2026

Summary

  • Extend _artifact_to_tags() to emit artifact_id, commit_sha, branch, repo, base_sha, base_branch, pr_number as tags on size analysis issue events
  • Add select_related("preprod_artifact__commit_comparison") to 4 queryset calls in the comparison task to avoid N+1 queries
  • Add tests for the new tags (with and without commit_comparison)

Test plan

  • pytest -svv --create-db tests/sentry/preprod/size_analysis/test_grouptype.py — all 23 tests pass
  • pre-commit run --files on all modified files passes

@mtopo27 mtopo27 requested a review from a team as a code owner March 17, 2026 14:49
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 17, 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 2 potential issues.

Autofix Details

Bugbot Autofix prepared fixes for both issues found in the latest run.

  • ✅ Fixed: Nullable head_ref used unconditionally as tag value
    • I guarded the branch tag assignment so head_ref is only added when non-null, preventing None values in the string tag map.
  • ✅ Fixed: Missing select_related for commit_comparison in manual task
    • I added select_related("preprod_artifact__commit_comparison") to both manual comparison metric querysets to avoid per-artifact lazy loads.

Create PR

Or push these changes by commenting:

@cursor push 067ecdfead
Preview (067ecdfead)
diff --git a/src/sentry/preprod/size_analysis/grouptype.py b/src/sentry/preprod/size_analysis/grouptype.py
--- a/src/sentry/preprod/size_analysis/grouptype.py
+++ b/src/sentry/preprod/size_analysis/grouptype.py
@@ -61,7 +61,8 @@
     commit_comparison = artifact.commit_comparison
     if commit_comparison is not None:
         tags["commit_sha"] = commit_comparison.head_sha
-        tags["branch"] = commit_comparison.head_ref
+        if commit_comparison.head_ref is not None:
+            tags["branch"] = commit_comparison.head_ref
         tags["repo"] = commit_comparison.head_repo_name
         if commit_comparison.base_sha:
             tags["base_sha"] = commit_comparison.base_sha

diff --git a/src/sentry/preprod/size_analysis/tasks.py b/src/sentry/preprod/size_analysis/tasks.py
--- a/src/sentry/preprod/size_analysis/tasks.py
+++ b/src/sentry/preprod/size_analysis/tasks.py
@@ -326,6 +326,7 @@
         )
         .select_related("preprod_artifact")
         .select_related("preprod_artifact__mobile_app_info")
+        .select_related("preprod_artifact__commit_comparison")
     )
     head_size_metrics = list(head_size_metrics_qs)
 
@@ -337,6 +338,7 @@
         )
         .select_related("preprod_artifact")
         .select_related("preprod_artifact__mobile_app_info")
+        .select_related("preprod_artifact__commit_comparison")
     )
     base_size_metrics = list(base_size_metrics_qs)

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

@github-actions
Copy link
Contributor

Backend Test Failures

Failures on 81a465e in this run:

tests/sentry/preprod/size_analysis/test_size_analysis_tasks.py::ArtifactToTagsTest::test_minimal_artifact_datalog
tests/sentry/preprod/size_analysis/test_size_analysis_tasks.py:272: in test_minimal_artifact_data
    assert tags == {"app_id": "com.example.app"}
E   AssertionError: assert {'app_id': 'c...act_id': '39'} == {'app_id': 'com.example.app'}
E     
E     Omitting 1 identical items, use -vv to show
E     Left contains 1 more item:
E     {'artifact_id': '39'}
E     
E     Full diff:
E       {
E           'app_id': 'com.example.app',
E     +     'artifact_id': '39',
E       }

@mtopo27 mtopo27 force-pushed the max/add-git-metadata-size-analysis-tags branch from 265a229 to 6e8a3ab Compare March 17, 2026 15:23
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.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@github-actions
Copy link
Contributor

Backend Test Failures

Failures on 50f543e in this run:

tests/sentry/preprod/size_analysis/test_size_analysis_tasks.py::ArtifactToTagsTest::test_minimal_artifact_datalog
tests/sentry/preprod/size_analysis/test_size_analysis_tasks.py:272: in test_minimal_artifact_data
    assert tags == {"app_id": "com.example.app"}
E   AssertionError: assert {'app_id': 'c...act_id': '39'} == {'app_id': 'com.example.app'}
E     
E     Omitting 1 identical items, use -vv to show
E     Left contains 1 more item:
E     {'artifact_id': '39'}
E     
E     Full diff:
E       {
E           'app_id': 'com.example.app',
E     +     'artifact_id': '39',
E       }



def _artifact_to_tags(artifact: PreprodArtifact) -> dict[str, str]:
def _artifact_to_tags(artifact: PreprodArtifact, *, include_git: bool = True) -> dict[str, str]:
Copy link
Contributor

Choose a reason for hiding this comment

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

this get's called twice, once for head and once for base build:

Image

You might want to add this below: https://github.com/getsentry/sentry/pull/110854/changes#diff-be91e49fb005a5e8d892931306474bc033bd1af21bb40c5a929f89562ea6742eR246

(so it appears at the root level)

Copy link
Contributor

Choose a reason for hiding this comment

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

oh I see it's controlled via the include_git boolean. I still would not put this here even if you want it nested under head. You could just directly add the tags below and name them head.foo

mtopo27 and others added 7 commits March 17, 2026 14:41
…lysis issues

Emit commit SHA, branch, repo, base SHA, base branch, PR number,
provider, and artifact ID as tags on size analysis issue events so
they are searchable and filterable in the issue detail page.

Also add select_related for commit_comparison in the size analysis
task queries to avoid N+1 queries when building tags.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rename commit_sha to sha so it renders cleanly as "sha" under the
head/base tag groups. Drop provider tag as unnecessary.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ual task

The manual_size_analysis_comparison task querysets were not updated
with the commit_comparison select_related, causing N+1 queries.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The head artifact's commit_comparison already contains the base SHA
and base branch, so emitting git tags for the base artifact is
redundant and potentially confusing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Git metadata describes the comparison context, not a specific artifact,
so it belongs at the root level rather than nested under head.*. This
produces a cleaner tag layout: head.*/base.* for artifact-level tags
and git.* for commit comparison metadata.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… git tags

Mypy cannot narrow Django model field types through truthiness checks.
Use walrus operator with `is not None` to properly narrow nullable
string fields from CommitComparison.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

@chromy chromy left a comment

Choose a reason for hiding this comment

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

lgtm

@mtopo27 mtopo27 merged commit 7dfea0b into master Mar 17, 2026
57 checks passed
@mtopo27 mtopo27 deleted the max/add-git-metadata-size-analysis-tags branch March 17, 2026 19:55
mtopo27 added a commit that referenced this pull request Mar 24, 2026
Make `head.artifact_id` and `base.artifact_id` tags clickable on the
issue detail page, linking to the preprod size build detail page
(`/preprod/size/{id}/`).

These tags were added in #110854 but rendered as plain text. This adds
them to the existing tag-key switch in `EventTagsTreeValue`, following
the same `Link` + `TagLinkText` pattern used by `transaction` and
`replayId` tags. Uses the existing `getSizeBuildPath` utility.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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.

2 participants