Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion src/sentry/quotas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ def to_object(self) -> Mapping[str, Any]:

# This mirrors the Retentions struct in relay
# https://github.com/getsentry/relay/blob/641e7f20cd/relay-dynamic-config/src/project.rs#L34-L45
RETENTIONS_CONFIG_MAPPING = {DataCategory.SPAN: "span", DataCategory.LOG_BYTE: "log"}
RETENTIONS_CONFIG_MAPPING = {
DataCategory.LOG_BYTE: "log",
DataCategory.TRANSACTION: "span",
DataCategory.SPAN: "span",
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: Duplicate Keys Cause Configuration Conflicts

The RETENTIONS_CONFIG_MAPPING maps DataCategory.TRANSACTION and DataCategory.SPAN to the same 'span' key. If both categories are present in retention data, dictionary comprehensions using this mapping will silently overwrite one value with the other. This results in unpredictable retention policies and potentially incorrect configuration sent to Relay.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A customer can have either DataCategory.TRANSACTION or DataCategory.SPAN, but not both.



def build_metric_abuse_quotas() -> list[AbuseQuota]:
Expand Down
25 changes: 25 additions & 0 deletions tests/sentry/api/endpoints/test_relay_projectconfigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,31 @@ def test_parse_retentions(call_endpoint, default_project):
}


@django_db_all
def test_parse_retentions_with_transactions(call_endpoint, default_project):
with patch("sentry.quotas.backend") as quotas_mock:
quotas_mock.get_retentions = lambda x: {
DataCategory.ERROR: RetentionSettings(standard=10, downsampled=20),
DataCategory.REPLAY: RetentionSettings(standard=11, downsampled=21),
DataCategory.TRANSACTION: RetentionSettings(standard=12, downsampled=22),
DataCategory.LOG_BYTE: RetentionSettings(standard=13, downsampled=23),
}
quotas_mock.get_event_retention = lambda x: 45
quotas_mock.get_downsampled_event_retention = lambda x: 90

result, status_code = call_endpoint()
assert status_code < 400
assert_no_snakecase_key(result)
cfg = safe.get_path(result, "configs", str(default_project.id))

assert safe.get_path(cfg, "config", "eventRetention") == 45
assert safe.get_path(cfg, "config", "downsampledEventRetention") == 90
assert safe.get_path(cfg, "config", "retentions") == {
"span": {"standard": 12, "downsampled": 22},
"log": {"standard": 13, "downsampled": 23},
}


@django_db_all
def test_relays_dyamic_sampling(call_endpoint, default_project) -> None:
"""
Expand Down
Loading