Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
feat: move common connect/timeout errors from sentry to metrics (#471)
Browse files Browse the repository at this point in the history
Closes #467
  • Loading branch information
pjenvey authored Oct 26, 2022
1 parent 22a62ce commit f98b810
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,16 @@ 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,
}
}

/// 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 {
Expand Down
12 changes: 10 additions & 2 deletions src/web/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand Down

0 comments on commit f98b810

Please sign in to comment.