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

ref(statsd): Add metric name as a tag for Sentry errors #1797

Merged
merged 4 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Add support for client hints. ([#1752](https://github.com/getsentry/relay/pull/1752))

**Internal**:

- Add metric name as tag on Sentry errors from relay dropping metrics. ([#1680](https://github.com/getsentry/relay/issues/1680))
iker-barriocanal marked this conversation as resolved.
Show resolved Hide resolved

## 23.1.1

**Features**:
Expand Down
127 changes: 84 additions & 43 deletions relay-statsd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,81 +492,122 @@ pub trait GaugeMetric {
macro_rules! metric {
// counter increment
(counter($id:expr) += $value:expr $(, $k:ident = $v:expr)* $(,)?) => {
$crate::with_client(|client| {
use $crate::_pred::*;
client.send_metric(
client.count_with_tags(&$crate::CounterMetric::name(&$id), $value)
$(.with_tag(stringify!($k), $v))*
)
})
relay_log::with_scope(
|scope| {
scope.set_tag("key", &$crate::CounterMetric::name(&$id));
}, || {
$crate::with_client(|client| {
use $crate::_pred::*;
client.send_metric(
client.count_with_tags(&$crate::CounterMetric::name(&$id), $value)
$(.with_tag(stringify!($k), $v))*
)
})
}
)
};

// counter decrement
(counter($id:expr) -= $value:expr $(, $k:ident = $v:expr)* $(,)?) => {
$crate::with_client(|client| {
use $crate::_pred::*;
client.send_metric(
client.count_with_tags(&$crate::CounterMetric::name(&$id), -$value)
$(.with_tag(stringify!($k), $v))*
)
})
relay_log::with_scope(
|scope| {
scope.set_tag("key", &$crate::CounterMetric::name(&$id));
}, || {
$crate::with_client(|client| {
use $crate::_pred::*;
client.send_metric(
client.count_with_tags(&$crate::CounterMetric::name(&$id), -$value)
$(.with_tag(stringify!($k), $v))*
)
})
}
)
};

// gauge set
(gauge($id:expr) = $value:expr $(, $k:ident = $v:expr)* $(,)?) => {
$crate::with_client(|client| {
use $crate::_pred::*;
client.send_metric(
client.gauge_with_tags(&$crate::GaugeMetric::name(&$id), $value)
$(.with_tag(stringify!($k), $v))*
relay_log::with_scope(
|scope| {
scope.set_tag("key", &$crate::GaugeMetric::name(&$id));
}, || {
client.send_metric(
client.gauge_with_tags(&$crate::GaugeMetric::name(&$id), $value)
$(.with_tag(stringify!($k), $v))*
)
}
)
})
};

// histogram
(histogram($id:expr) = $value:expr $(, $k:ident = $v:expr)* $(,)?) => {
$crate::with_client(|client| {
use $crate::_pred::*;
client.send_metric(
client.histogram_with_tags(&$crate::HistogramMetric::name(&$id), $value)
$(.with_tag(stringify!($k), $v))*
)
})
use $crate::_pred::*;
relay_log::with_scope(
|scope| {
scope.set_tag("key", &$crate::HistogramMetric::name(&$id));
}, || {
$crate::with_client(|client| {
client.send_metric(
client.histogram_with_tags(&$crate::HistogramMetric::name(&$id), $value)
$(.with_tag(stringify!($k), $v))*
)
})
}
)
};

// sets (count unique occurrences of a value per time interval)
(set($id:expr) = $value:expr $(, $k:ident = $v:expr)* $(,)?) => {
$crate::with_client(|client| {
use $crate::_pred::*;
client.send_metric(
client.set_with_tags(&$crate::SetMetric::name(&$id), $value)
$(.with_tag(stringify!($k), $v))*
)
})
use $crate::_pred::*;
relay_log::with_scope(
|scope| {
scope.set_tag("key", &$crate::SetMetric::name(&$id));
}, || {
$crate::with_client(|client| {
client.send_metric(
client.set_with_tags(&$crate::SetMetric::name(&$id), $value)
$(.with_tag(stringify!($k), $v))*
)
})
}
)
};

// timer value (duration)
(timer($id:expr) = $value:expr $(, $k:ident = $v:expr)* $(,)?) => {
$crate::with_client(|client| {
use $crate::_pred::*;
client.send_metric(
client.time_with_tags(&$crate::TimerMetric::name(&$id), $value)
$(.with_tag(stringify!($k), $v))*
)
relay_log::with_scope(
|scope| {
scope.set_tag("key", &$crate::TimerMetric::name(&$id));
}, || {
use $crate::_pred::*;
client.send_metric(
client.time_with_tags(&$crate::TimerMetric::name(&$id), $value)
$(.with_tag(stringify!($k), $v))*
)
})
})
};

// timed block
(timer($id:expr), $($k:ident = $v:expr,)* $block:block) => {{
let now = std::time::Instant::now();
let rv = {$block};
$crate::with_client(|client| {
use $crate::_pred::*;
client.send_metric(
client.time_with_tags(&$crate::TimerMetric::name(&$id), now.elapsed())
$(.with_tag(stringify!($k), $v))*
)
});
relay_log::with_scope(
|scope| {
scope.set_tag("key", &$crate::TimerMetric::name(&$id));
}, || {
$crate::with_client(|client| {
use $crate::_pred::*;
client.send_metric(
client.time_with_tags(&$crate::TimerMetric::name(&$id), now.elapsed())
$(.with_tag(stringify!($k), $v))*
)
});
}
);
rv
}};
}
Expand Down