Skip to content

feat(occurrences): Add RPCBase boilerplate#104842

Merged
thetruecpaul merged 1 commit intomasterfrom
cpaul/eap/add-occurrences-rpc
Dec 15, 2025
Merged

feat(occurrences): Add RPCBase boilerplate#104842
thetruecpaul merged 1 commit intomasterfrom
cpaul/eap/add-occurrences-rpc

Conversation

@thetruecpaul
Copy link
Copy Markdown
Contributor

There's a lot of good work & validation in this framework. Let's pick it up and use it for our own ends.

This PR adds an implementation of RPCBase for use with Occurrence trace items.

@thetruecpaul thetruecpaul requested a review from a team December 12, 2025 05:30
@thetruecpaul thetruecpaul requested a review from a team as a code owner December 12, 2025 05:30
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 12, 2025
@thetruecpaul thetruecpaul force-pushed the cpaul/eap/add-occurrences-rpc branch from 5ba15f7 to 8ddd2e1 Compare December 12, 2025 05:39
Comment on lines +64 to +74
orderby: list[str] | None,
offset: int,
limit: int,
referrer: str,
config: SearchResolverConfig,
sampling_mode: SAMPLING_MODES | None = None,
equations: list[str] | None = None,
page_token: PageToken | None = None,
additional_queries: AdditionalQueries | None = None,
debug: bool = False,
) -> EAPResponse:

This comment was marked as outdated.

Copy link
Copy Markdown
Member

@shashjar shashjar left a comment

Choose a reason for hiding this comment

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

overall looks good, thanks. left some nits + request for tests


@classmethod
@sentry_sdk.trace
def run_table_query(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as bot comments - seems like we can put debug on the SnubaParams instead of a separate arg, and looks like additional_queries aren't passed through

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same for run_table_query_with_tags?

tags should be formatted appropriately - e.g. {tags[foo], tags[bar]}
"""

columns = OccurrencesRPC.DEFINITIONS.columns.copy()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: can use cls.DEFINITIONS here

logger = logging.getLogger("sentry.snuba.occurrences_rpc")


class OccurrencesRPC(rpc_dataset_common.RPCBase):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we add tests for this? I think we can extend the parametrized tests in tests/sentry/snuba/test_rpc_dataset_common.py. I also see there are tests for search resolution for the other datasets (e.g. tests/sentry/search/eap/test_spans.py) - not sure if we've implemented everything we need in order to add those tests for occurrences, but if so can we do that?

),
]
)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: Missing trace column definition in occurrence columns

OCCURRENCE_COLUMNS is missing the trace column definition that all other RPC implementations (Spans, OurLogs, ProfileFunctions) explicitly include. The base class RPCBase.get_table_rpc_request and get_timeseries_query call resolver.resolve_column("trace") to handle trace-based sampling optimizations. Without the explicit definition, the resolver falls back to creating a dynamic ResolvedAttribute with internal_name="trace" instead of the expected "sentry.trace_id". This causes trace-based queries to use the wrong internal column name, which would result in failed or incorrect query results against the Snuba backend.

Fix in Cursor Fix in Web

public_alias=tag_name,
internal_name=tag_name,
search_type="string",
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: Incorrect internal_name format for tag columns

In run_table_query_with_tags, the internal_name for tag columns is incorrectly set to tag_name (e.g., "tags[foo]") instead of just name (e.g., "foo"). When the SearchResolver dynamically resolves a tag like tags[foo], it extracts just "foo" as the internal_name using regex. This inconsistency means pre-registered tag columns would have a different internal_name format than dynamically resolved ones, causing the RPC AttributeKey.name to be set incorrectly and potentially causing queries to fail or return wrong results.

Fix in Cursor Fix in Web

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 15, 2025

Codecov Report

❌ Patch coverage is 81.25000% with 6 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/snuba/occurrences_rpc.py 75.00% 6 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #104842   +/-   ##
========================================
  Coverage   80.45%    80.46%           
========================================
  Files        9397      9399    +2     
  Lines      403608    403694   +86     
  Branches    25925     25925           
========================================
+ Hits       324730    324816   +86     
  Misses      78438     78438           
  Partials      440       440           

There's a lot of good work & validation in this framework. Let's pick it up and use it for our own ends.

This PR adds an implementation of RPCBase for use with Occurrence trace items.
@thetruecpaul thetruecpaul force-pushed the cpaul/eap/add-occurrences-rpc branch from 146af52 to e2f7b67 Compare December 15, 2025 20:55
@thetruecpaul thetruecpaul enabled auto-merge (squash) December 15, 2025 20:57
@thetruecpaul thetruecpaul merged commit ea763ed into master Dec 15, 2025
67 checks passed
@thetruecpaul thetruecpaul deleted the cpaul/eap/add-occurrences-rpc branch December 15, 2025 21:17
@github-actions github-actions bot locked and limited conversation to collaborators Dec 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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