feat(occurrences on eap): Implement run_stats_query in Occurrences EAP RPC class#112878
feat(occurrences on eap): Implement run_stats_query in Occurrences EAP RPC class#112878
run_stats_query in Occurrences EAP RPC class#112878Conversation
|
|
||
| @classmethod | ||
| @sentry_sdk.trace | ||
| def run_stats_query( |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
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.
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.


Precursor to #112889. First of two backend PRs to support attribute breakdowns for occurrences in Explore.
Occurrences.run_stats_query()for attribute distribution queries on occurrence trace items in EAP, following the same pattern asSpans.run_stats_query()occurrence_categoryfiltering (ERROR vs. ISSUE_PLATFORM)