Skip to content

Commit

Permalink
feat(metrics): Extract measurement ratings, port from frontend (#1130)
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Nov 18, 2021
1 parent 113b719 commit a21076a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

**Features**:

- Extract measurement ratings, port from frontend. ([#1130](https://github.com/getsentry/relay/pull/1130))
- External Relays perform dynamic sampling and emit outcomes as client reports. This feature is now enabled *by default*. ([#1119](https://github.com/getsentry/relay/pull/1119))

**Internal**:
Expand Down
46 changes: 39 additions & 7 deletions relay-server/src/actors/envelopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,28 @@ fn with_tag(
tags
}

#[cfg(feature = "processing")]
fn get_measurement_rating(name: &str, value: f64) -> Option<String> {
let rate_range = |meh_ceiling: f64, poor_ceiling: f64| {
debug_assert!(meh_ceiling < poor_ceiling);
if value < meh_ceiling {
Some("good".to_owned())
} else if value < poor_ceiling {
Some("meh".to_owned())
} else {
Some("poor".to_owned())
}
};

match name {
"measurement.lcp" => rate_range(2500.0, 4000.0),
"measurement.fcp" => rate_range(1000.0, 3000.0),
"measurement.fid" => rate_range(100.0, 300.0),
"measurement.cls" => rate_range(0.1, 0.25),
_ => None,
}
}

#[cfg(feature = "processing")]
fn extract_transaction_metrics(event: &Event, target: &mut Vec<Metric>) {
let timestamp = match event
Expand Down Expand Up @@ -445,12 +467,18 @@ fn extract_transaction_metrics(event: &Event, target: &mut Vec<Metric>) {
None => continue,
};

let name = format!("measurement.{}", name);
let mut tags = tags.clone();
if let Some(rating) = get_measurement_rating(&name, measurement) {
tags.insert("measurement_rating".to_owned(), rating);
}

target.push(Metric {
name: format!("measurement.{}", name),
name,
unit: MetricUnit::None,
value: MetricValue::Distribution(measurement),
timestamp,
tags: tags.clone(),
tags,
});
}
}
Expand Down Expand Up @@ -3357,7 +3385,8 @@ mod tests {
"environment": "fake_environment",
"transaction": "mytransaction",
"measurements": {
"foo": {"value": 420.69}
"foo": {"value": 420.69},
"lcp": {"value": 3000.0}
},
"breakdowns": {
"breakdown1": {
Expand All @@ -3375,12 +3404,15 @@ mod tests {
let mut metrics = vec![];
extract_transaction_metrics(event.value().unwrap(), &mut metrics);

assert_eq!(metrics.len(), 4);
assert_eq!(metrics.len(), 5);

assert_eq!(metrics[0].name, "measurement.foo");
assert_eq!(metrics[1].name, "breakdown.breakdown1.bar");
assert_eq!(metrics[2].name, "breakdown.breakdown2.baz");
assert_eq!(metrics[3].name, "breakdown.breakdown2.zap");
assert_eq!(metrics[1].name, "measurement.lcp");
assert_eq!(metrics[2].name, "breakdown.breakdown1.bar");
assert_eq!(metrics[3].name, "breakdown.breakdown2.baz");
assert_eq!(metrics[4].name, "breakdown.breakdown2.zap");

assert_eq!(metrics[1].tags["measurement_rating"], "meh");

for metric in metrics {
assert!(matches!(metric.value, MetricValue::Distribution(_)));
Expand Down

0 comments on commit a21076a

Please sign in to comment.