Skip to content

Conversation

@scttcper
Copy link
Member

Add support for including empty tag values in the group tags endpoint (api/0/issues/{id}/tags/) when the organizations:issue-tags-include-empty-values feature flag is enabled.

Makes a 2nd snuba query and attaches the empty values. I couldn't figure out how to make this work in a single snuba query, but i did figure out how to do this without N snuba queries.

also needs some follow up frontend work

image

part of https://linear.app/getsentry/issue/RTC-1181/

Add support for including empty tag values in the group tags endpoint
(api/0/issues/{id}/tags/) when the organizations:issue-tags-include-empty-values
feature flag is enabled.

Changes:
- Add include_empty_values parameter to get_group_tag_keys_and_top_values methods
- Add __get_empty_value_stats_map helper method to query empty tag stats
- Update group_tags endpoint to check feature flag and pass parameter
- Add feature flag organizations:issue-tags-include-empty-values
- Add tests for empty tag inclusion behavior
@scttcper scttcper requested review from a team as code owners October 23, 2025 22:06
@linear
Copy link

linear bot commented Oct 23, 2025

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 23, 2025
@scttcper scttcper requested a review from wedamija October 23, 2025 22:06

include_empty_values = features.has(
"organizations:issue-tags-include-empty-values",
organization=group.project.organization,
Copy link
Contributor

Choose a reason for hiding this comment

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

if we're doing this on group.project.org, would making this a project option be better?

Copy link
Member Author

Choose a reason for hiding this comment

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

i just need it behind a flag, org is usually the easier one to roll out

@codecov
Copy link

codecov bot commented Oct 23, 2025

Codecov Report

❌ Patch coverage is 97.29730% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/tagstore/snuba/backend.py 97.05% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #102049      +/-   ##
===========================================
+ Coverage   80.95%    80.97%   +0.02%     
===========================================
  Files        8797      8763      -34     
  Lines      389822    389456     -366     
  Branches    24800     24740      -60     
===========================================
- Hits       315588    315373     -215     
+ Misses      73860     73726     -134     
+ Partials      374       357      -17     

# Whether to allow issue only search on the issue list
manager.add("organizations:issue-search-allow-postgres-only-search", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=False)
# Include empty tag count in issue tag totals/values
manager.add("organizations:issue-tags-include-empty-values", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

you mentioned you'll need this in the frontend, will you want api_expose=True?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think in the frontend i can just handle empty strings and let the backend decide when to send them the value is "" which doesn't exist today.

Copy link
Contributor

@cvxluo cvxluo left a comment

Choose a reason for hiding this comment

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

i think this looks fine, and it makes sense to me, but i'd wait for an approval from someone more familiar with this endpoint

Comment on lines +742 to +744
if not stats or stats.get("count", 0) <= 0:
continue
vals = values_by_key.get(k, {})
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: from my understanding think these need to be .get(), since empty_stats_map is either {} (so the iteration won't run) or are guarenteed to have k (same with above for count)?

response = self.client.get(url, format="json")
assert response.status_code == 200
values = {v["value"] for v in response.data[0]["topValues"]}
assert values == {"", "bar"}
Copy link
Contributor

Choose a reason for hiding this comment

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

can we also check that the empty tag count is correct (so response.data[0]["topValues"]["count"] is 1 or whatever)

Copy link
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

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

I'm kind of confused about why we want to allow this, what's the value of a tag with no name?

If a customer wants some dummy value, they can just write a tag with DUMMY as the name. Tbh, I don't think we should do this, especially since it causes an extra query

Comment on lines +802 to +813
empty_results = snuba.query(
dataset=dataset,
start=start,
end=end,
groupby=None,
conditions=conditions,
filter_keys=empty_filters,
aggregations=[],
selected_columns=selected_columns_empty,
referrer="tagstore._get_tag_keys_and_top_values_empty_counts",
tenant_ids=tenant_ids,
)
Copy link
Member

Choose a reason for hiding this comment

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

Are we going to end up making an extra query for every org to fetch these empty keys?

Copy link
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

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

Ok, I read through the linear and I understand what we're trying to do here... I'm going to think a little on the query and see if we can avoid a second one


# Then supplement the key objects with the top values for each.
if include_empty_values:
keys_to_check = list(values_by_key.keys()) or [k.key for k in keys_with_counts]
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: Tag Key Logic Fails with Empty Values

The keys_to_check logic in get_group_tag_keys_and_top_values incorrectly determines which keys to check for empty values. The expression list(values_by_key.keys()) or [k.key for k in keys_with_counts] can omit tags that only have empty values, especially when other tags have non-empty values or when specific keys are requested. This leads to incomplete tag data.

Fix in Cursor Fix in Web

@scttcper scttcper merged commit 4b8374d into master Oct 29, 2025
67 of 68 checks passed
@scttcper scttcper deleted the scttcper/issue-tags-include-empty-values branch October 29, 2025 18:54
scttcper added a commit that referenced this pull request Oct 30, 2025
In #102049 added the empty tags, but noticing the total values no longer makes sense. Increases the total count when empty values is active
scttcper added a commit that referenced this pull request Oct 30, 2025
In #102049 added the empty tags, but noticing the total values no longer
makes sense. Increases the total count when empty values is active

part of https://linear.app/getsentry/issue/RTC-1181/
@sentry
Copy link

sentry bot commented Oct 31, 2025

Issues attributed to commits in this pull request

This pull request was merged and Sentry observed the following issues:

shashjar pushed a commit that referenced this pull request Nov 4, 2025
Add support for including empty tag values in the group tags endpoint
(api/0/issues/{id}/tags/) when the
organizations:issue-tags-include-empty-values feature flag is enabled.

Makes a 2nd snuba query and attaches the empty values. I couldn't figure
out how to make this work in a single snuba query, but i did figure out
how to do this without N snuba queries.

also needs some follow up frontend work

<img width="454" height="256" alt="image"
src="https://github.com/user-attachments/assets/6b935125-7ed5-4418-bcbb-f4bbc7349990"
/>

part of https://linear.app/getsentry/issue/RTC-1181/
shashjar pushed a commit that referenced this pull request Nov 4, 2025
In #102049 added the empty tags, but noticing the total values no longer
makes sense. Increases the total count when empty values is active

part of https://linear.app/getsentry/issue/RTC-1181/
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.

4 participants