fix: don't add extra prefixes to middleware emitted metrics (#1630)

Closes SYNC-4478
This commit is contained in:
Philip Jenvey 2024-11-13 12:04:18 -08:00 committed by GitHub
parent 3ed6d6077c
commit 9b033edcb0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 13 deletions

View File

@ -14,15 +14,13 @@ use crate::{ReportableError, Taggable};
#[derive(Clone)]
pub struct SentryWrapper<E> {
metrics: Arc<StatsdClient>,
metric_label: String,
phantom: PhantomData<E>,
}
impl<E> SentryWrapper<E> {
pub fn new(metrics: Arc<StatsdClient>, metric_label: String) -> Self {
pub fn new(metrics: Arc<StatsdClient>) -> Self {
Self {
metrics,
metric_label,
phantom: PhantomData,
}
}
@ -44,7 +42,6 @@ where
ok(SentryWrapperMiddleware {
service: Rc::new(RefCell::new(service)),
metrics: self.metrics.clone(),
metric_label: self.metric_label.clone(),
phantom: PhantomData,
})
}
@ -54,7 +51,6 @@ where
pub struct SentryWrapperMiddleware<S, E> {
service: Rc<RefCell<S>>,
metrics: Arc<StatsdClient>,
metric_label: String,
phantom: PhantomData<E>,
}
@ -81,7 +77,6 @@ where
// get the tag information
let metrics = self.metrics.clone();
let metric_label = self.metric_label.clone();
let tags = sreq.get_tags();
let extras = sreq.get_extras();
@ -100,7 +95,7 @@ where
// capture it, and then turn it off before we run out of money.
if let Some(label) = reportable_err.metric_label() {
debug!("Sentry: Sending error to metrics: {:?}", reportable_err);
let _ = metrics.incr(&format!("{}.{}", metric_label, label));
let _ = metrics.incr(&label);
}
debug!("Sentry: Not reporting error (service error): {:?}", error);
return Err(error);
@ -122,7 +117,7 @@ where
if !reportable_err.is_sentry_event() {
if let Some(label) = reportable_err.metric_label() {
debug!("Sentry: Sending error to metrics: {:?}", reportable_err);
let _ = metrics.incr(&format!("{}.{}", metric_label, label));
let _ = metrics.incr(&label);
}
debug!("Not reporting error (service error): {:?}", error);
return Ok(response);

View File

@ -88,10 +88,7 @@ macro_rules! build_app {
// These will wrap all outbound responses with matching status codes.
.wrap(ErrorHandlers::new().handler(StatusCode::NOT_FOUND, ApiError::render_404))
// These are our wrappers
.wrap(SentryWrapper::<ApiError>::new(
$metrics.clone(),
"api_error".to_owned(),
))
.wrap(SentryWrapper::<ApiError>::new($metrics.clone()))
.wrap_fn(middleware::weave::set_weave_timestamp)
.wrap_fn(tokenserver::logging::handle_request_log_line)
.wrap_fn(middleware::rejectua::reject_user_agent)
@ -199,7 +196,6 @@ macro_rules! build_app_without_syncstorage {
.wrap(ErrorHandlers::new().handler(StatusCode::NOT_FOUND, ApiError::render_404))
.wrap(SentryWrapper::<tokenserver_common::TokenserverError>::new(
$metrics.clone(),
"api_error".to_owned(),
))
// These are our wrappers
.wrap_fn(tokenserver::logging::handle_request_log_line)