Skip to content

Conversation

@akshayutture-augment
Copy link

@akshayutture-augment akshayutture-augment commented Nov 14, 2025

Test 3


Replicated from ai-code-review-evaluation/sentry-cursor#3


Note

Adds error upsampling that transforms count() to upsampled_count for eligible error queries, integrates it into organization events stats with caching, and covers with tests.

  • API/Queries:
    • Integrate error upsampling into organization_events_stats by conditionally transforming query columns (count() -> upsampled_count() as count) for eligible error queries across top events and timeseries (RPC and non-RPC).
    • Minor validation copy fix: "topEvents needs to be at least 1".
  • Helper Module (sentry.api.helpers.error_upsampling):
    • Add eligibility check with short-lived cache, allowlist evaluation, dataset-aware gating, and cache invalidation.
    • Provide transform_query_columns_for_error_upsampling for column rewriting.
  • Discover Dataset:
    • Add upsampled_count() SnQL aggregate mapping to toInt64(sum(sample_weight)).
  • Tests:
    • New unit tests for helper behavior and dataset gating.
    • New endpoint tests validating upsampling with full/partial/no allowlist and transaction queries.
  • Test Utilities:
    • Factories: set sample_rate from contexts.error_sampling.client_sample_rate for stored events to support tests.
  • Config:
    • Mypy overrides updated to include new helper and tests.

Written by Cursor Bugbot for commit 6ad6fe3. Configure here.

yuvmen and others added 2 commits July 25, 2025 09:48
…(#94376)

Part of the Error Upsampling project:
https://www.notion.so/sentry/Tech-Spec-Error-Up-Sampling-1e58b10e4b5d80af855cf3b992f75894?source=copy_link

Events-stats API will now check if all projects in the query are
allowlisted for upsampling, and convert the count query to a sum over
`sample_weight` in Snuba, this is done by defining a new SnQL function
`upsampled_count()`.

I noticed there are also eps() and epm() functions in use in this
endpoint. I considered (and even worked on) also supporting
swapping eps() and epm() which for correctness should probably also not
count naively and use `sample_weight`, but this
caused some complications and since they are only in use by specific
dashboard widgets and not available in discover
I decided to defer changing them until we realize it is needed.
- Add 60-second cache for upsampling eligibility checks to improve performance
- Separate upsampling eligibility check from query transformation for better optimization
- Remove unnecessary null checks in upsampled_count() function per schema requirements
- Add cache invalidation utilities for configuration management

This improves performance during high-traffic periods by avoiding repeated
expensive allowlist lookups while maintaining data consistency.
@akshayutture-augment
Copy link
Author

cursor review

# This cached result ensures consistent behavior across query execution
should_upsample = is_errors_query_for_error_upsampled_projects(
snuba_params, organization, dataset, request
)
Copy link

Choose a reason for hiding this comment

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

Bug: Wrong Dataset Causes Upsampling Errors

The _get_event_stats function uses dataset from the outer closure instead of the scoped_dataset parameter when checking upsampling eligibility. This causes incorrect behavior when the dashboard widget split logic passes a different dataset (e.g., discover) than the original request dataset (e.g., metrics_enhanced_performance). The upsampling check will evaluate against the wrong dataset, potentially applying or skipping transformations incorrectly.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants