Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions syncserver-common/src/middleware/sentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand All @@ -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,
})
}
Expand All @@ -54,7 +51,6 @@ where
pub struct SentryWrapperMiddleware<S, E> {
service: Rc<RefCell<S>>,
metrics: Arc<StatsdClient>,
metric_label: String,
phantom: PhantomData<E>,
}

Expand All @@ -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();

Expand All @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions syncserver/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down