From 5bd0933997792bea824a9791e0fc91cc2fdf44be Mon Sep 17 00:00:00 2001 From: Philip Jenvey Date: Thu, 1 Jun 2023 10:34:56 -0700 Subject: [PATCH] fix: emit metrics also in the common Response error case (#384) SYNC-3635 --- autoendpoint/src/middleware/sentry.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/autoendpoint/src/middleware/sentry.rs b/autoendpoint/src/middleware/sentry.rs index 3f69673d4..17d241fa5 100644 --- a/autoendpoint/src/middleware/sentry.rs +++ b/autoendpoint/src/middleware/sentry.rs @@ -17,16 +17,16 @@ use sentry::{protocol::Event, Hub}; use crate::LocalError; use autopush_common::tags::Tags; -#[derive(Clone, Default)] +#[derive(Clone)] pub struct SentryWrapper { - metrics: Option>, + metrics: Arc, metric_label: String, } impl SentryWrapper { pub fn new(metrics: Arc, metric_label: String) -> Self { Self { - metrics: Some(metrics), + metrics, metric_label, } } @@ -55,7 +55,7 @@ where #[derive(Debug)] pub struct SentryWrapperMiddleware { service: Rc>, - metrics: Option>, + metrics: Arc, metric_label: String, } @@ -106,11 +106,9 @@ where // but we may need that information to debug a production issue. We can // add an info here, temporarily turn on info level debugging on a given server, // capture it, and then turn it off before we run out of money. - info!("Sentry: Sending error to metrics: {:?}", api_err.kind); - if let Some(metrics) = metrics { - if let Some(label) = api_err.kind.metric_label() { - let _ = metrics.incr(&format!("{}.{}", metric_label, label)); - } + if let Some(label) = api_err.kind.metric_label() { + info!("Sentry: Sending error to metrics: {:?}", api_err.kind); + let _ = metrics.incr(&format!("{}.{}", metric_label, label)); } } debug!("Sentry: Not reporting error (service error): {:?}", error); @@ -129,6 +127,10 @@ where if let Some(error) = response.response().error() { if let Some(api_err) = error.as_error::() { if !api_err.kind.is_sentry_event() { + if let Some(label) = api_err.kind.metric_label() { + info!("Sentry: Sending error to metrics: {:?}", api_err.kind); + let _ = metrics.incr(&format!("{}.{}", metric_label, label)); + } debug!("Not reporting error (service error): {:?}", error); return Ok(response); }