Skip to content

Conversation

@chromy
Copy link
Contributor

@chromy chromy commented Jan 20, 2026

No description provided.

@chromy chromy requested a review from a team as a code owner January 20, 2026 15:54
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 20, 2026
cursor[bot]

This comment was marked as outdated.

Add routing logic for TRACE_ITEM_PREPROD event type to use the
PreprodSize dataset module in entity_subscription.py. Without this,
preprod alerts would incorrectly query the Spans dataset.
@chromy chromy changed the title feat(preprod): Add preprod to snuba feat(preprod): Add TRACE_ITEM_PREPROD support to snuba Jan 20, 2026
cursor[bot]

This comment was marked as outdated.

…ROD alerts

When TRACE_ITEM_PREPROD is selected for alerts, we need to use
PreprodSizeSearchResolverConfig instead of the default SearchResolverConfig.
This ensures the critical `sub_item_type="size_metric"` filter is applied,
so preprod alerts query only size metric data instead of all preprod data.
Comment on lines 347 to 357
extrapolation_mode=proto_extrapolation_mode,
stable_timestamp_quantization=False,
)
elif is_preprod:
search_config = PreprodSizeSearchResolverConfig(
stable_timestamp_quantization=False,
extrapolation_mode=proto_extrapolation_mode,
)
else:
search_config = SearchResolverConfig(
stable_timestamp_quantization=False,
Copy link

Choose a reason for hiding this comment

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

Bug: The chart generation logic in incidents/charts.py incorrectly sets the dataset to "spans" instead of "preprodSize" for the new TRACE_ITEM_PREPROD event type.
Severity: MEDIUM

Suggested Fix

In incidents/charts.py, add a condition to check for the TRACE_ITEM_PREPROD event type. When this event type is detected, explicitly set query_params["dataset"] to "preprodSize" to ensure the correct dataset is queried for chart data.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/sentry/snuba/entity_subscription.py#L347-L357

Potential issue: The introduction of the `TRACE_ITEM_PREPROD` event type is not fully
handled in the alert chart generation logic. In `incidents/charts.py`, when
`build_metric_alert_chart()` is called for a `TRACE_ITEM_PREPROD` alert, the code
defaults to setting the `dataset` query parameter to `"spans"`. However, this new event
type requires the dataset to be `"preprodSize"`. This mismatch will cause the
`/organizations/{slug}/events-stats/` API endpoint to query the wrong Snuba dataset,
resulting in incorrect or empty charts for preprod size alerts.

Did we get this right? 👍 / 👎 to inform future reviews.

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.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

SnubaQueryEventType.EventType.TRACE_ITEM_LOG,
SnubaQueryEventType.EventType.TRACE_ITEM_SPAN,
SnubaQueryEventType.EventType.TRACE_ITEM_METRIC,
SnubaQueryEventType.EventType.TRACE_ITEM_PREPROD,
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing aggregate validation for TRACE_ITEM_PREPROD causes runtime failures

Medium Severity

TRACE_ITEM_PREPROD is added as a valid event type, but unlike TRACE_ITEM_METRIC which has validate_trace_metrics_aggregate(), there's no validation ensuring the aggregate is supported by PreprodSize. The PREPROD_SIZE_AGGREGATE_DEFINITIONS only defines max and min functions. Users can create alerts with common aggregates like count() that pass validation but fail at runtime with "Unknown function" errors when SearchResolver.resolve_function() can't find the function in the limited preprod definitions.

Additional Locations (1)

Fix in Cursor Fix in Web

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