Skip to content

Commit

Permalink
ref(metrics): Add normalization and update set metrics hashing (#658)
Browse files Browse the repository at this point in the history
Add metrics normalization in accordance with the metrics developer docs.
Add metric name, unit, and tag truncation to adhere to the metrics user docs.
Add to_envelope for a single Metric instance to facilitate sending metrics from sentry-cli.
Change hash function to crc32 as described here, this ensures compatibility between different SDKs using the same metric.
Use clone_from instead of clone and clone_into instead of to_owned in a couple of places as suggested by clippy.
  • Loading branch information
elramen authored May 27, 2024
1 parent 8c701e8 commit 73d04ae
Show file tree
Hide file tree
Showing 13 changed files with 1,467 additions and 139 deletions.
996 changes: 977 additions & 19 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions sentry-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ UNSTABLE_cadence = ["dep:cadence", "UNSTABLE_metrics"]

[dependencies]
cadence = { version = "0.29.0", optional = true }
crc32fast = "1.4.0"
itertools = "0.13.0"
log = { version = "0.4.8", optional = true, features = ["std"] }
once_cell = "1"
rand = { version = "0.8.1", optional = true }
regex = "1.7.3"
sentry-types = { version = "0.32.3", path = "../sentry-types" }
serde = { version = "1.0.104", features = ["derive"] }
serde_json = { version = "1.0.46" }
Expand Down
7 changes: 4 additions & 3 deletions sentry-core/src/cadence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ mod tests {

println!("{metrics}");

assert!(metrics.contains("sentry.test.count.with.tags:1|c|#foo:bar|T"));
assert!(metrics.contains("sentry.test.some.count:11|c|T"));
assert!(metrics.contains("sentry.test.some.distr:1:2:3|d|T"));
assert!(metrics
.contains("sentry.test.count.with.tags@none:1|c|#environment:production,foo:bar|T"));
assert!(metrics.contains("sentry.test.some.count@none:11|c|#environment:production|T"));
assert!(metrics.contains("sentry.test.some.distr@none:1:2:3|d|#environment:production|T"));
assert_eq!(items.next(), None);
}
}
6 changes: 3 additions & 3 deletions sentry-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@ impl Client {
}

if event.release.is_none() {
event.release = self.options.release.clone();
event.release.clone_from(&self.options.release);
}
if event.environment.is_none() {
event.environment = self.options.environment.clone();
event.environment.clone_from(&self.options.environment);
}
if event.server_name.is_none() {
event.server_name = self.options.server_name.clone();
event.server_name.clone_from(&self.options.server_name);
}
if &event.platform == "other" {
event.platform = "native".into();
Expand Down
Loading

0 comments on commit 73d04ae

Please sign in to comment.