From f98b8104a3af30de68e5c7189b9057d5b4798440 Mon Sep 17 00:00:00 2001 From: Philip Jenvey Date: Tue, 25 Oct 2022 17:09:58 -0700 Subject: [PATCH] feat: move common connect/timeout errors from sentry to metrics (#471) Closes #467 --- src/error.rs | 3 +++ src/web/handlers.rs | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index fb1446c6..4cefc516 100644 --- a/src/error.rs +++ b/src/error.rs @@ -133,6 +133,8 @@ impl HandlerErrorKind { pub fn metric_label(&self) -> Option<&'static str> { match self { HandlerErrorKind::InvalidUA => Some("request.error.invalid_ua"), + // HandlerErrorKind::Reqest(e) if e.is_timeout() || e.is_connect()) + // metrics emitted elsewhere (in handlers::get_tiles) _ => None, } } @@ -140,6 +142,7 @@ impl HandlerErrorKind { /// Whether this error should trigger a Sentry event pub fn is_sentry_event(&self) -> bool { !matches!(self, HandlerErrorKind::InvalidUA) + && !matches!(self, HandlerErrorKind::Reqwest(e) if e.is_timeout() || e.is_connect()) } pub fn as_response_string(&self) -> String { diff --git a/src/web/handlers.rs b/src/web/handlers.rs index f1bbabc6..1d73b718 100644 --- a/src/web/handlers.rs +++ b/src/web/handlers.rs @@ -159,8 +159,6 @@ pub async fn get_tiles( Ok(tiles.to_response(settings.cache_control_header)) } Err(e) => { - metrics.incr_with_tags("tiles.get.error", Some(&tags)); - if matches!(e.kind(), HandlerErrorKind::BadAdmResponse(_)) { // Handle a bad response from ADM specially. // Report it to metrics and sentry, but also store an empty record @@ -185,6 +183,16 @@ pub async fn get_tiles( return Ok(HttpResponse::NoContent().finish()); } + match e.kind() { + HandlerErrorKind::Reqwest(e) if e.is_timeout() => tags.add_tag("reason", "timeout"), + HandlerErrorKind::Reqwest(e) if e.is_connect() => tags.add_tag("reason", "connect"), + _ => (), + } + if handle.fallback_tiles.is_some() { + tags.add_tag("fallback", "true"); + } + metrics.incr_with_tags("tiles.get.error", Some(&tags)); + // A general error occurred, try rendering fallback Tiles if let Some(tiles) = handle.fallback_tiles { return Ok(fallback_response(settings, &tiles));