Skip to content

feat(session): Add unhandled session status type #4939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

**Features**:
- Add `unhandled` status type for Release Health `session` and `sessions` envelopes. ([#4939](https://github.com/getsentry/relay/pull/4939))

**Internal**:

- Emit outcomes for skipped large attachments on playstation crashes. ([#4862](https://github.com/getsentry/relay/pull/4862))
Expand Down
25 changes: 22 additions & 3 deletions relay-event-schema/src/protocol/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub enum SessionStatus {
Abnormal,
/// The session exited cleanly but experienced some errors during its run.
Errored,
/// The session had an unhandled error, but did not crash.
Unhandled,
/// Unknown status, for forward compatibility.
Unknown(String),
}
Expand All @@ -50,6 +52,7 @@ impl SessionStatus {
SessionStatus::Abnormal => "abnormal",
SessionStatus::Exited => "exited",
SessionStatus::Errored => "errored",
SessionStatus::Unhandled => "unhandled",
SessionStatus::Unknown(s) => s.as_str(),
}
}
Expand All @@ -73,6 +76,7 @@ impl std::str::FromStr for SessionStatus {
"abnormal" => SessionStatus::Abnormal,
"exited" => SessionStatus::Exited,
"errored" => SessionStatus::Errored,
"unhandled" => SessionStatus::Unhandled,
other => SessionStatus::Unknown(other.to_owned()),
})
}
Expand Down Expand Up @@ -173,6 +177,7 @@ pub trait SessionLike {
fn distinct_id(&self) -> Option<&String>;
fn total_count(&self) -> u32;
fn abnormal_count(&self) -> u32;
fn unhandled_count(&self) -> u32;
fn crashed_count(&self) -> u32;
fn all_errors(&self) -> Option<SessionErrored>;
fn abnormal_mechanism(&self) -> AbnormalMechanism;
Expand Down Expand Up @@ -250,6 +255,13 @@ impl SessionLike for SessionUpdate {
}
}

fn unhandled_count(&self) -> u32 {
match self.status {
SessionStatus::Unhandled => 1,
_ => 0,
}
}

fn crashed_count(&self) -> u32 {
match self.status {
SessionStatus::Crashed => 1,
Expand Down Expand Up @@ -299,6 +311,9 @@ pub struct SessionAggregateItem {
/// The number of abnormal sessions that ocurred.
#[serde(default, skip_serializing_if = "is_zero")]
pub abnormal: u32,
/// The number of unhandled sessions that ocurred.
#[serde(default, skip_serializing_if = "is_zero")]
pub unhandled: u32,
/// The number of crashed sessions that ocurred.
#[serde(default, skip_serializing_if = "is_zero")]
pub crashed: u32,
Expand All @@ -314,21 +329,25 @@ impl SessionLike for SessionAggregateItem {
}

fn total_count(&self) -> u32 {
self.exited + self.errored + self.abnormal + self.crashed
self.exited + self.abnormal + self.errored + self.unhandled + self.crashed
}

fn abnormal_count(&self) -> u32 {
self.abnormal
}

fn unhandled_count(&self) -> u32 {
self.unhandled
}

fn crashed_count(&self) -> u32 {
self.crashed
}

fn all_errors(&self) -> Option<SessionErrored> {
// Errors contain crashed & abnormal as well.
// Errors contain all of: abnormal, unhandled, and crashed.
// See https://github.com/getsentry/snuba/blob/c45f2a8636f9ea3dfada4e2d0ae5efef6c6248de/snuba/migrations/snuba_migrations/sessions/0003_sessions_matview.py#L80-L81
let all_errored = self.abnormal + self.crashed + self.errored;
let all_errored = self.abnormal + self.errored + self.unhandled + self.crashed;
if all_errored > 0 {
Some(SessionErrored::Aggregated(all_errored))
} else {
Expand Down
27 changes: 27 additions & 0 deletions relay-server/src/metrics_extraction/sessions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,33 @@ pub fn extract_session_metrics<T: SessionLike>(
}
}

if session.unhandled_count() > 0 {
target.push(
SessionMetric::Session {
counter: session.unhandled_count().into(),
tags: SessionSessionTags {
status: "unhandled".to_owned(),
common_tags: common_tags.clone(),
},
}
.into_metric(timestamp),
);

if let Some(distinct_id) = nil_to_none(session.distinct_id()) {
target.push(
SessionMetric::User {
distinct_id: distinct_id.clone(),
tags: SessionUserTags {
status: Some(SessionStatus::Unhandled),
abnormal_mechanism: None,
common_tags: common_tags.clone(),
},
}
.into_metric(timestamp),
);
}
}

if session.crashed_count() > 0 {
target.push(
SessionMetric::Session {
Expand Down
Loading