Skip to content

Commit 2392ad7

Browse files
authored
feat(metrics): Add ability to compute metrics summary and attach it to events (#3769)
1 parent ed2fc8c commit 2392ad7

File tree

14 files changed

+1134
-33
lines changed

14 files changed

+1134
-33
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
- Ingest profiler_id in the profile context and in spans. ([#3714](https://github.com/getsentry/relay/pull/3714), [#3784](https://github.com/getsentry/relay/pull/3784))
1717
- Support extrapolation of metrics extracted from sampled data, as long as the sample rate is set in the DynamicSamplingContext. ([#3753](https://github.com/getsentry/relay/pull/3753))
1818
- Extract thread ID and name in spans. ([#3771](https://github.com/getsentry/relay/pull/3771))
19+
- Compute metrics summary on the extracted custom metrics. ([#3769](https://github.com/getsentry/relay/pull/3769))
20+
21+
>>>>>>> master
1922
2023
## 24.6.0
2124

relay-dynamic-config/src/global.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ pub struct Options {
214214
)]
215215
pub span_extraction_sample_rate: Option<f32>,
216216

217+
/// Overall sampling of metrics summaries computation.
218+
#[serde(
219+
rename = "relay.compute-metrics-summaries.sample-rate",
220+
deserialize_with = "default_on_error",
221+
skip_serializing_if = "is_default"
222+
)]
223+
pub compute_metrics_summaries_sample_rate: Option<f32>,
224+
217225
/// The maximum duplication factor used to extrapolate distribution metrics from sampled data.
218226
///
219227
/// This applies as long as Relay duplicates distribution values to extrapolate. The default is

relay-event-schema/src/protocol/metrics_summary.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,13 @@ pub struct MetricSummary {
4040
/// Tags of the metric.
4141
pub tags: Annotated<Object<String>>,
4242
}
43+
44+
impl MetricSummary {
45+
/// Merges another [`MetricSummary`] in this [`MetricsSummary`].
46+
pub fn merge(&mut self, other: MetricSummary) {
47+
self.min.merge(other.min, |l, r| *l = l.min(r));
48+
self.max.merge(other.max, |l, r| *l = l.max(r));
49+
self.sum.merge(other.sum, |l, r| *l += r);
50+
self.count.merge(other.count, |l, r| *l += r);
51+
}
52+
}

relay-protocol/src/annotated.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ impl<T> Annotated<T> {
190190
{
191191
self.value_mut().get_or_insert_with(f)
192192
}
193+
194+
/// Merges the supplied [`Annotated`] in the left [`Annotated`].
195+
pub fn merge(&mut self, other: Annotated<T>, block: impl FnOnce(&mut T, T)) {
196+
match (self.value_mut(), other.into_value()) {
197+
(Some(left), Some(right)) => block(left, right),
198+
(None, Some(right)) => self.set_value(Some(right)),
199+
_ => {}
200+
}
201+
}
193202
}
194203

195204
impl<T> Annotated<T>

0 commit comments

Comments
 (0)