Skip to content

feat(occurrences on eap): Implement run_stats_query in Occurrences EAP RPC class#112878

Open
shashjar wants to merge 1 commit intomasterfrom
shashjar/implement-stats-query-occurrences-eap-rpc
Open

feat(occurrences on eap): Implement run_stats_query in Occurrences EAP RPC class#112878
shashjar wants to merge 1 commit intomasterfrom
shashjar/implement-stats-query-occurrences-eap-rpc

Conversation

@shashjar
Copy link
Copy Markdown
Member

@shashjar shashjar commented Apr 13, 2026

Precursor to #112889. First of two backend PRs to support attribute breakdowns for occurrences in Explore.

  • Implements Occurrences.run_stats_query() for attribute distribution queries on occurrence trace items in EAP, following the same pattern as Spans.run_stats_query()
  • Adds supporting infrastructure: occurrence attribute alias mappings, private attribute definitions, stats-excluded attributes
  • Supports optional occurrence_category filtering (ERROR vs. ISSUE_PLATFORM)


@classmethod
@sentry_sdk.trace
def run_stats_query(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note that arbitrary attributes on occurrence trace items are stored in EAP with columns constructed as f"attr[{key}]". This may require some transformation work down the line to make sure attributes get displayed nicely in the frontend.

attributes: list[AttributeKey] | None = None,
max_buckets: int = 75,
skip_translate_internal_to_public_alias: bool = False,
occurrence_category: OccurrenceCategory | None = None,
Copy link
Copy Markdown
Member Author

@shashjar shashjar Apr 14, 2026

Choose a reason for hiding this comment

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

Note that (like the other query functions in the Occurrences RPC class) run_stats_query accepts an optional occurrence_category argument to filter down to error occurrences or issue platform occurrences (queries both by default). We may want to take this into account for Errors on Explore, i.e. if we want to limit the queries to error occurrences only.

Question for Explore team: will Errors on Explore be truly errors-only, or do we want to include issue platform events there as well?

@shashjar shashjar requested review from a team April 14, 2026 00:04
@shashjar shashjar marked this pull request as ready for review April 14, 2026 00:05
@shashjar shashjar requested a review from a team as a code owner April 14, 2026 00:05
@shashjar shashjar removed the request for review from a team April 14, 2026 00:05
Copy link
Copy Markdown
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 prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Unused constant defined but never referenced anywhere
    • Added filtering logic in run_stats_query to use OCCURRENCE_STATS_EXCLUDED_ATTRIBUTES_PUBLIC_ALIAS, preventing system-level identifiers from appearing in stats results.

Create PR

Or push these changes by commenting:

@cursor push 91c2df869c
Preview (91c2df869c)
diff --git a/src/sentry/snuba/occurrences_rpc.py b/src/sentry/snuba/occurrences_rpc.py
--- a/src/sentry/snuba/occurrences_rpc.py
+++ b/src/sentry/snuba/occurrences_rpc.py
@@ -315,6 +315,9 @@
         response = snuba_rpc.trace_item_stats_rpc(stats_request)
         stats = []
 
+        from sentry.search.eap.occurrences.attributes import (
+            OCCURRENCE_STATS_EXCLUDED_ATTRIBUTES_PUBLIC_ALIAS,
+        )
         from sentry.search.eap.utils import can_expose_attribute, translate_internal_to_public_alias
 
         for result in response.results:
@@ -340,6 +343,8 @@
                                 SupportedTraceItemType.OCCURRENCES,
                             )
                             public_alias = public_alias or attribute.attribute_name
+                            if public_alias in OCCURRENCE_STATS_EXCLUDED_ATTRIBUTES_PUBLIC_ALIAS:
+                                continue
                             attrs[public_alias].append(
                                 {"label": bucket.label, "value": bucket.value}
                             )

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

Reviewed by Cursor Bugbot for commit d133699. Configure here.

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