Skip to content

Conversation

@shruthilayaj
Copy link
Member

No description provided.

@shruthilayaj shruthilayaj requested a review from a team as a code owner November 18, 2025 18:56
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 18, 2025
Comment on lines +93 to +99
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"
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

@shruthilayaj shruthilayaj enabled auto-merge (squash) November 18, 2025 19:03
@codecov
Copy link

codecov bot commented Nov 18, 2025

Codecov Report

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

Files with missing lines Patch % Lines
src/sentry/discover/compare_timeseries.py 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #103540      +/-   ##
===========================================
- Coverage   80.58%    80.58%   -0.01%     
===========================================
  Files        9261      9261              
  Lines      395411    395415       +4     
  Branches    25212     25212              
===========================================
+ Hits       318641    318642       +1     
- Misses      76340     76343       +3     
  Partials      430       430              

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?

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

@shruthilayaj shruthilayaj merged commit db8dc3d into master Nov 19, 2025
66 checks passed
@shruthilayaj shruthilayaj deleted the shruthi/chore/tag-extrapolation-modes branch November 19, 2025 15:35
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.

4 participants