feat(dynamic-sampling): per-org transaction rebalancing#116475
feat(dynamic-sampling): per-org transaction rebalancing#116475constantinius wants to merge 8 commits into
Conversation
| compare_rebalanced_projects_with_cache(config, rebalanced_projects, cached_sample_rates) | ||
|
|
||
| if not get_eap_transaction_volumes(config): | ||
| transaction_volumes = get_eap_transaction_volumes(config) |
| ) -> dict[int, tuple[list[RebalancedItem], float]]: | ||
| intensity = options.get("dynamic-sampling.prioritise_transactions.rebalance_intensity") | ||
| sample_rates = _project_sample_rates(config) | ||
| return { |
There was a problem hiding this comment.
Are we not clamping the sample rates yet? If no, should we record information about it?
Co-authored-by: Simon Hellmayr <shellmayr@users.noreply.github.com>
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit c30e3ed. Configure here.
…anced projects ones
| TransactionsRebalancingInput( | ||
| classes=[ | ||
| RebalancedItem(id=transaction_name, count=count) | ||
| for transaction_name, count in project_data["transaction_counts"] | ||
| ], | ||
| sample_rate=sample_rate, | ||
| total_num_classes=project_data.get("total_num_classes"), | ||
| total=project_data.get("total_num_transactions"), | ||
| intensity=intensity, | ||
| ) | ||
| ) |
There was a problem hiding this comment.
Bug: The call to TransactionsRebalancingModel().run() lacks error handling. An empty transaction_counts list will raise an unhandled InvalidModelInputError, crashing the background task.
Severity: MEDIUM
Suggested Fix
Before calling the model, add a guard to check if transaction_counts is empty and return early if it is. This mimics the safe handling present in the legacy code. Alternatively, wrap the call to TransactionsRebalancingModel().run() in a try...except InvalidModelInputError block to handle the validation failure gracefully without crashing the task.
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/dynamic_sampling/per_org/calculations.py#L131-L142
Potential issue: In `run_transaction_balancing`, the call to
`TransactionsRebalancingModel().run()` is not wrapped in any error handling. The model's
`run` method will raise an `InvalidModelInputError` if its input validation fails, which
occurs if the `transaction_counts` list is empty. This is a realistic edge case for
projects that have no transactions passing the volume filter. The unhandled exception
propagates up, causing the `run_calculations_per_org_task` to fail and preventing
dynamic sampling calculations from completing for that organization.

Closes TET-2403