-
Notifications
You must be signed in to change notification settings - Fork 94
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
feat(metrics): Prefix all metric names [INGEST-548] #1147
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
26c30dc
ref(metrics): Move session extraction code
jjbayer e130fd4
Add missing file
jjbayer d500343
Remove unused import in test
jjbayer a2bd256
feat(metrics): Prefix all metric names
jjbayer f6ac94b
fix: feature-gate transaction extraction helpers
jjbayer ee5a783
fix: Clippy and tests
jjbayer e22a5d8
Merge branch 'master' into feat/rename-metrics
jjbayer a07aee1
ref: performance -> transactions
jjbayer f6e72f8
Use write! instead of format
jjbayer b8a9e17
doc: changelog
jjbayer d83b501
fix: feature gate import
jjbayer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
use std::collections::BTreeSet; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use std::collections::BTreeSet; | ||
|
||
#[cfg(feature = "processing")] | ||
use { | ||
relay_common::UnixTimestamp, | ||
relay_general::protocol::{AsPair, Event, EventType}, | ||
relay_metrics::{Metric, MetricUnit, MetricValue}, | ||
std::collections::BTreeMap, | ||
std::fmt::Write, | ||
}; | ||
|
||
/// Configuration in relation to extracting metrics from transaction events. | ||
|
@@ -18,6 +18,21 @@ pub struct TransactionMetricsConfig { | |
extract_custom_tags: BTreeSet<String>, | ||
} | ||
|
||
#[cfg(feature = "processing")] | ||
const METRIC_NAME_PREFIX: &str = "sentry.transactions"; | ||
|
||
/// Generate a transaction-related metric name | ||
#[cfg(feature = "processing")] | ||
fn metric_name(parts: &[&str]) -> String { | ||
let mut name = METRIC_NAME_PREFIX.to_owned(); | ||
for part in parts { | ||
// Unwrapping here should be fine: | ||
// https://github.com/rust-lang/rust/blob/1.57.0/library/alloc/src/string.rs#L2721-L2724 | ||
write!(name, ".{}", part).unwrap(); | ||
} | ||
name | ||
} | ||
|
||
#[cfg(feature = "processing")] | ||
pub fn extract_transaction_metrics( | ||
config: &TransactionMetricsConfig, | ||
|
@@ -79,15 +94,15 @@ pub fn extract_transaction_metrics( | |
} | ||
|
||
if let Some(measurements) = event.measurements.value() { | ||
for (name, annotated) in measurements.iter() { | ||
for (measurement_name, annotated) in measurements.iter() { | ||
let measurement = match annotated.value().and_then(|m| m.value.value()) { | ||
Some(measurement) => *measurement, | ||
None => continue, | ||
}; | ||
|
||
let name = format!("measurements.{}", name); | ||
let name = metric_name(&["measurements", measurement_name]); | ||
let mut tags = tags.clone(); | ||
if let Some(rating) = get_measurement_rating(&name, measurement) { | ||
if let Some(rating) = get_measurement_rating(measurement_name, measurement) { | ||
tags.insert("measurement_rating".to_owned(), rating); | ||
} | ||
|
||
|
@@ -115,7 +130,7 @@ pub fn extract_transaction_metrics( | |
}; | ||
|
||
push_metric(Metric { | ||
name: format!("breakdown.{}.{}", breakdown, name), | ||
name: metric_name(&["breakdowns", breakdown, name]), | ||
unit: MetricUnit::None, | ||
value: MetricValue::Distribution(measurement), | ||
timestamp, | ||
|
@@ -140,10 +155,10 @@ fn get_measurement_rating(name: &str, value: f64) -> Option<String> { | |
}; | ||
|
||
match name { | ||
"measurements.lcp" => rate_range(2500.0, 4000.0), | ||
"measurements.fcp" => rate_range(1000.0, 3000.0), | ||
"measurements.fid" => rate_range(100.0, 300.0), | ||
"measurements.cls" => rate_range(0.1, 0.25), | ||
"lcp" => rate_range(2500.0, 4000.0), | ||
"fcp" => rate_range(1000.0, 3000.0), | ||
"fid" => rate_range(100.0, 300.0), | ||
"cls" => rate_range(0.1, 0.25), | ||
_ => None, | ||
} | ||
} | ||
|
@@ -198,11 +213,11 @@ mod tests { | |
r#" | ||
{ | ||
"extractMetrics": [ | ||
"measurements.foo", | ||
"measurements.lcp", | ||
"breakdown.breakdown1.bar", | ||
"breakdown.breakdown2.baz", | ||
"breakdown.breakdown2.zap" | ||
"sentry.transactions.measurements.foo", | ||
"sentry.transactions.measurements.lcp", | ||
"sentry.transactions.breakdowns.breakdown1.bar", | ||
"sentry.transactions.breakdowns.breakdown2.baz", | ||
"sentry.transactions.breakdowns.breakdown2.zap" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I briefly considered omitting the prefixes in the project config, since we're already in a config object called |
||
], | ||
"extractCustomTags": ["fOO"] | ||
} | ||
|
@@ -215,11 +230,20 @@ mod tests { | |
|
||
assert_eq!(metrics.len(), 5); | ||
|
||
assert_eq!(metrics[0].name, "measurements.foo"); | ||
assert_eq!(metrics[1].name, "measurements.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[0].name, "sentry.transactions.measurements.foo"); | ||
assert_eq!(metrics[1].name, "sentry.transactions.measurements.lcp"); | ||
assert_eq!( | ||
metrics[2].name, | ||
"sentry.transactions.breakdowns.breakdown1.bar" | ||
); | ||
assert_eq!( | ||
metrics[3].name, | ||
"sentry.transactions.breakdowns.breakdown2.baz" | ||
); | ||
assert_eq!( | ||
metrics[4].name, | ||
"sentry.transactions.breakdowns.breakdown2.zap" | ||
); | ||
|
||
assert_eq!(metrics[1].tags["measurement_rating"], "meh"); | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this renames metrics from
breakdown.foo
tobreakdowns.foo
, to be consistent withmeasurements
.