From b47e9ffd309f296a30f4bbb5f83ae002a0a3ba38 Mon Sep 17 00:00:00 2001 From: Nipunn Koorapati Date: Thu, 2 Jan 2025 17:21:36 -0800 Subject: [PATCH] Don't sample system OCCs to sentry. (#32672) They happen at lower frequency and are actionable on our side. GitOrigin-RevId: eaeae7fa90b377ad3102fa0336b2b1b9e52a8ef9 --- crates/errors/src/lib.rs | 26 ++++++++++++++++++++++++-- crates/pb/protos/errors.proto | 1 + crates/pb/src/error_metadata.rs | 18 +++++++++++------- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/crates/errors/src/lib.rs b/crates/errors/src/lib.rs index 0c7c91af..9f72b29f 100644 --- a/crates/errors/src/lib.rs +++ b/crates/errors/src/lib.rs @@ -54,6 +54,7 @@ pub enum ErrorCode { table_name: Option, document_id: Option, write_source: Option, + is_system: bool, }, PaginationLimit, OutOfRetention, @@ -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(), @@ -276,6 +278,7 @@ impl ErrorMetadata { table_name, document_id, write_source, + is_system: false, }, short_msg: OCC_ERROR.into(), msg: format!( @@ -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))), } @@ -598,6 +606,7 @@ impl ErrorMetadataAnyhowExt for anyhow::Error { table_name, document_id, write_source, + is_system: _, } => Some(( table_name.clone(), document_id.clone(), @@ -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"), diff --git a/crates/pb/protos/errors.proto b/crates/pb/protos/errors.proto index 2a4911eb..9ed12812 100644 --- a/crates/pb/protos/errors.proto +++ b/crates/pb/protos/errors.proto @@ -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 { diff --git a/crates/pb/src/error_metadata.rs b/crates/pb/src/error_metadata.rs index 29b983b0..38c81600 100644 --- a/crates/pb/src/error_metadata.rs +++ b/crates/pb/src/error_metadata.rs @@ -36,9 +36,9 @@ impl From for ErrorCodeProto { } } -impl From 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, @@ -48,9 +48,10 @@ impl From 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, @@ -73,10 +74,12 @@ impl From for ErrorMetadataProto { table_name, document_id, write_source, + is_system, } => Some(OccInfoProto { table_name, document_id, write_source, + is_system, }), _ => None, }, @@ -88,7 +91,8 @@ impl TryFrom for ErrorMetadata { type Error = anyhow::Error; fn try_from(metadata: ErrorMetadataProto) -> anyhow::Result { - 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 {