Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(error-tracking): preserve exception list order in derived properties (#63250)

Hugues Pouillot4f644fab8bac
diff --git a/rust/cymbal/src/types/mod.rs b/rust/cymbal/src/types/mod.rs
index f2d9d1e07ab8..704c6dbe7420 100644
--- a/rust/cymbal/src/types/mod.rs
+++ b/rust/cymbal/src/types/mod.rs
@@ -334,16 +334,18 @@ impl FingerprintedErrProps {
}
}
+// Deduplicates while preserving first-seen order, so derived properties
+// ($exception_types, $exception_values, ...) follow the $exception_list order.
fn unique_by<T, I, F, K>(items: I, key_extractor: F) -> Vec<K>
where
I: Iterator<Item = T>,
F: Fn(T) -> Option<K>,
K: Eq + Hash + Clone,
{
+ let mut seen = HashSet::new();
items
.filter_map(key_extractor)
- .collect::<HashSet<_>>()
- .into_iter()
+ .filter(|key| seen.insert(key.clone()))
.collect()
}
@@ -542,7 +544,7 @@ mod test {
use crate::{frames::RawFrame, types::Stacktrace};
- use super::RawErrProps;
+ use super::{Exception, ExceptionList, RawErrProps};
#[test]
fn it_deserialises_error_props() {
@@ -630,4 +632,31 @@ mod test {
"missing field `type` at line 5 column 13"
);
}
+
+ #[test]
+ fn unique_properties_preserve_exception_list_order() {
+ let make_exception = |t: &str, v: &str| Exception {
+ exception_id: None,
+ exception_type: t.to_string(),
+ exception_message: v.to_string(),
+ mechanism: None,
+ module: None,
+ thread_id: None,
+ stack: None,
+ };
+
+ let list: ExceptionList = vec![
+ make_exception("ZError", "z happened"),
+ make_exception("AError", "a happened"),
+ make_exception("ZError", "z happened"),
+ make_exception("MError", "m happened"),
+ ]
+ .into();
+
+ assert_eq!(list.get_unique_types(), vec!["ZError", "AError", "MError"]);
+ assert_eq!(
+ list.get_unique_messages(),
+ vec!["z happened", "a happened", "m happened"]
+ );
+ }
}
diff --git a/rust/cymbal/tests/remote_resolution_parity.rs b/rust/cymbal/tests/remote_resolution_parity.rs
index 6c893b2430b1..9b4f4dfe9b67 100644
--- a/rust/cymbal/tests/remote_resolution_parity.rs
+++ b/rust/cymbal/tests/remote_resolution_parity.rs
@@ -161,22 +161,9 @@ async fn local_and_remote_stages_produce_identical_exception_list_for_empty_stac
// Properties derived by PropertiesResolver should also match in both
// paths, since they're computed from the (parity-checked) exception_list.
- // `exception_types` / `exception_messages` come back through cymbal's
- // `unique_by` helper, which round-trips through a HashSet — order is
- // therefore implementation-defined per run, so we compare as sorted sets.
- fn sorted(input: Option<Vec<String>>) -> Vec<String> {
- let mut out = input.unwrap_or_default();
- out.sort();
- out
- }
- assert_eq!(
- sorted(local_out.exception_types),
- sorted(remote_out.exception_types)
- );
- assert_eq!(
- sorted(local_out.exception_messages),
- sorted(remote_out.exception_messages)
- );
+ // `unique_by` preserves exception_list order, so compare directly.
+ assert_eq!(local_out.exception_types, remote_out.exception_types);
+ assert_eq!(local_out.exception_messages, remote_out.exception_messages);
assert_eq!(local_out.exception_handled, remote_out.exception_handled);
}