Skip to content

Commit b82f755

Browse files
cleptricclaude
andauthored
fix(outcomes): Sort CLIENT_DISCARD_REASONS for binary_search (#7655)
Sort the `CLIENT_DISCARD_REASONS` array alphabetically so that `binary_search` works correctly. The list was not sorted, with `buffer_overflow` appearing at the end instead of its correct alphabetical position between `before_send` and `cache_overflow`. Since `binary_search` requires a sorted slice, it would fail to find `buffer_overflow` and incorrectly set the reason to `None`. Also adds a test to verify the list remains sorted, preventing future regressions when new reasons are added. Co-authored-by: Claude <[email protected]>
1 parent f1eb68e commit b82f755

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

rust_snuba/src/processors/outcomes.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const CLIENT_DISCARD_REASONS: &[&str] = &[
1717
"backpressure",
1818
// an event was dropped in the `before_send` lifecycle method
1919
"before_send",
20+
// an SDK internal buffer (eg. breadcrumbs buffer) overflowed
21+
"buffer_overflow",
2022
// a SDK internal cache (eg: offline event cache) overflowed
2123
"cache_overflow",
2224
// an event was dropped by an event processor; may also be used for ignored exceptions / errors
@@ -37,8 +39,6 @@ const CLIENT_DISCARD_REASONS: &[&str] = &[
3739
"sample_rate",
3840
// an event was dropped because of an error when sending it (eg: 400 response)
3941
"send_error",
40-
// an SDK internal buffer (eg. breadcrumbs buffer) overflowed
41-
"buffer_overflow",
4242
];
4343

4444
pub fn process_message(
@@ -126,4 +126,12 @@ mod tests {
126126

127127
assert_eq!(result.rows.into_encoded_rows(), expected);
128128
}
129+
130+
#[test]
131+
fn test_client_discard_reasons_sorted() {
132+
// CLIENT_DISCARD_REASONS must be sorted for binary_search to work correctly
133+
let mut sorted = CLIENT_DISCARD_REASONS.to_vec();
134+
sorted.sort();
135+
assert_eq!(CLIENT_DISCARD_REASONS, sorted.as_slice());
136+
}
129137
}

0 commit comments

Comments
 (0)