Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/sentry/discover/compare_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ def make_rpc_request(
query_parts, dropped_fields = translate_mep_to_eap(query_parts)

extrapolation_mode = None
extrapolation_mode_str = None
if dataset == Dataset.PerformanceMetrics.value:
extrapolation_mode = ExtrapolationMode.EXTRAPOLATION_MODE_SERVER_ONLY
extrapolation_mode_str = "serverOnly"
if dataset == Dataset.Transactions.value:
extrapolation_mode = ExtrapolationMode.EXTRAPOLATION_MODE_NONE
extrapolation_mode_str = "none"
Comment on lines +93 to +99
Copy link

Choose a reason for hiding this comment

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

Bug: The extrapolation_mode_str variable remains None for unhandled datasets, leading to missing Sentry tags and extrapolationMode=None in API calls.
Severity: CRITICAL | Confidence: 0.95

🔍 Detailed Analysis

The extrapolation_mode_str variable is initialized to None and only assigned string values for Dataset.PerformanceMetrics.value and Dataset.Transactions.value. When make_rpc_request() is called with other dataset values, extrapolation_mode_str remains None. This causes sentry_sdk.set_tag("extrapolation_mode", extrapolation_mode_str) to not set a tag, and the API URL will include extrapolationMode=None, which downstream APIs may misinterpret or not expect, leading to silent failures for alert rules using unsupported datasets.

💡 Suggested Fix

Add an else clause or elif to provide a default extrapolation_mode_str for unhandled datasets, or implement input validation to restrict dataset to supported types.

🤖 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/discover/compare_timeseries.py#L93-L99

Potential issue: The `extrapolation_mode_str` variable is initialized to `None` and only
assigned string values for `Dataset.PerformanceMetrics.value` and
`Dataset.Transactions.value`. When `make_rpc_request()` is called with other `dataset`
values, `extrapolation_mode_str` remains `None`. This causes
`sentry_sdk.set_tag("extrapolation_mode", extrapolation_mode_str)` to not set a tag, and
the API URL will include `extrapolationMode=None`, which downstream APIs may
misinterpret or not expect, leading to silent failures for alert rules using unsupported
datasets.

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

Reference_id: 2780202


results = Spans.run_timeseries_query(
params=snuba_params,
Expand All @@ -103,9 +106,11 @@ def make_rpc_request(
config=SearchResolverConfig(
extrapolation_mode=extrapolation_mode,
),
sampling_mode=None,
sampling_mode="NORMAL",
)

sentry_sdk.set_tag("extrapolation_mode", extrapolation_mode_str)
Copy link
Member

Choose a reason for hiding this comment

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

I call this query.sampling_mode here

Copy link
Member Author

Choose a reason for hiding this comment

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

@Zylphrex extrapolation mode isn't the same as sampling mode! extrapolation mode refers to what sampling factors we want to consider for extrapolation (new stuff added so we can migrate alerts)

Copy link
Member

Choose a reason for hiding this comment

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

ahh my bad, but also oh boy, another mode?


assert snuba_params.start is not None
assert snuba_params.end is not None

Expand All @@ -119,6 +124,7 @@ def make_rpc_request(
start=snuba_params.start.strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
end=snuba_params.end.strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
sampling="NORMAL",
extrapolationMode=extrapolation_mode_str,
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: Extrapolation mode string passed as None to URL

When dataset is neither PerformanceMetrics nor Transactions, extrapolation_mode_str remains None and gets passed to format_api_call. Python's urlencode converts None to the string "None", resulting in URLs like ...?extrapolationMode=None. This creates misleading debug URLs in Sentry extras. The parameter should either be omitted when None or use a meaningful default value.

Fix in Cursor Fix in Web

)
sentry_sdk.set_extra("eap_call", api_call)

Expand Down
Loading