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(error-tracking): infer issue severity (#81913)

Hugues Pouillotb97af1a3c058
diff --git a/rust/cymbal/.sqlx/query-eaee581d5e4a9d242b35bfc8dbd9bb3025432f32243da56733b270e3bb6871bf.json b/rust/cymbal/.sqlx/query-7fa7861a996118fad5b880adee65f610b8394b926c43692f01a0d9fb3bf1ab48.json
similarity index 58%
rename from rust/cymbal/.sqlx/query-eaee581d5e4a9d242b35bfc8dbd9bb3025432f32243da56733b270e3bb6871bf.json
rename to rust/cymbal/.sqlx/query-7fa7861a996118fad5b880adee65f610b8394b926c43692f01a0d9fb3bf1ab48.json
index 8d962b7e9cf9..d17e021e7e75 100644
--- a/rust/cymbal/.sqlx/query-eaee581d5e4a9d242b35bfc8dbd9bb3025432f32243da56733b270e3bb6871bf.json
+++ b/rust/cymbal/.sqlx/query-7fa7861a996118fad5b880adee65f610b8394b926c43692f01a0d9fb3bf1ab48.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n INSERT INTO posthog_errortrackingissue (id, team_id, status, name, description, created_at)\n VALUES ($1, $2, $3, $4, $5, $6)\n ",
+ "query": "\n INSERT INTO posthog_errortrackingissue (id, team_id, status, severity, name, description, created_at)\n VALUES ($1, $2, $3, $4, $5, $6, $7)\n ",
"describe": {
"columns": [],
"parameters": {
@@ -10,10 +10,11 @@
"Text",
"Text",
"Text",
+ "Text",
"Timestamptz"
]
},
"nullable": []
},
- "hash": "eaee581d5e4a9d242b35bfc8dbd9bb3025432f32243da56733b270e3bb6871bf"
+ "hash": "7fa7861a996118fad5b880adee65f610b8394b926c43692f01a0d9fb3bf1ab48"
}
diff --git a/rust/cymbal/src/modes/processing/issue_resolution.rs b/rust/cymbal/src/modes/processing/issue_resolution.rs
index e8e6b2037f31..266e01a0169f 100644
--- a/rust/cymbal/src/modes/processing/issue_resolution.rs
+++ b/rust/cymbal/src/modes/processing/issue_resolution.rs
@@ -90,6 +90,33 @@ pub enum IssueStatus {
Suppressed,
}
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub(crate) enum IssueSeverity {
+ Low,
+ Medium,
+ High,
+ Critical,
+}
+
+pub(crate) fn infer_issue_severity(
+ exception_level: Option<&str>,
+ handled: Option<bool>,
+) -> Option<IssueSeverity> {
+ match exception_level.map(str::to_ascii_lowercase).as_deref() {
+ Some("fatal" | "critical") => Some(IssueSeverity::Critical),
+ Some("warning" | "warn") => Some(IssueSeverity::Medium),
+ Some("info" | "log" | "debug" | "trace") => Some(IssueSeverity::Low),
+ Some("error") => handled.map(|handled| {
+ if handled {
+ IssueSeverity::Medium
+ } else {
+ IssueSeverity::High
+ }
+ }),
+ _ => None,
+ }
+}
+
impl Issue {
pub async fn load_by_fingerprint<'c, E>(
executor: E,
@@ -139,10 +166,11 @@ impl Issue {
Ok(res)
}
- pub async fn insert_new<'c, E>(
+ pub(crate) async fn insert_new<'c, E>(
team_id: i32,
name: String,
description: String,
+ severity: Option<IssueSeverity>,
executor: E,
) -> Result<Issue, UnhandledError>
where
@@ -161,7 +189,7 @@ impl Issue {
id: Uuid::now_v7(),
team_id,
status: IssueStatus::Active,
- severity: None,
+ severity: severity.map(|severity| severity.to_string()),
name: Some(name),
description: Some(description),
created_at: Utc::now(),
@@ -169,12 +197,13 @@ impl Issue {
sqlx::query!(
r#"
- INSERT INTO posthog_errortrackingissue (id, team_id, status, name, description, created_at)
- VALUES ($1, $2, $3, $4, $5, $6)
+ INSERT INTO posthog_errortrackingissue (id, team_id, status, severity, name, description, created_at)
+ VALUES ($1, $2, $3, $4, $5, $6, $7)
"#,
issue.id,
issue.team_id,
issue.status.to_string(),
+ issue.severity,
issue.name,
issue.description,
issue.created_at
@@ -642,6 +671,17 @@ impl Display for IssueStatus {
}
}
+impl Display for IssueSeverity {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ IssueSeverity::Low => write!(f, "low"),
+ IssueSeverity::Medium => write!(f, "medium"),
+ IssueSeverity::High => write!(f, "high"),
+ IssueSeverity::Critical => write!(f, "critical"),
+ }
+ }
+}
+
#[cfg(test)]
mod test {
use common_redis::{MockRedisClient, MockRedisValue};
@@ -675,6 +715,32 @@ mod test {
);
}
+ #[test]
+ fn infers_issue_severity_only_from_confident_signals() {
+ for (level, handled, expected) in [
+ (Some("fatal"), Some(true), Some("critical")),
+ (Some("critical"), Some(false), Some("critical")),
+ (Some("error"), Some(false), Some("high")),
+ (Some("error"), Some(true), Some("medium")),
+ (Some("error"), None, None),
+ (Some("warning"), Some(false), Some("medium")),
+ (Some("warn"), None, Some("medium")),
+ (Some("info"), Some(false), Some("low")),
+ (Some("log"), Some(true), Some("low")),
+ (Some("debug"), None, Some("low")),
+ (Some("trace"), Some(true), Some("low")),
+ (None, Some(false), None),
+ (None, Some(true), None),
+ (Some("custom"), Some(false), None),
+ (Some("CUSTOM"), Some(true), None),
+ ] {
+ assert_eq!(
+ super::infer_issue_severity(level, handled).map(|severity| severity.to_string()),
+ expected.map(str::to_string)
+ );
+ }
+ }
+
#[tokio::test]
async fn stores_full_event_properties_as_raw_json_with_a_ttl() {
let redis = MockRedisClient::new();
diff --git a/rust/cymbal/src/modes/processing/stages/linking/issue.rs b/rust/cymbal/src/modes/processing/stages/linking/issue.rs
index 130868c263dc..cb1c2b31bfa8 100644
--- a/rust/cymbal/src/modes/processing/stages/linking/issue.rs
+++ b/rust/cymbal/src/modes/processing/stages/linking/issue.rs
@@ -10,7 +10,7 @@ use crate::{
app_context::AppContext,
error::UnhandledError,
issue_resolution::{
- send_fingerprint_issue_state, send_issue_created_notification,
+ infer_issue_severity, send_fingerprint_issue_state, send_issue_created_notification,
send_issue_reopened_notification, Issue, IssueFingerprintOverride,
},
metric_consts::{ISSUE_CREATED, ISSUE_LINKER_OPERATOR},
@@ -291,6 +291,10 @@ async fn resolve_issue(
team_id,
name.to_string(),
description.to_string(),
+ infer_issue_severity(
+ event_properties.exception_level(),
+ event_properties.exception_handled(),
+ ),
&mut *txn,
)
.await?;
diff --git a/rust/cymbal/src/modes/processing/types/exception_event.rs b/rust/cymbal/src/modes/processing/types/exception_event.rs
index 785be2a1e79d..39dc146f695c 100644
--- a/rust/cymbal/src/modes/processing/types/exception_event.rs
+++ b/rust/cymbal/src/modes/processing/types/exception_event.rs
@@ -221,6 +221,10 @@ impl<S> ExceptionEvent<S> {
&self.props
}
+ pub(crate) fn exception_level(&self) -> Option<&str> {
+ self.props.get("$exception_level").and_then(Value::as_str)
+ }
+
pub fn proposed_issue_name(&self) -> Option<&str> {
self.proposed_issue_name.as_deref()
}
@@ -311,6 +315,13 @@ impl ExceptionEvent<Fingerprinted> {
&self.state.fingerprint
}
+ pub(crate) fn exception_handled(&self) -> Option<bool> {
+ self.exception_list
+ .first()
+ .and_then(|exception| exception.mechanism.as_ref())
+ .and_then(|mechanism| mechanism.handled)
+ }
+
pub(crate) fn into_linked(self, issue: Issue) -> ExceptionEvent<Linked> {
self.map_state(|state| Linked {
metadata: state.metadata,
diff --git a/rust/cymbal/tests/event.rs b/rust/cymbal/tests/event.rs
index 3267c46223f9..72d0295f362f 100644
--- a/rust/cymbal/tests/event.rs
+++ b/rust/cymbal/tests/event.rs
@@ -378,13 +378,16 @@ async fn empty_exception_list_returns_event_with_error(db: PgPool) {
}
#[sqlx::test(migrations = "./tests/test_migrations")]
-async fn creates_issue_with_fingerprint(db: PgPool) {
+async fn new_issue_only_infers_confident_severity_without_overwriting_existing_severity(
+ db: PgPool,
+) {
let harness = TestHarness::new(db);
- let input = make_event(vec![make_exception_with_stack(
+ let exception = make_exception_with_stack(
"Error",
"test error message",
vec![frame_at(make_frame_js("handleClick"), "src/app.js", 42, 10)],
- )]);
+ );
+ let mut input = make_event(vec![exception]);
let (status, body): (_, SuccessResponse) = harness.post_event(&input).await;
@@ -394,6 +397,29 @@ async fn creates_issue_with_fingerprint(db: PgPool) {
assert_eq!(event.types(), ["Error"]);
assert_eq!(event.values(), ["test error message"]);
assert_eq!(harness.get_issue_id().await, event.issue_id());
+ let severity: Option<String> =
+ sqlx::query_scalar("SELECT severity FROM posthog_errortrackingissue WHERE id = $1")
+ .bind(event.issue_id())
+ .fetch_one(&harness.db)
+ .await
+ .expect("Issue should have severity");
+ assert_eq!(severity, None);
+
+ sqlx::query("UPDATE posthog_errortrackingissue SET severity = 'low' WHERE id = $1")
+ .bind(event.issue_id())
+ .execute(&harness.db)
+ .await
+ .expect("Issue severity should update");
+ input.properties["$exception_level"] = json!("fatal");
+ let (status, _): (_, SuccessResponse) = harness.post_event(&input).await;
+ assert!(status.is_success(), "Expected success, got {:?}", status);
+ let severity: Option<String> =
+ sqlx::query_scalar("SELECT severity FROM posthog_errortrackingissue WHERE id = $1")
+ .bind(event.issue_id())
+ .fetch_one(&harness.db)
+ .await
+ .expect("Issue should keep severity");
+ assert_eq!(severity.as_deref(), Some("low"));
}
#[sqlx::test(migrations = "./tests/test_migrations")]