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.

feat(cymbal): add rust error tracking frame type (#62200)

Catalin Irimie6039b6841833
diff --git a/rust/cymbal/src/frames/mod.rs b/rust/cymbal/src/frames/mod.rs
index 3a3932a14d7d..596562f83fb0 100644
--- a/rust/cymbal/src/frames/mod.rs
+++ b/rust/cymbal/src/frames/mod.rs
@@ -20,6 +20,7 @@ use crate::{
php::RawPHPFrame,
python::RawPythonFrame,
ruby::RawRubyFrame,
+ rust::RawRustFrame,
},
metric_consts::{FRAME_NOT_RESOLVED, FRAME_RESOLVED, LEGACY_JS_FRAME_RESOLVED, PER_FRAME_TIME},
sanitize_source_line,
@@ -74,6 +75,8 @@ pub enum RawFrame {
Dart(RawDartFrame),
#[serde(rename = "apple")]
Apple(RawAppleFrame),
+ #[serde(rename = "rust")]
+ Rust(RawRustFrame),
#[serde(rename = "custom")]
Custom(CustomFrame),
// TODO - remove once we're happy no clients are using this anymore
@@ -109,6 +112,7 @@ impl RawFrame {
RawFrame::Php(frame) => (to_vec(Ok(frame.into())), "php"),
RawFrame::Python(frame) => (to_vec(Ok(frame.into())), "python"),
RawFrame::Ruby(frame) => (to_vec(Ok(frame.into())), "ruby"),
+ RawFrame::Rust(frame) => (to_vec(Ok(frame.into())), "rust"),
RawFrame::Custom(frame) => (to_vec(Ok(frame.into())), "custom"),
RawFrame::Go(frame) => (to_vec(Ok(frame.into())), "go"),
RawFrame::Hermes(frame) => (to_vec(frame.resolve(team_id, catalog).await), "hermes"),
@@ -161,6 +165,7 @@ impl RawFrame {
| RawFrame::Go(_)
| RawFrame::Dart(_)
| RawFrame::Apple(_)
+ | RawFrame::Rust(_)
| RawFrame::Custom(_) => None,
}
}
@@ -173,6 +178,7 @@ impl RawFrame {
RawFrame::Python(raw) => raw.frame_id(),
RawFrame::Ruby(raw) => raw.frame_id(),
RawFrame::Go(raw) => raw.frame_id(),
+ RawFrame::Rust(raw) => raw.frame_id(),
RawFrame::Custom(raw) => raw.frame_id(),
RawFrame::Hermes(raw) => raw.frame_id(),
RawFrame::Java(raw) => raw.frame_id(),
@@ -445,7 +451,7 @@ fn to_vec<T, E>(item: Result<T, E>) -> Result<Vec<T>, E> {
#[cfg(test)]
mod test {
- use crate::frames::RawFrame;
+ use crate::frames::{Frame, RawFrame};
#[test]
fn ensure_custom_frames_work() {
@@ -468,4 +474,60 @@ mod test {
_ => panic!("Expected a custom frame"),
}
}
+
+ #[test]
+ fn ensure_rust_frames_work() {
+ let data = r#"
+ {
+ "function": "checkout::payment::charge",
+ "module": "checkout::payment",
+ "filename": "src/main.rs",
+ "resolved": true,
+ "in_app": true,
+ "lineno": 42,
+ "platform": "rust"
+ }
+ "#;
+
+ let frame: RawFrame = serde_json::from_str(data).unwrap();
+ match frame {
+ RawFrame::Rust(frame) => {
+ let resolved: Frame = (&frame).into();
+ let resolved_frame_id = frame.frame_id();
+ assert_eq!(resolved.lang, "rust");
+ assert_eq!(resolved.mangled_name, "checkout::payment::charge");
+ assert_eq!(
+ resolved.resolved_name.as_deref(),
+ Some("checkout::payment::charge")
+ );
+ assert_eq!(resolved.source.as_deref(), Some("src/main.rs"));
+ assert_eq!(resolved.module.as_deref(), Some("checkout::payment"));
+ assert_eq!(resolved.line, Some(42));
+ assert_eq!(resolved.context, None);
+
+ let unresolved_data = data.replace("\"resolved\": true,", "\"resolved\": false,");
+ let unresolved_frame: RawFrame = serde_json::from_str(&unresolved_data).unwrap();
+ match unresolved_frame {
+ RawFrame::Rust(frame) => assert_eq!(frame.frame_id(), resolved_frame_id),
+ _ => panic!("Expected a rust frame"),
+ }
+
+ let missing_function_data =
+ data.replace("\"function\": \"checkout::payment::charge\",\n", "");
+ let missing_function_frame: RawFrame =
+ serde_json::from_str(&missing_function_data).unwrap();
+ match missing_function_frame {
+ RawFrame::Rust(frame) => {
+ let resolved: Frame = (&frame).into();
+ assert_eq!(resolved.mangled_name, "");
+ assert_eq!(resolved.resolved_name, None);
+ assert_eq!(resolved.source.as_deref(), Some("src/main.rs"));
+ assert_eq!(resolved.line, Some(42));
+ }
+ _ => panic!("Expected a rust frame"),
+ }
+ }
+ _ => panic!("Expected a rust frame"),
+ }
+ }
}
diff --git a/rust/cymbal/src/langs/mod.rs b/rust/cymbal/src/langs/mod.rs
index 887f36f7bf96..4d4e1fe59619 100644
--- a/rust/cymbal/src/langs/mod.rs
+++ b/rust/cymbal/src/langs/mod.rs
@@ -11,6 +11,7 @@ pub mod node;
pub mod php;
pub mod python;
pub mod ruby;
+pub mod rust;
pub mod utils;
// Some metadata is common across all languages, so we define it here. In some
diff --git a/rust/cymbal/src/langs/rust.rs b/rust/cymbal/src/langs/rust.rs
new file mode 100644
index 000000000000..3cee3d5a3cfe
--- /dev/null
+++ b/rust/cymbal/src/langs/rust.rs
@@ -0,0 +1,63 @@
+use common_types::error_tracking::FrameId;
+use serde::{Deserialize, Serialize};
+use sha2::{Digest, Sha512};
+
+use crate::{frames::Frame, langs::CommonFrameMetadata};
+
+#[derive(Debug, Clone, Deserialize, Serialize)]
+pub struct RawRustFrame {
+ pub function: Option<String>,
+ pub filename: Option<String>,
+ pub lineno: Option<u32>,
+ pub colno: Option<u32>,
+ pub module: Option<String>,
+ #[serde(default)]
+ pub resolved: bool,
+ #[serde(flatten)]
+ meta: CommonFrameMetadata,
+}
+
+impl RawRustFrame {
+ pub fn frame_id(&self) -> String {
+ let mut hasher = Sha512::new();
+
+ self.filename
+ .as_ref()
+ .inspect(|f| hasher.update(f.as_bytes()));
+ hasher.update(self.function.as_deref().unwrap_or_default().as_bytes());
+ hasher.update(self.lineno.unwrap_or_default().to_be_bytes());
+ hasher.update(self.colno.unwrap_or_default().to_be_bytes());
+ hasher.update(b"rust");
+ self.module
+ .as_ref()
+ .inspect(|m| hasher.update(m.as_bytes()));
+ format!("{:x}", hasher.finalize())
+ }
+}
+
+impl From<&RawRustFrame> for Frame {
+ fn from(value: &RawRustFrame) -> Self {
+ let function = value.function.clone().unwrap_or_default();
+
+ Frame {
+ frame_id: FrameId::placeholder(),
+ mangled_name: function,
+ line: value.lineno,
+ column: value.colno,
+ source: value.filename.clone(),
+ in_app: value.meta.in_app,
+ resolved_name: value.function.clone(),
+ lang: "rust".to_string(),
+ resolved: value.resolved,
+ resolve_failure: None,
+
+ junk_drawer: None,
+ context: None,
+ release: None,
+ synthetic: value.meta.synthetic,
+ suspicious: false,
+ module: value.module.clone(),
+ code_variables: None,
+ }
+ }
+}