Skip to content

Commit

Permalink
Don't sample system OCCs to sentry. (#32672)
Browse files Browse the repository at this point in the history
They happen at lower frequency and are actionable on our side.

GitOrigin-RevId: eaeae7fa90b377ad3102fa0336b2b1b9e52a8ef9
  • Loading branch information
nipunn1313 authored and Convex, Inc. committed Jan 3, 2025
1 parent 1e4f23f commit b47e9ff
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
26 changes: 24 additions & 2 deletions crates/errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub enum ErrorCode {
table_name: Option<String>,
document_id: Option<String>,
write_source: Option<String>,
is_system: bool,
},
PaginationLimit,
OutOfRetention,
Expand Down Expand Up @@ -250,6 +251,7 @@ impl ErrorMetadata {
table_name: None,
document_id: None,
write_source: None,
is_system: true,
},
short_msg: OCC_ERROR.into(),
msg: OCC_ERROR_MSG.into(),
Expand All @@ -276,6 +278,7 @@ impl ErrorMetadata {
table_name,
document_id,
write_source,
is_system: false,
},
short_msg: OCC_ERROR.into(),
msg: format!(
Expand Down Expand Up @@ -422,7 +425,12 @@ impl ErrorMetadata {
// 1% sampling for OCC/Overloaded/RateLimited, since we only really care about the
// details if they happen at high volume.
ErrorCode::RateLimited => Some((sentry::Level::Info, Some(0.001))),
ErrorCode::OCC { .. } => Some((sentry::Level::Warning, Some(0.001))),
ErrorCode::OCC {
is_system: false, ..
} => Some((sentry::Level::Warning, Some(0.001))),
ErrorCode::OCC {
is_system: true, ..
} => Some((sentry::Level::Warning, None)),
// we want to see these a bit more than the others above
ErrorCode::Overloaded => Some((sentry::Level::Warning, Some(0.1))),
}
Expand Down Expand Up @@ -598,6 +606,7 @@ impl ErrorMetadataAnyhowExt for anyhow::Error {
table_name,
document_id,
write_source,
is_system: _,
} => Some((
table_name.clone(),
document_id.clone(),
Expand Down Expand Up @@ -836,7 +845,20 @@ mod proptest {
ErrorCode::PaginationLimit => {
ErrorMetadata::pagination_limit("pagination", "limit")
},
ErrorCode::OCC { .. } => ErrorMetadata::system_occ(),
ErrorCode::OCC {
is_system: true, ..
} => ErrorMetadata::system_occ(),
ErrorCode::OCC {
is_system: false,
table_name,
document_id,
write_source,
} => ErrorMetadata::user_occ(
table_name,
document_id,
write_source,
Some("description".to_string()),
),
ErrorCode::OutOfRetention => ErrorMetadata::out_of_retention(),
ErrorCode::Unauthenticated => ErrorMetadata::unauthenticated("un", "auth"),
ErrorCode::Forbidden => ErrorMetadata::forbidden("for", "bidden"),
Expand Down
1 change: 1 addition & 0 deletions crates/pb/protos/errors.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ message OccInfo {
optional string table_name = 1;
optional string document_id = 2;
optional string write_source = 3;
bool is_system = 4;
}

message ErrorMetadata {
Expand Down
18 changes: 11 additions & 7 deletions crates/pb/src/error_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ impl From<ErrorCode> for ErrorCodeProto {
}
}

impl From<ErrorCodeProto> for ErrorCode {
fn from(code: ErrorCodeProto) -> Self {
match code {
impl ErrorCodeProto {
fn into_rust_type(self, occ_info: OccInfoProto) -> ErrorCode {
match self {
ErrorCodeProto::BadRequest => ErrorCode::BadRequest,
ErrorCodeProto::Unauthenticated => ErrorCode::Unauthenticated,
ErrorCodeProto::Forbidden => ErrorCode::Forbidden,
Expand All @@ -48,9 +48,10 @@ impl From<ErrorCodeProto> for ErrorCode {
ErrorCodeProto::Overloaded => ErrorCode::Overloaded,
ErrorCodeProto::RejectedBeforeExecution => ErrorCode::RejectedBeforeExecution,
ErrorCodeProto::Occ => ErrorCode::OCC {
table_name: None,
document_id: None,
write_source: None,
table_name: occ_info.table_name,
document_id: occ_info.document_id,
write_source: occ_info.write_source,
is_system: occ_info.is_system,
},
ErrorCodeProto::PaginationLimit => ErrorCode::PaginationLimit,
ErrorCodeProto::OutOfRetention => ErrorCode::OutOfRetention,
Expand All @@ -73,10 +74,12 @@ impl From<ErrorMetadata> for ErrorMetadataProto {
table_name,
document_id,
write_source,
is_system,
} => Some(OccInfoProto {
table_name,
document_id,
write_source,
is_system,
}),
_ => None,
},
Expand All @@ -88,7 +91,8 @@ impl TryFrom<ErrorMetadataProto> for ErrorMetadata {
type Error = anyhow::Error;

fn try_from(metadata: ErrorMetadataProto) -> anyhow::Result<Self> {
let code = ErrorCodeProto::try_from(metadata.code)?.into();
let code = ErrorCodeProto::try_from(metadata.code)?
.into_rust_type(metadata.occ_info.unwrap_or_default());
let short_msg = metadata.short_msg.context("Missing `short_msg` field")?;
let msg = metadata.msg.context("Missing `msg` field")?;
Ok(Self {
Expand Down

0 comments on commit b47e9ff

Please sign in to comment.